chore(vscode): update to 1.54.2

This commit is contained in:
Joe Previte
2021-03-11 10:27:10 -07:00
1459 changed files with 53404 additions and 51004 deletions

View File

@@ -30,7 +30,7 @@ suite('dom', () => {
assert(element.classList.contains('far'));
assert(!element.classList.contains('boo'));
assert(element.classList.contains('foobar'));
assert.equal(element.className, 'foobar far');
assert.strictEqual(element.className, 'foobar far');
element = document.createElement('div');
element.className = 'foobar boo far';
@@ -39,19 +39,19 @@ suite('dom', () => {
assert(!element.classList.contains('far'));
assert(element.classList.contains('boo'));
assert(element.classList.contains('foobar'));
assert.equal(element.className, 'foobar boo');
assert.strictEqual(element.className, 'foobar boo');
element.classList.remove('boo');
assert(!element.classList.contains('far'));
assert(!element.classList.contains('boo'));
assert(element.classList.contains('foobar'));
assert.equal(element.className, 'foobar');
assert.strictEqual(element.className, 'foobar');
element.classList.remove('foobar');
assert(!element.classList.contains('far'));
assert(!element.classList.contains('boo'));
assert(!element.classList.contains('foobar'));
assert.equal(element.className, '');
assert.strictEqual(element.className, '');
});
test('removeClass should consider hyphens', function () {
@@ -83,7 +83,7 @@ suite('dom', () => {
const div = $('div');
assert(div);
assert(div instanceof HTMLElement);
assert.equal(div.tagName, 'DIV');
assert.strictEqual(div.tagName, 'DIV');
assert(!div.firstChild);
});
@@ -91,42 +91,42 @@ suite('dom', () => {
const div = $('div#foo');
assert(div);
assert(div instanceof HTMLElement);
assert.equal(div.tagName, 'DIV');
assert.equal(div.id, 'foo');
assert.strictEqual(div.tagName, 'DIV');
assert.strictEqual(div.id, 'foo');
});
test('should buld nodes with class-name', () => {
const div = $('div.foo');
assert(div);
assert(div instanceof HTMLElement);
assert.equal(div.tagName, 'DIV');
assert.equal(div.className, 'foo');
assert.strictEqual(div.tagName, 'DIV');
assert.strictEqual(div.className, 'foo');
});
test('should build nodes with attributes', () => {
let div = $('div', { class: 'test' });
assert.equal(div.className, 'test');
assert.strictEqual(div.className, 'test');
div = $('div', undefined);
assert.equal(div.className, '');
assert.strictEqual(div.className, '');
});
test('should build nodes with children', () => {
let div = $('div', undefined, $('span', { id: 'demospan' }));
let firstChild = div.firstChild as HTMLElement;
assert.equal(firstChild.tagName, 'SPAN');
assert.equal(firstChild.id, 'demospan');
assert.strictEqual(firstChild.tagName, 'SPAN');
assert.strictEqual(firstChild.id, 'demospan');
div = $('div', undefined, 'hello');
assert.equal(div.firstChild && div.firstChild.textContent, 'hello');
assert.strictEqual(div.firstChild && div.firstChild.textContent, 'hello');
});
test('should build nodes with text children', () => {
let div = $('div', undefined, 'foobar');
let firstChild = div.firstChild as HTMLElement;
assert.equal(firstChild.tagName, undefined);
assert.equal(firstChild.textContent, 'foobar');
assert.strictEqual(firstChild.tagName, undefined);
assert.strictEqual(firstChild.textContent, 'foobar');
});
});
});

View File

@@ -9,53 +9,53 @@ import { sha1Hex } from 'vs/base/browser/hash';
suite('Hash', () => {
test('string', () => {
assert.equal(hash('hello'), hash('hello'));
assert.notEqual(hash('hello'), hash('world'));
assert.notEqual(hash('hello'), hash('olleh'));
assert.notEqual(hash('hello'), hash('Hello'));
assert.notEqual(hash('hello'), hash('Hello '));
assert.notEqual(hash('h'), hash('H'));
assert.notEqual(hash('-'), hash('_'));
assert.strictEqual(hash('hello'), hash('hello'));
assert.notStrictEqual(hash('hello'), hash('world'));
assert.notStrictEqual(hash('hello'), hash('olleh'));
assert.notStrictEqual(hash('hello'), hash('Hello'));
assert.notStrictEqual(hash('hello'), hash('Hello '));
assert.notStrictEqual(hash('h'), hash('H'));
assert.notStrictEqual(hash('-'), hash('_'));
});
test('number', () => {
assert.equal(hash(1), hash(1));
assert.notEqual(hash(0), hash(1));
assert.notEqual(hash(1), hash(-1));
assert.notEqual(hash(0x12345678), hash(0x123456789));
assert.strictEqual(hash(1), hash(1));
assert.notStrictEqual(hash(0), hash(1));
assert.notStrictEqual(hash(1), hash(-1));
assert.notStrictEqual(hash(0x12345678), hash(0x123456789));
});
test('boolean', () => {
assert.equal(hash(true), hash(true));
assert.notEqual(hash(true), hash(false));
assert.strictEqual(hash(true), hash(true));
assert.notStrictEqual(hash(true), hash(false));
});
test('array', () => {
assert.equal(hash([1, 2, 3]), hash([1, 2, 3]));
assert.equal(hash(['foo', 'bar']), hash(['foo', 'bar']));
assert.equal(hash([]), hash([]));
assert.equal(hash([]), hash(new Array()));
assert.notEqual(hash(['foo', 'bar']), hash(['bar', 'foo']));
assert.notEqual(hash(['foo', 'bar']), hash(['bar', 'foo', null]));
assert.notEqual(hash(['foo', 'bar', null]), hash(['bar', 'foo', null]));
assert.notEqual(hash(['foo', 'bar']), hash(['bar', 'foo', undefined]));
assert.notEqual(hash(['foo', 'bar', undefined]), hash(['bar', 'foo', undefined]));
assert.notEqual(hash(['foo', 'bar', null]), hash(['foo', 'bar', undefined]));
assert.strictEqual(hash([1, 2, 3]), hash([1, 2, 3]));
assert.strictEqual(hash(['foo', 'bar']), hash(['foo', 'bar']));
assert.strictEqual(hash([]), hash([]));
assert.strictEqual(hash([]), hash(new Array()));
assert.notStrictEqual(hash(['foo', 'bar']), hash(['bar', 'foo']));
assert.notStrictEqual(hash(['foo', 'bar']), hash(['bar', 'foo', null]));
assert.notStrictEqual(hash(['foo', 'bar', null]), hash(['bar', 'foo', null]));
assert.notStrictEqual(hash(['foo', 'bar']), hash(['bar', 'foo', undefined]));
assert.notStrictEqual(hash(['foo', 'bar', undefined]), hash(['bar', 'foo', undefined]));
assert.notStrictEqual(hash(['foo', 'bar', null]), hash(['foo', 'bar', undefined]));
});
test('object', () => {
assert.equal(hash({}), hash({}));
assert.equal(hash({}), hash(Object.create(null)));
assert.equal(hash({ 'foo': 'bar' }), hash({ 'foo': 'bar' }));
assert.equal(hash({ 'foo': 'bar', 'foo2': undefined }), hash({ 'foo2': undefined, 'foo': 'bar' }));
assert.notEqual(hash({ 'foo': 'bar' }), hash({ 'foo': 'bar2' }));
assert.notEqual(hash({}), hash([]));
assert.strictEqual(hash({}), hash({}));
assert.strictEqual(hash({}), hash(Object.create(null)));
assert.strictEqual(hash({ 'foo': 'bar' }), hash({ 'foo': 'bar' }));
assert.strictEqual(hash({ 'foo': 'bar', 'foo2': undefined }), hash({ 'foo2': undefined, 'foo': 'bar' }));
assert.notStrictEqual(hash({ 'foo': 'bar' }), hash({ 'foo': 'bar2' }));
assert.notStrictEqual(hash({}), hash([]));
});
test('array - unexpected collision', function () {
const a = hash([undefined, undefined, undefined, undefined, undefined]);
const b = hash([undefined, undefined, 'HHHHHH', [{ line: 0, character: 0 }, { line: 0, character: 0 }], undefined]);
assert.notEqual(a, b);
assert.notStrictEqual(a, b);
});
test('all different', () => {
@@ -65,9 +65,9 @@ suite('Hash', () => {
];
const hashes: number[] = candidates.map(hash);
for (let i = 0; i < hashes.length; i++) {
assert.equal(hashes[i], hash(candidates[i])); // verify that repeated invocation returns the same hash
assert.strictEqual(hashes[i], hash(candidates[i])); // verify that repeated invocation returns the same hash
for (let k = i + 1; k < hashes.length; k++) {
assert.notEqual(hashes[i], hashes[k], `Same hash ${hashes[i]} for ${JSON.stringify(candidates[i])} and ${JSON.stringify(candidates[k])}`);
assert.notStrictEqual(hashes[i], hashes[k], `Same hash ${hashes[i]} for ${JSON.stringify(candidates[i])} and ${JSON.stringify(candidates[k])}`);
}
}
});
@@ -79,11 +79,11 @@ suite('Hash', () => {
const hash = new StringSHA1();
hash.update(str);
let actual = hash.digest();
assert.equal(actual, expected);
assert.strictEqual(actual, expected);
// Test with crypto.subtle
actual = await sha1Hex(str);
assert.equal(actual, expected);
assert.strictEqual(actual, expected);
}
test('sha1-1', () => {

View File

@@ -2,6 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
@@ -13,50 +14,50 @@ suite('HighlightedLabel', () => {
});
test('empty label', function () {
assert.equal(label.element.innerHTML, '');
assert.strictEqual(label.element.innerHTML, '');
});
test('no decorations', function () {
label.set('hello');
assert.equal(label.element.innerHTML, '<span>hello</span>');
assert.strictEqual(label.element.innerHTML, '<span>hello</span>');
});
test('escape html', function () {
label.set('hel<lo');
assert.equal(label.element.innerHTML, '<span>hel&lt;lo</span>');
assert.strictEqual(label.element.innerHTML, '<span>hel&lt;lo</span>');
});
test('everything highlighted', function () {
label.set('hello', [{ start: 0, end: 5 }]);
assert.equal(label.element.innerHTML, '<span class="highlight">hello</span>');
assert.strictEqual(label.element.innerHTML, '<span class="highlight">hello</span>');
});
test('beginning highlighted', function () {
label.set('hellothere', [{ start: 0, end: 5 }]);
assert.equal(label.element.innerHTML, '<span class="highlight">hello</span><span>there</span>');
assert.strictEqual(label.element.innerHTML, '<span class="highlight">hello</span><span>there</span>');
});
test('ending highlighted', function () {
label.set('goodbye', [{ start: 4, end: 7 }]);
assert.equal(label.element.innerHTML, '<span>good</span><span class="highlight">bye</span>');
assert.strictEqual(label.element.innerHTML, '<span>good</span><span class="highlight">bye</span>');
});
test('middle highlighted', function () {
label.set('foobarfoo', [{ start: 3, end: 6 }]);
assert.equal(label.element.innerHTML, '<span>foo</span><span class="highlight">bar</span><span>foo</span>');
assert.strictEqual(label.element.innerHTML, '<span>foo</span><span class="highlight">bar</span><span>foo</span>');
});
test('escapeNewLines', () => {
let highlights = [{ start: 0, end: 5 }, { start: 7, end: 9 }, { start: 11, end: 12 }];// before,after,after
let escaped = HighlightedLabel.escapeNewLines('ACTION\r\n_TYPE2', highlights);
assert.equal(escaped, 'ACTION\u23CE_TYPE2');
assert.deepEqual(highlights, [{ start: 0, end: 5 }, { start: 6, end: 8 }, { start: 10, end: 11 }]);
assert.strictEqual(escaped, 'ACTION\u23CE_TYPE2');
assert.deepStrictEqual(highlights, [{ start: 0, end: 5 }, { start: 6, end: 8 }, { start: 10, end: 11 }]);
highlights = [{ start: 5, end: 9 }, { start: 11, end: 12 }];//overlap,after
escaped = HighlightedLabel.escapeNewLines('ACTION\r\n_TYPE2', highlights);
assert.equal(escaped, 'ACTION\u23CE_TYPE2');
assert.deepEqual(highlights, [{ start: 5, end: 8 }, { start: 10, end: 11 }]);
assert.strictEqual(escaped, 'ACTION\u23CE_TYPE2');
assert.deepStrictEqual(highlights, [{ start: 5, end: 8 }, { start: 10, end: 11 }]);
});
});

View File

@@ -3,45 +3,45 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
import * as assert from 'assert';
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
suite('renderLabelWithIcons', () => {
test('no icons', () => {
const result = renderLabelWithIcons(' hello World .');
assert.equal(elementsToString(result), ' hello World .');
assert.strictEqual(elementsToString(result), ' hello World .');
});
test('icons only', () => {
const result = renderLabelWithIcons('$(alert)');
assert.equal(elementsToString(result), '<span class="codicon codicon-alert"></span>');
assert.strictEqual(elementsToString(result), '<span class="codicon codicon-alert"></span>');
});
test('icon and non-icon strings', () => {
const result = renderLabelWithIcons(` $(alert) Unresponsive`);
assert.equal(elementsToString(result), ' <span class="codicon codicon-alert"></span> Unresponsive');
assert.strictEqual(elementsToString(result), ' <span class="codicon codicon-alert"></span> Unresponsive');
});
test('multiple icons', () => {
const result = renderLabelWithIcons('$(check)$(error)');
assert.equal(elementsToString(result), '<span class="codicon codicon-check"></span><span class="codicon codicon-error"></span>');
assert.strictEqual(elementsToString(result), '<span class="codicon codicon-check"></span><span class="codicon codicon-error"></span>');
});
test('escaped icons', () => {
const result = renderLabelWithIcons('\\$(escaped)');
assert.equal(elementsToString(result), '$(escaped)');
assert.strictEqual(elementsToString(result), '$(escaped)');
});
test('icon with animation', () => {
const result = renderLabelWithIcons('$(zip~anim)');
assert.equal(elementsToString(result), '<span class="codicon codicon-zip codicon-modifier-anim"></span>');
assert.strictEqual(elementsToString(result), '<span class="codicon codicon-zip codicon-modifier-anim"></span>');
});
const elementsToString = (elements: Array<HTMLElement | string>): string => {

View File

@@ -9,20 +9,20 @@ import { layout, LayoutAnchorPosition } from 'vs/base/browser/ui/contextview/con
suite('Contextview', function () {
test('layout', () => {
assert.equal(layout(200, 20, { offset: 0, size: 0, position: LayoutAnchorPosition.Before }), 0);
assert.equal(layout(200, 20, { offset: 50, size: 0, position: LayoutAnchorPosition.Before }), 50);
assert.equal(layout(200, 20, { offset: 200, size: 0, position: LayoutAnchorPosition.Before }), 180);
assert.strictEqual(layout(200, 20, { offset: 0, size: 0, position: LayoutAnchorPosition.Before }), 0);
assert.strictEqual(layout(200, 20, { offset: 50, size: 0, position: LayoutAnchorPosition.Before }), 50);
assert.strictEqual(layout(200, 20, { offset: 200, size: 0, position: LayoutAnchorPosition.Before }), 180);
assert.equal(layout(200, 20, { offset: 0, size: 0, position: LayoutAnchorPosition.After }), 0);
assert.equal(layout(200, 20, { offset: 50, size: 0, position: LayoutAnchorPosition.After }), 30);
assert.equal(layout(200, 20, { offset: 200, size: 0, position: LayoutAnchorPosition.After }), 180);
assert.strictEqual(layout(200, 20, { offset: 0, size: 0, position: LayoutAnchorPosition.After }), 0);
assert.strictEqual(layout(200, 20, { offset: 50, size: 0, position: LayoutAnchorPosition.After }), 30);
assert.strictEqual(layout(200, 20, { offset: 200, size: 0, position: LayoutAnchorPosition.After }), 180);
assert.equal(layout(200, 20, { offset: 0, size: 50, position: LayoutAnchorPosition.Before }), 50);
assert.equal(layout(200, 20, { offset: 50, size: 50, position: LayoutAnchorPosition.Before }), 100);
assert.equal(layout(200, 20, { offset: 150, size: 50, position: LayoutAnchorPosition.Before }), 130);
assert.strictEqual(layout(200, 20, { offset: 0, size: 50, position: LayoutAnchorPosition.Before }), 50);
assert.strictEqual(layout(200, 20, { offset: 50, size: 50, position: LayoutAnchorPosition.Before }), 100);
assert.strictEqual(layout(200, 20, { offset: 150, size: 50, position: LayoutAnchorPosition.Before }), 130);
assert.equal(layout(200, 20, { offset: 0, size: 50, position: LayoutAnchorPosition.After }), 50);
assert.equal(layout(200, 20, { offset: 50, size: 50, position: LayoutAnchorPosition.After }), 30);
assert.equal(layout(200, 20, { offset: 150, size: 50, position: LayoutAnchorPosition.After }), 130);
assert.strictEqual(layout(200, 20, { offset: 0, size: 50, position: LayoutAnchorPosition.After }), 50);
assert.strictEqual(layout(200, 20, { offset: 50, size: 50, position: LayoutAnchorPosition.After }), 30);
assert.strictEqual(layout(200, 20, { offset: 150, size: 50, position: LayoutAnchorPosition.After }), 130);
});
});

View File

@@ -807,4 +807,187 @@ suite('Async', () => {
assert.strictEqual(deferred.isRejected, true);
});
});
suite('Promises.allSettled', () => {
test('resolves', async () => {
const p1 = Promise.resolve(1);
const p2 = async.timeout(1).then(() => 2);
const p3 = async.timeout(2).then(() => 3);
const result = await async.Promises.allSettled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], { status: 'fulfilled', value: 1 });
assert.deepStrictEqual(result[1], { status: 'fulfilled', value: 2 });
assert.deepStrictEqual(result[2], { status: 'fulfilled', value: 3 });
});
test('resolves in order', async () => {
const p1 = async.timeout(2).then(() => 1);
const p2 = async.timeout(1).then(() => 2);
const p3 = Promise.resolve(3);
const result = await async.Promises.allSettled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], { status: 'fulfilled', value: 1 });
assert.deepStrictEqual(result[1], { status: 'fulfilled', value: 2 });
assert.deepStrictEqual(result[2], { status: 'fulfilled', value: 3 });
});
test('rejects', async () => {
const p1 = Promise.reject(1);
const p2Error = new Error('2');
const p2 = async.timeout(1).then(() => { throw p2Error; });
const p3Error = new Error('3');
const p3 = async.timeout(2).then(() => { throw p3Error; });
const result = await async.Promises.allSettled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], { status: 'rejected', reason: 1 });
assert.deepStrictEqual(result[1], { status: 'rejected', reason: p2Error });
assert.deepStrictEqual(result[2], { status: 'rejected', reason: p3Error });
});
test('rejects in order', async () => {
const p1Error = new Error('1');
const p1 = async.timeout(2).then(() => { throw p1Error; });
const p2Error = new Error('2');
const p2 = async.timeout(1).then(() => { throw p2Error; });
const p3 = Promise.reject(3);
const result = await async.Promises.allSettled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], { status: 'rejected', reason: p1Error });
assert.deepStrictEqual(result[1], { status: 'rejected', reason: p2Error });
assert.deepStrictEqual(result[2], { status: 'rejected', reason: 3 });
});
test('resolves & rejects', async () => {
const p1 = Promise.resolve(1);
const p2Error = new Error('2');
const p2 = async.timeout(1).then(() => { throw p2Error; });
const p3 = async.timeout(2).then(() => 3);
const result = await async.Promises.allSettled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], { status: 'fulfilled', value: 1 });
assert.deepStrictEqual(result[1], { status: 'rejected', reason: p2Error });
assert.deepStrictEqual(result[2], { status: 'fulfilled', value: 3 });
});
test('resolves & rejects in order', async () => {
const p1Error = new Error('2');
const p1 = async.timeout(1).then(() => { throw p1Error; });
const p2 = async.timeout(2).then(() => 2);
const p3 = Promise.resolve(3);
const result = await async.Promises.allSettled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], { status: 'rejected', reason: p1Error });
assert.deepStrictEqual(result[1], { status: 'fulfilled', value: 2 });
assert.deepStrictEqual(result[2], { status: 'fulfilled', value: 3 });
});
test('can empty', async () => {
const result = await async.Promises.allSettled<number>([]);
assert.strictEqual(result.length, 0);
});
});
suite('Promises.settled', () => {
test('resolves', async () => {
const p1 = Promise.resolve(1);
const p2 = async.timeout(1).then(() => 2);
const p3 = async.timeout(2).then(() => 3);
const result = await async.Promises.settled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
assert.deepStrictEqual(result[2], 3);
});
test('resolves in order', async () => {
const p1 = async.timeout(2).then(() => 1);
const p2 = async.timeout(1).then(() => 2);
const p3 = Promise.resolve(3);
const result = await async.Promises.settled<number>([p1, p2, p3]);
assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
assert.deepStrictEqual(result[2], 3);
});
test('rejects with first error but handles all promises (all errors)', async () => {
const p1 = Promise.reject(1);
let p2Handled = false;
const p2Error = new Error('2');
const p2 = async.timeout(1).then(() => {
p2Handled = true;
throw p2Error;
});
let p3Handled = false;
const p3Error = new Error('3');
const p3 = async.timeout(2).then(() => {
p3Handled = true;
throw p3Error;
});
let error: Error | undefined = undefined;
try {
await async.Promises.settled<number>([p1, p2, p3]);
} catch (e) {
error = e;
}
assert.ok(error);
assert.notStrictEqual(error, p2Error);
assert.notStrictEqual(error, p3Error);
assert.ok(p2Handled);
assert.ok(p3Handled);
});
test('rejects with first error but handles all promises (1 error)', async () => {
const p1 = Promise.resolve(1);
let p2Handled = false;
const p2Error = new Error('2');
const p2 = async.timeout(1).then(() => {
p2Handled = true;
throw p2Error;
});
let p3Handled = false;
const p3 = async.timeout(2).then(() => {
p3Handled = true;
return 3;
});
let error: Error | undefined = undefined;
try {
await async.Promises.settled<number>([p1, p2, p3]);
} catch (e) {
error = e;
}
assert.strictEqual(error, p2Error);
assert.ok(p2Handled);
assert.ok(p3Handled);
});
});
});

View File

@@ -3,10 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Event, Emitter, EventBufferer, EventMultiplexer, IWaitUntil, PauseableEmitter, AsyncEmitter } from 'vs/base/common/event';
import { Event, Emitter, EventBufferer, EventMultiplexer, PauseableEmitter } from 'vs/base/common/event';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import * as Errors from 'vs/base/common/errors';
import { timeout } from 'vs/base/common/async';
import { errorHandler, setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { AsyncEmitter, IWaitUntil, timeout } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
namespace Samples {
@@ -57,7 +57,7 @@ suite('Event', function () {
// unhook listener
subscription.dispose();
doc.setText('boo');
assert.equal(counter.count, 2);
assert.strictEqual(counter.count, 2);
});
@@ -80,7 +80,7 @@ suite('Event', function () {
subscription.dispose();
doc.setText('boo');
assert.equal(counter.count, 2);
assert.strictEqual(counter.count, 2);
});
test('Emitter, store', function () {
@@ -100,7 +100,7 @@ suite('Event', function () {
subscription.dispose();
doc.setText('boo');
assert.equal(counter.count, 2);
assert.strictEqual(counter.count, 2);
});
test('onFirstAdd|onLastRemove', () => {
@@ -112,25 +112,25 @@ suite('Event', function () {
onLastListenerRemove() { lastCount += 1; }
});
assert.equal(firstCount, 0);
assert.equal(lastCount, 0);
assert.strictEqual(firstCount, 0);
assert.strictEqual(lastCount, 0);
let subscription = a.event(function () { });
assert.equal(firstCount, 1);
assert.equal(lastCount, 0);
assert.strictEqual(firstCount, 1);
assert.strictEqual(lastCount, 0);
subscription.dispose();
assert.equal(firstCount, 1);
assert.equal(lastCount, 1);
assert.strictEqual(firstCount, 1);
assert.strictEqual(lastCount, 1);
subscription = a.event(function () { });
assert.equal(firstCount, 2);
assert.equal(lastCount, 1);
assert.strictEqual(firstCount, 2);
assert.strictEqual(lastCount, 1);
});
test('throwingListener', () => {
const origErrorHandler = Errors.errorHandler.getUnexpectedErrorHandler();
Errors.setUnexpectedErrorHandler(() => null);
const origErrorHandler = errorHandler.getUnexpectedErrorHandler();
setUnexpectedErrorHandler(() => null);
try {
let a = new Emitter<undefined>();
@@ -143,10 +143,10 @@ suite('Event', function () {
hit = true;
});
a.fire(undefined);
assert.equal(hit, true);
assert.strictEqual(hit, true);
} finally {
Errors.setUnexpectedErrorHandler(origErrorHandler);
setUnexpectedErrorHandler(origErrorHandler);
}
});
@@ -162,15 +162,15 @@ suite('Event', function () {
let reg2 = emitter.event(listener, context);
emitter.fire(undefined);
assert.equal(counter, 2);
assert.strictEqual(counter, 2);
reg1.dispose();
emitter.fire(undefined);
assert.equal(counter, 3);
assert.strictEqual(counter, 3);
reg2.dispose();
emitter.fire(undefined);
assert.equal(counter, 3);
assert.strictEqual(counter, 3);
});
test('Debounce Event', function (done: () => void) {
@@ -192,9 +192,9 @@ suite('Event', function () {
assert.ok(keys, 'was not expecting keys.');
if (count === 1) {
doc.setText('4');
assert.deepEqual(keys, ['1', '2', '3']);
assert.deepStrictEqual(keys, ['1', '2', '3']);
} else if (count === 2) {
assert.deepEqual(keys, ['4']);
assert.deepStrictEqual(keys, ['4']);
done();
}
});
@@ -217,7 +217,7 @@ suite('Event', function () {
emitter.fire();
await timeout(1);
assert.equal(calls, 1);
assert.strictEqual(calls, 1);
});
test('Debounce Event - leading', async function () {
@@ -234,7 +234,7 @@ suite('Event', function () {
emitter.fire();
emitter.fire();
await timeout(1);
assert.equal(calls, 2);
assert.strictEqual(calls, 2);
});
test('Debounce Event - leading reset', async function () {
@@ -248,7 +248,7 @@ suite('Event', function () {
emitter.fire(1);
await timeout(1);
assert.deepEqual(calls, [1, 1]);
assert.deepStrictEqual(calls, [1, 1]);
});
test('Emitter - In Order Delivery', function () {
@@ -258,7 +258,7 @@ suite('Event', function () {
if (event === 'e1') {
a.fire('e2');
// assert that all events are delivered at this point
assert.deepEqual(listener2Events, ['e1', 'e2']);
assert.deepStrictEqual(listener2Events, ['e1', 'e2']);
}
});
a.event(function listener2(event) {
@@ -267,7 +267,7 @@ suite('Event', function () {
a.fire('e1');
// assert that all events are delivered in order
assert.deepEqual(listener2Events, ['e1', 'e2']);
assert.deepStrictEqual(listener2Events, ['e1', 'e2']);
});
});
@@ -283,9 +283,9 @@ suite('AsyncEmitter', function () {
let emitter = new AsyncEmitter<E>();
emitter.event(e => {
assert.equal(e.foo, true);
assert.equal(e.bar, 1);
assert.equal(typeof e.waitUntil, 'function');
assert.strictEqual(e.foo, true);
assert.strictEqual(e.bar, 1);
assert.strictEqual(typeof e.waitUntil, 'function');
});
emitter.fireAsync({ foo: true, bar: 1, }, CancellationToken.None);
@@ -303,20 +303,20 @@ suite('AsyncEmitter', function () {
emitter.event(e => {
e.waitUntil(timeout(10).then(_ => {
assert.equal(globalState, 0);
assert.strictEqual(globalState, 0);
globalState += 1;
}));
});
emitter.event(e => {
e.waitUntil(timeout(1).then(_ => {
assert.equal(globalState, 1);
assert.strictEqual(globalState, 1);
globalState += 1;
}));
});
await emitter.fireAsync({ foo: true }, CancellationToken.None);
assert.equal(globalState, 2);
assert.strictEqual(globalState, 2);
});
test('sequential, in-order delivery', async function () {
@@ -332,7 +332,7 @@ suite('AsyncEmitter', function () {
e.waitUntil(timeout(10).then(async _ => {
if (e.foo === 1) {
await emitter.fireAsync({ foo: 2 }, CancellationToken.None);
assert.deepEqual(events, [1, 2]);
assert.deepStrictEqual(events, [1, 2]);
done = true;
}
}));
@@ -349,8 +349,8 @@ suite('AsyncEmitter', function () {
});
test('catch errors', async function () {
const origErrorHandler = Errors.errorHandler.getUnexpectedErrorHandler();
Errors.setUnexpectedErrorHandler(() => null);
const origErrorHandler = errorHandler.getUnexpectedErrorHandler();
setUnexpectedErrorHandler(() => null);
interface E extends IWaitUntil {
foo: boolean;
@@ -367,16 +367,17 @@ suite('AsyncEmitter', function () {
emitter.event(e => {
globalState += 1;
e.waitUntil(timeout(10));
e.waitUntil(timeout(20).then(() => globalState++)); // multiple `waitUntil` are supported and awaited on
});
await emitter.fireAsync({ foo: true }, CancellationToken.None).then(() => {
assert.equal(globalState, 2);
assert.strictEqual(globalState, 3);
}).catch(e => {
console.log(e);
assert.ok(false);
});
Errors.setUnexpectedErrorHandler(origErrorHandler);
setUnexpectedErrorHandler(origErrorHandler);
});
});
@@ -390,7 +391,7 @@ suite('PausableEmitter', function () {
emitter.fire(1);
emitter.fire(2);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
});
test('pause/resume - no merge', function () {
@@ -400,17 +401,17 @@ suite('PausableEmitter', function () {
emitter.event(e => data.push(e));
emitter.fire(1);
emitter.fire(2);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.pause();
emitter.fire(3);
emitter.fire(4);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.resume();
assert.deepEqual(data, [1, 2, 3, 4]);
assert.deepStrictEqual(data, [1, 2, 3, 4]);
emitter.fire(5);
assert.deepEqual(data, [1, 2, 3, 4, 5]);
assert.deepStrictEqual(data, [1, 2, 3, 4, 5]);
});
test('pause/resume - merge', function () {
@@ -420,18 +421,18 @@ suite('PausableEmitter', function () {
emitter.event(e => data.push(e));
emitter.fire(1);
emitter.fire(2);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.pause();
emitter.fire(3);
emitter.fire(4);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.resume();
assert.deepEqual(data, [1, 2, 7]);
assert.deepStrictEqual(data, [1, 2, 7]);
emitter.fire(5);
assert.deepEqual(data, [1, 2, 7, 5]);
assert.deepStrictEqual(data, [1, 2, 7, 5]);
});
test('double pause/resume', function () {
@@ -441,22 +442,22 @@ suite('PausableEmitter', function () {
emitter.event(e => data.push(e));
emitter.fire(1);
emitter.fire(2);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.pause();
emitter.pause();
emitter.fire(3);
emitter.fire(4);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.resume();
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.resume();
assert.deepEqual(data, [1, 2, 3, 4]);
assert.deepStrictEqual(data, [1, 2, 3, 4]);
emitter.resume();
assert.deepEqual(data, [1, 2, 3, 4]);
assert.deepStrictEqual(data, [1, 2, 3, 4]);
});
test('resume, no pause', function () {
@@ -466,11 +467,11 @@ suite('PausableEmitter', function () {
emitter.event(e => data.push(e));
emitter.fire(1);
emitter.fire(2);
assert.deepEqual(data, [1, 2]);
assert.deepStrictEqual(data, [1, 2]);
emitter.resume();
emitter.fire(3);
assert.deepEqual(data, [1, 2, 3]);
assert.deepStrictEqual(data, [1, 2, 3]);
});
test('nested pause', function () {
@@ -493,16 +494,16 @@ suite('PausableEmitter', function () {
emitter.pause();
emitter.fire(1);
emitter.fire(2);
assert.deepEqual(data, []);
assert.deepStrictEqual(data, []);
emitter.resume();
assert.deepEqual(data, [1, 1]); // paused after first event
assert.deepStrictEqual(data, [1, 1]); // paused after first event
emitter.resume();
assert.deepEqual(data, [1, 1, 2, 2]); // remaing event delivered
assert.deepStrictEqual(data, [1, 1, 2, 2]); // remaing event delivered
emitter.fire(3);
assert.deepEqual(data, [1, 1, 2, 2, 3, 3]);
assert.deepStrictEqual(data, [1, 1, 2, 2, 3, 3]);
});
});
@@ -518,13 +519,13 @@ suite('Event utils', () => {
const event = bufferer.wrapEvent(emitter.event);
const listener = event(counter.onEvent, counter);
assert.equal(counter.count, 0);
assert.strictEqual(counter.count, 0);
emitter.fire();
assert.equal(counter.count, 1);
assert.strictEqual(counter.count, 1);
emitter.fire();
assert.equal(counter.count, 2);
assert.strictEqual(counter.count, 2);
emitter.fire();
assert.equal(counter.count, 3);
assert.strictEqual(counter.count, 3);
listener.dispose();
});
@@ -536,20 +537,20 @@ suite('Event utils', () => {
const event = bufferer.wrapEvent(emitter.event);
const listener = event(counter.onEvent, counter);
assert.equal(counter.count, 0);
assert.strictEqual(counter.count, 0);
emitter.fire();
assert.equal(counter.count, 1);
assert.strictEqual(counter.count, 1);
bufferer.bufferEvents(() => {
emitter.fire();
assert.equal(counter.count, 1);
assert.strictEqual(counter.count, 1);
emitter.fire();
assert.equal(counter.count, 1);
assert.strictEqual(counter.count, 1);
});
assert.equal(counter.count, 3);
assert.strictEqual(counter.count, 3);
emitter.fire();
assert.equal(counter.count, 4);
assert.strictEqual(counter.count, 4);
listener.dispose();
});
@@ -563,20 +564,20 @@ suite('Event utils', () => {
const listener2 = Event.once(emitter.event)(() => counter2++);
const listener3 = Event.once(emitter.event)(() => counter3++);
assert.equal(counter1, 0);
assert.equal(counter2, 0);
assert.equal(counter3, 0);
assert.strictEqual(counter1, 0);
assert.strictEqual(counter2, 0);
assert.strictEqual(counter3, 0);
listener3.dispose();
emitter.fire();
assert.equal(counter1, 1);
assert.equal(counter2, 1);
assert.equal(counter3, 0);
assert.strictEqual(counter1, 1);
assert.strictEqual(counter2, 1);
assert.strictEqual(counter3, 0);
emitter.fire();
assert.equal(counter1, 2);
assert.equal(counter2, 1);
assert.equal(counter3, 0);
assert.strictEqual(counter1, 2);
assert.strictEqual(counter2, 1);
assert.strictEqual(counter3, 0);
listener1.dispose();
listener2.dispose();
@@ -591,10 +592,10 @@ suite('Event utils', () => {
const event = Event.fromPromise(Promise.resolve(null));
event(() => count++);
assert.equal(count, 0);
assert.strictEqual(count, 0);
await timeout(10);
assert.equal(count, 1);
assert.strictEqual(count, 1);
});
test('should emit when done - setTimeout', async () => {
@@ -604,9 +605,9 @@ suite('Event utils', () => {
const event = Event.fromPromise(promise);
event(() => count++);
assert.equal(count, 0);
assert.strictEqual(count, 0);
await promise;
assert.equal(count, 1);
assert.strictEqual(count, 1);
});
});
@@ -646,14 +647,14 @@ suite('Event utils', () => {
assert.deepEqual(result, []);
const listener = bufferedEvent(num => result.push(num));
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
emitter.fire(4);
assert.deepEqual(result, [1, 2, 3, 4]);
assert.deepStrictEqual(result, [1, 2, 3, 4]);
listener.dispose();
emitter.fire(5);
assert.deepEqual(result, [1, 2, 3, 4]);
assert.deepStrictEqual(result, [1, 2, 3, 4]);
});
test('should buffer events on next tick', async () => {
@@ -668,14 +669,14 @@ suite('Event utils', () => {
assert.deepEqual(result, []);
const listener = bufferedEvent(num => result.push(num));
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
await timeout(10);
emitter.fire(4);
assert.deepEqual(result, [1, 2, 3, 4]);
assert.deepStrictEqual(result, [1, 2, 3, 4]);
listener.dispose();
emitter.fire(5);
assert.deepEqual(result, [1, 2, 3, 4]);
assert.deepStrictEqual(result, [1, 2, 3, 4]);
});
test('should fire initial buffer events', () => {
@@ -690,7 +691,7 @@ suite('Event utils', () => {
assert.deepEqual(result, []);
bufferedEvent(num => result.push(num));
assert.deepEqual(result, [-2, -1, 0, 1, 2, 3]);
assert.deepStrictEqual(result, [-2, -1, 0, 1, 2, 3]);
});
});
@@ -704,10 +705,10 @@ suite('Event utils', () => {
const e1 = new Emitter<number>();
m.add(e1.event);
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
});
test('multiplexer dispose works', () => {
@@ -718,16 +719,16 @@ suite('Event utils', () => {
const e1 = new Emitter<number>();
m.add(e1.event);
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
m.dispose();
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
});
test('event dispose works', () => {
@@ -738,16 +739,16 @@ suite('Event utils', () => {
const e1 = new Emitter<number>();
m.add(e1.event);
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
e1.dispose();
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
});
test('mutliplexer event dispose works', () => {
@@ -758,16 +759,16 @@ suite('Event utils', () => {
const e1 = new Emitter<number>();
const l1 = m.add(e1.event);
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
l1.dispose();
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
e1.fire(0);
assert.deepEqual(result, [0]);
assert.deepStrictEqual(result, [0]);
});
test('hot start works', () => {
@@ -785,7 +786,7 @@ suite('Event utils', () => {
e1.fire(1);
e2.fire(2);
e3.fire(3);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
});
test('cold start works', () => {
@@ -804,7 +805,7 @@ suite('Event utils', () => {
e1.fire(1);
e2.fire(2);
e3.fire(3);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
});
test('late add works', () => {
@@ -825,7 +826,7 @@ suite('Event utils', () => {
m.add(e3.event);
e3.fire(3);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
});
test('add dispose works', () => {
@@ -845,15 +846,15 @@ suite('Event utils', () => {
const e3 = new Emitter<number>();
const l3 = m.add(e3.event);
e3.fire(3);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
l3.dispose();
e3.fire(4);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
e2.fire(4);
e1.fire(5);
assert.deepEqual(result, [1, 2, 3, 4, 5]);
assert.deepStrictEqual(result, [1, 2, 3, 4, 5]);
});
});
@@ -864,31 +865,31 @@ suite('Event utils', () => {
const result: number[] = [];
const listener = event(num => result.push(num));
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
emitter.fire(1);
assert.deepEqual(result, [1]);
assert.deepStrictEqual(result, [1]);
emitter.fire(2);
assert.deepEqual(result, [1, 2]);
assert.deepStrictEqual(result, [1, 2]);
emitter.fire(2);
assert.deepEqual(result, [1, 2]);
assert.deepStrictEqual(result, [1, 2]);
emitter.fire(1);
assert.deepEqual(result, [1, 2, 1]);
assert.deepStrictEqual(result, [1, 2, 1]);
emitter.fire(1);
assert.deepEqual(result, [1, 2, 1]);
assert.deepStrictEqual(result, [1, 2, 1]);
emitter.fire(3);
assert.deepEqual(result, [1, 2, 1, 3]);
assert.deepStrictEqual(result, [1, 2, 1, 3]);
emitter.fire(3);
assert.deepEqual(result, [1, 2, 1, 3]);
assert.deepStrictEqual(result, [1, 2, 1, 3]);
emitter.fire(3);
assert.deepEqual(result, [1, 2, 1, 3]);
assert.deepStrictEqual(result, [1, 2, 1, 3]);
listener.dispose();
});

View File

@@ -5,7 +5,7 @@
import * as assert from 'assert';
import * as extpath from 'vs/base/common/extpath';
import * as platform from 'vs/base/common/platform';
import { isWindows } from 'vs/base/common/platform';
import { CharCode } from 'vs/base/common/charCode';
suite('Paths', () => {
@@ -32,7 +32,7 @@ suite('Paths', () => {
assert.strictEqual(extpath.getRoot('file://foo'), '');
});
(!platform.isWindows ? test.skip : test)('isUNC', () => {
(!isWindows ? test.skip : test)('isUNC', () => {
assert.ok(!extpath.isUNC('foo'));
assert.ok(!extpath.isUNC('/foo'));
assert.ok(!extpath.isUNC('\\foo'));
@@ -51,7 +51,7 @@ suite('Paths', () => {
assert.ok(!extpath.isValidBasename('/test.txt'));
assert.ok(!extpath.isValidBasename('\\test.txt'));
if (platform.isWindows) {
if (isWindows) {
assert.ok(!extpath.isValidBasename('aux'));
assert.ok(!extpath.isValidBasename('Aux'));
assert.ok(!extpath.isValidBasename('LPT0'));
@@ -72,7 +72,7 @@ suite('Paths', () => {
});
test('sanitizeFilePath', () => {
if (platform.isWindows) {
if (isWindows) {
assert.strictEqual(extpath.sanitizeFilePath('.', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.strictEqual(extpath.sanitizeFilePath('', 'C:\\the\\cwd'), 'C:\\the\\cwd');
@@ -108,7 +108,7 @@ suite('Paths', () => {
});
test('isRootOrDriveLetter', () => {
if (platform.isWindows) {
if (isWindows) {
assert.ok(extpath.isRootOrDriveLetter('c:'));
assert.ok(extpath.isRootOrDriveLetter('D:'));
assert.ok(extpath.isRootOrDriveLetter('D:/'));
@@ -122,7 +122,7 @@ suite('Paths', () => {
});
test('hasDriveLetter', () => {
if (platform.isWindows) {
if (isWindows) {
assert.ok(extpath.hasDriveLetter('c:'));
assert.ok(extpath.hasDriveLetter('D:'));
assert.ok(extpath.hasDriveLetter('D:/'));
@@ -136,7 +136,7 @@ suite('Paths', () => {
});
test('getDriveLetter', () => {
if (platform.isWindows) {
if (isWindows) {
assert.strictEqual(extpath.getDriveLetter('c:'), 'c');
assert.strictEqual(extpath.getDriveLetter('D:'), 'D');
assert.strictEqual(extpath.getDriveLetter('D:/'), 'D');

View File

@@ -4,13 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as scorer from 'vs/base/common/fuzzyScorer';
import { IItemAccessor, FuzzyScore, FuzzyScore2, IItemScore, prepareQuery, scoreFuzzy, scoreFuzzy2, scoreItemFuzzy, compareItemsByFuzzyScore, pieceToQuery } from 'vs/base/common/fuzzyScorer';
import { URI } from 'vs/base/common/uri';
import { basename, dirname, sep, posix, win32 } from 'vs/base/common/path';
import { isWindows } from 'vs/base/common/platform';
import { Schemas } from 'vs/base/common/network';
class ResourceAccessorClass implements scorer.IItemAccessor<URI> {
class ResourceAccessorClass implements IItemAccessor<URI> {
getItemLabel(resource: URI): string {
return basename(resource.fsPath);
@@ -27,7 +27,7 @@ class ResourceAccessorClass implements scorer.IItemAccessor<URI> {
const ResourceAccessor = new ResourceAccessorClass();
class ResourceWithSlashAccessorClass implements scorer.IItemAccessor<URI> {
class ResourceWithSlashAccessorClass implements IItemAccessor<URI> {
getItemLabel(resource: URI): string {
return basename(resource.fsPath);
@@ -44,7 +44,7 @@ class ResourceWithSlashAccessorClass implements scorer.IItemAccessor<URI> {
const ResourceWithSlashAccessor = new ResourceWithSlashAccessorClass();
class ResourceWithBackslashAccessorClass implements scorer.IItemAccessor<URI> {
class ResourceWithBackslashAccessorClass implements IItemAccessor<URI> {
getItemLabel(resource: URI): string {
return basename(resource.fsPath);
@@ -61,7 +61,7 @@ class ResourceWithBackslashAccessorClass implements scorer.IItemAccessor<URI> {
const ResourceWithBackslashAccessor = new ResourceWithBackslashAccessorClass();
class NullAccessorClass implements scorer.IItemAccessor<URI> {
class NullAccessorClass implements IItemAccessor<URI> {
getItemLabel(resource: URI): string {
return undefined!;
@@ -76,24 +76,24 @@ class NullAccessorClass implements scorer.IItemAccessor<URI> {
}
}
function _doScore(target: string, query: string, fuzzy: boolean): scorer.FuzzyScore {
const preparedQuery = scorer.prepareQuery(query);
function _doScore(target: string, query: string, fuzzy: boolean): FuzzyScore {
const preparedQuery = prepareQuery(query);
return scorer.scoreFuzzy(target, preparedQuery.normalized, preparedQuery.normalizedLowercase, fuzzy);
return scoreFuzzy(target, preparedQuery.normalized, preparedQuery.normalizedLowercase, fuzzy);
}
function _doScore2(target: string, query: string, matchOffset: number = 0): scorer.FuzzyScore2 {
const preparedQuery = scorer.prepareQuery(query);
function _doScore2(target: string, query: string, matchOffset: number = 0): FuzzyScore2 {
const preparedQuery = prepareQuery(query);
return scorer.scoreFuzzy2(target, preparedQuery, 0, matchOffset);
return scoreFuzzy2(target, preparedQuery, 0, matchOffset);
}
function scoreItem<T>(item: T, query: string, fuzzy: boolean, accessor: scorer.IItemAccessor<T>): scorer.IItemScore {
return scorer.scoreItemFuzzy(item, scorer.prepareQuery(query), fuzzy, accessor, Object.create(null));
function scoreItem<T>(item: T, query: string, fuzzy: boolean, accessor: IItemAccessor<T>): IItemScore {
return scoreItemFuzzy(item, prepareQuery(query), fuzzy, accessor, Object.create(null));
}
function compareItemsByScore<T>(itemA: T, itemB: T, query: string, fuzzy: boolean, accessor: scorer.IItemAccessor<T>): number {
return scorer.compareItemsByFuzzyScore(itemA, itemB, scorer.prepareQuery(query), fuzzy, accessor, Object.create(null));
function compareItemsByScore<T>(itemA: T, itemB: T, query: string, fuzzy: boolean, accessor: IItemAccessor<T>): number {
return compareItemsByFuzzyScore(itemA, itemB, prepareQuery(query), fuzzy, accessor, Object.create(null));
}
const NullAccessor = new NullAccessorClass();
@@ -103,7 +103,7 @@ suite('Fuzzy Scorer', () => {
test('score (fuzzy)', function () {
const target = 'HeLlo-World';
const scores: scorer.FuzzyScore[] = [];
const scores: FuzzyScore[] = [];
scores.push(_doScore(target, 'HelLo-World', true)); // direct case match
scores.push(_doScore(target, 'hello-world', true)); // direct mix-case match
scores.push(_doScore(target, 'HW', true)); // direct case prefix (multiple)
@@ -1071,16 +1071,16 @@ suite('Fuzzy Scorer', () => {
});
test('prepareQuery', () => {
assert.strictEqual(scorer.prepareQuery(' f*a ').normalized, 'fa');
assert.strictEqual(scorer.prepareQuery('model Tester.ts').original, 'model Tester.ts');
assert.strictEqual(scorer.prepareQuery('model Tester.ts').originalLowercase, 'model Tester.ts'.toLowerCase());
assert.strictEqual(scorer.prepareQuery('model Tester.ts').normalized, 'modelTester.ts');
assert.strictEqual(scorer.prepareQuery('Model Tester.ts').normalizedLowercase, 'modeltester.ts');
assert.strictEqual(scorer.prepareQuery('ModelTester.ts').containsPathSeparator, false);
assert.strictEqual(scorer.prepareQuery('Model' + sep + 'Tester.ts').containsPathSeparator, true);
assert.strictEqual(prepareQuery(' f*a ').normalized, 'fa');
assert.strictEqual(prepareQuery('model Tester.ts').original, 'model Tester.ts');
assert.strictEqual(prepareQuery('model Tester.ts').originalLowercase, 'model Tester.ts'.toLowerCase());
assert.strictEqual(prepareQuery('model Tester.ts').normalized, 'modelTester.ts');
assert.strictEqual(prepareQuery('Model Tester.ts').normalizedLowercase, 'modeltester.ts');
assert.strictEqual(prepareQuery('ModelTester.ts').containsPathSeparator, false);
assert.strictEqual(prepareQuery('Model' + sep + 'Tester.ts').containsPathSeparator, true);
// with spaces
let query = scorer.prepareQuery('He*llo World');
let query = prepareQuery('He*llo World');
assert.strictEqual(query.original, 'He*llo World');
assert.strictEqual(query.normalized, 'HelloWorld');
assert.strictEqual(query.normalizedLowercase, 'HelloWorld'.toLowerCase());
@@ -1092,13 +1092,13 @@ suite('Fuzzy Scorer', () => {
assert.strictEqual(query.values?.[1].normalized, 'World');
assert.strictEqual(query.values?.[1].normalizedLowercase, 'World'.toLowerCase());
let restoredQuery = scorer.pieceToQuery(query.values!);
let restoredQuery = pieceToQuery(query.values!);
assert.strictEqual(restoredQuery.original, query.original);
assert.strictEqual(restoredQuery.values?.length, query.values?.length);
assert.strictEqual(restoredQuery.containsPathSeparator, query.containsPathSeparator);
// with spaces that are empty
query = scorer.prepareQuery(' Hello World ');
query = prepareQuery(' Hello World ');
assert.strictEqual(query.original, ' Hello World ');
assert.strictEqual(query.originalLowercase, ' Hello World '.toLowerCase());
assert.strictEqual(query.normalized, 'HelloWorld');
@@ -1115,19 +1115,19 @@ suite('Fuzzy Scorer', () => {
// Path related
if (isWindows) {
assert.strictEqual(scorer.prepareQuery('C:\\some\\path').pathNormalized, 'C:\\some\\path');
assert.strictEqual(scorer.prepareQuery('C:\\some\\path').normalized, 'C:\\some\\path');
assert.strictEqual(scorer.prepareQuery('C:\\some\\path').containsPathSeparator, true);
assert.strictEqual(scorer.prepareQuery('C:/some/path').pathNormalized, 'C:\\some\\path');
assert.strictEqual(scorer.prepareQuery('C:/some/path').normalized, 'C:\\some\\path');
assert.strictEqual(scorer.prepareQuery('C:/some/path').containsPathSeparator, true);
assert.strictEqual(prepareQuery('C:\\some\\path').pathNormalized, 'C:\\some\\path');
assert.strictEqual(prepareQuery('C:\\some\\path').normalized, 'C:\\some\\path');
assert.strictEqual(prepareQuery('C:\\some\\path').containsPathSeparator, true);
assert.strictEqual(prepareQuery('C:/some/path').pathNormalized, 'C:\\some\\path');
assert.strictEqual(prepareQuery('C:/some/path').normalized, 'C:\\some\\path');
assert.strictEqual(prepareQuery('C:/some/path').containsPathSeparator, true);
} else {
assert.strictEqual(scorer.prepareQuery('/some/path').pathNormalized, '/some/path');
assert.strictEqual(scorer.prepareQuery('/some/path').normalized, '/some/path');
assert.strictEqual(scorer.prepareQuery('/some/path').containsPathSeparator, true);
assert.strictEqual(scorer.prepareQuery('\\some\\path').pathNormalized, '/some/path');
assert.strictEqual(scorer.prepareQuery('\\some\\path').normalized, '/some/path');
assert.strictEqual(scorer.prepareQuery('\\some\\path').containsPathSeparator, true);
assert.strictEqual(prepareQuery('/some/path').pathNormalized, '/some/path');
assert.strictEqual(prepareQuery('/some/path').normalized, '/some/path');
assert.strictEqual(prepareQuery('/some/path').containsPathSeparator, true);
assert.strictEqual(prepareQuery('\\some\\path').pathNormalized, '/some/path');
assert.strictEqual(prepareQuery('\\some\\path').normalized, '/some/path');
assert.strictEqual(prepareQuery('\\some\\path').containsPathSeparator, true);
}
});

View File

@@ -2,9 +2,10 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as path from 'vs/base/common/path';
import * as glob from 'vs/base/common/glob';
import { sep } from 'vs/base/common/path';
import { isWindows } from 'vs/base/common/platform';
suite('Glob', () => {
@@ -952,7 +953,7 @@ suite('Glob', () => {
}
function nativeSep(slashPath: string): string {
return slashPath.replace(/\//g, path.sep);
return slashPath.replace(/\//g, sep);
}
test('relative pattern - glob star', function () {

View File

@@ -5,7 +5,7 @@
import * as assert from 'assert';
import { IMatch } from 'vs/base/common/filters';
import { matchesFuzzyIconAware, parseLabelWithIcons, IParsedLabelWithIcons, stripIcons } from 'vs/base/common/iconLabels';
import { matchesFuzzyIconAware, parseLabelWithIcons, IParsedLabelWithIcons, stripIcons, escapeIcons, markdownEscapeEscapedIcons } from 'vs/base/common/iconLabels';
export interface IIconFilter {
// Returns null if word doesn't match.
@@ -66,9 +66,23 @@ suite('Icon Labels', () => {
});
test('stripIcons', () => {
assert.equal(stripIcons('Hello World'), 'Hello World');
assert.equal(stripIcons('$(Hello World'), '$(Hello World');
assert.equal(stripIcons('$(Hello) World'), ' World');
assert.equal(stripIcons('$(Hello) W$(oi)rld'), ' Wrld');
assert.strictEqual(stripIcons('Hello World'), 'Hello World');
assert.strictEqual(stripIcons('$(Hello World'), '$(Hello World');
assert.strictEqual(stripIcons('$(Hello) World'), ' World');
assert.strictEqual(stripIcons('$(Hello) W$(oi)rld'), ' Wrld');
});
test('escapeIcons', () => {
assert.strictEqual(escapeIcons('Hello World'), 'Hello World');
assert.strictEqual(escapeIcons('$(Hello World'), '$(Hello World');
assert.strictEqual(escapeIcons('$(Hello) World'), '\\$(Hello) World');
assert.strictEqual(escapeIcons('\\$(Hello) W$(oi)rld'), '\\$(Hello) W\\$(oi)rld');
});
test('markdownEscapeEscapedIcons', () => {
assert.strictEqual(markdownEscapeEscapedIcons('Hello World'), 'Hello World');
assert.strictEqual(markdownEscapeEscapedIcons('$(Hello) World'), '$(Hello) World');
assert.strictEqual(markdownEscapeEscapedIcons('\\$(Hello) World'), '\\\\$(Hello) World');
});
});

View File

@@ -25,4 +25,11 @@ suite('Iterable', function () {
assert.equal(Iterable.first(customIterable), 'one'); // fresh
});
test('equals', () => {
assert.strictEqual(Iterable.equals([1, 2], [1, 2]), true);
assert.strictEqual(Iterable.equals([1, 2], [1]), false);
assert.strictEqual(Iterable.equals([1], [1, 2]), false);
assert.strictEqual(Iterable.equals([2, 1], [1, 2]), false);
});
});

View File

@@ -5,10 +5,10 @@
import * as assert from 'assert';
import * as labels from 'vs/base/common/labels';
import * as platform from 'vs/base/common/platform';
import { isMacintosh, isWindows } from 'vs/base/common/platform';
suite('Labels', () => {
(!platform.isWindows ? test.skip : test)('shorten - windows', () => {
(!isWindows ? test.skip : test)('shorten - windows', () => {
// nothing to shorten
assert.deepStrictEqual(labels.shorten(['a']), ['a']);
@@ -59,7 +59,7 @@ suite('Labels', () => {
assert.deepStrictEqual(labels.shorten(['src\\vs\\workbench\\parts\\execution\\electron-browser', 'src\\vs\\workbench\\parts\\execution\\electron-browser\\something', 'src\\vs\\workbench\\parts\\terminal\\electron-browser']), ['…\\execution\\electron-browser', '…\\something', '…\\terminal\\…']);
});
(platform.isWindows ? test.skip : test)('shorten - not windows', () => {
(isWindows ? test.skip : test)('shorten - not windows', () => {
// nothing to shorten
assert.deepStrictEqual(labels.shorten(['a']), ['a']);
@@ -134,13 +134,13 @@ suite('Labels', () => {
assert.strictEqual(labels.template(t, { dirty: '* ', activeEditorShort: 'somefile.txt', rootName: 'monaco', appName: 'Visual Studio Code', separator: { label: ' - ' } }), '* somefile.txt - monaco - Visual Studio Code');
});
(platform.isWindows ? test.skip : test)('getBaseLabel - unix', () => {
(isWindows ? test.skip : test)('getBaseLabel - unix', () => {
assert.strictEqual(labels.getBaseLabel('/some/folder/file.txt'), 'file.txt');
assert.strictEqual(labels.getBaseLabel('/some/folder'), 'folder');
assert.strictEqual(labels.getBaseLabel('/'), '/');
});
(!platform.isWindows ? test.skip : test)('getBaseLabel - windows', () => {
(!isWindows ? test.skip : test)('getBaseLabel - windows', () => {
assert.strictEqual(labels.getBaseLabel('c:'), 'C:');
assert.strictEqual(labels.getBaseLabel('c:\\'), 'C:');
assert.strictEqual(labels.getBaseLabel('c:\\some\\folder\\file.txt'), 'file.txt');
@@ -151,10 +151,10 @@ suite('Labels', () => {
test('mnemonicButtonLabel', () => {
assert.strictEqual(labels.mnemonicButtonLabel('Hello World'), 'Hello World');
assert.strictEqual(labels.mnemonicButtonLabel(''), '');
if (platform.isWindows) {
if (isWindows) {
assert.strictEqual(labels.mnemonicButtonLabel('Hello & World'), 'Hello && World');
assert.strictEqual(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do &not Save && Continue');
} else if (platform.isMacintosh) {
} else if (isMacintosh) {
assert.strictEqual(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.strictEqual(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do not Save & Continue');
} else {

View File

@@ -2,6 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { DisposableStore, dispose, IDisposable, MultiDisposeError, ReferenceCollection, toDisposable } from 'vs/base/common/lifecycle';
@@ -95,8 +96,8 @@ suite('Lifecycle', () => {
let array = [{ dispose() { } }, { dispose() { } }];
let array2 = dispose(array);
assert.equal(array.length, 2);
assert.equal(array2.length, 0);
assert.strictEqual(array.length, 2);
assert.strictEqual(array2.length, 0);
assert.ok(array !== array2);
let set = new Set<IDisposable>([{ dispose() { } }, { dispose() { } }]);
@@ -165,27 +166,27 @@ suite('Reference Collection', () => {
const ref1 = collection.acquire('test');
assert(ref1);
assert.equal(ref1.object, 4);
assert.equal(collection.count, 1);
assert.strictEqual(ref1.object, 4);
assert.strictEqual(collection.count, 1);
ref1.dispose();
assert.equal(collection.count, 0);
assert.strictEqual(collection.count, 0);
const ref2 = collection.acquire('test');
const ref3 = collection.acquire('test');
assert.equal(ref2.object, ref3.object);
assert.equal(collection.count, 1);
assert.strictEqual(ref2.object, ref3.object);
assert.strictEqual(collection.count, 1);
const ref4 = collection.acquire('monkey');
assert.equal(ref4.object, 6);
assert.equal(collection.count, 2);
assert.strictEqual(ref4.object, 6);
assert.strictEqual(collection.count, 2);
ref2.dispose();
assert.equal(collection.count, 2);
assert.strictEqual(collection.count, 2);
ref3.dispose();
assert.equal(collection.count, 1);
assert.strictEqual(collection.count, 1);
ref4.dispose();
assert.equal(collection.count, 0);
assert.strictEqual(collection.count, 0);
});
});

View File

@@ -132,6 +132,5 @@ suite('LinkedList', function () {
let b = list.pop();
assert.strictEqual(b, 'b');
assertElements(list, 'a');
});
});

View File

@@ -8,61 +8,61 @@ import { parseLinkedText } from 'vs/base/common/linkedText';
suite('LinkedText', () => {
test('parses correctly', () => {
assert.deepEqual(parseLinkedText('').nodes, []);
assert.deepEqual(parseLinkedText('hello').nodes, ['hello']);
assert.deepEqual(parseLinkedText('hello there').nodes, ['hello there']);
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href).').nodes, [
assert.deepStrictEqual(parseLinkedText('').nodes, []);
assert.deepStrictEqual(parseLinkedText('hello').nodes, ['hello']);
assert.deepStrictEqual(parseLinkedText('hello there').nodes, ['hello there']);
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href).').nodes, [
'Some message with ',
{ label: 'link text', href: 'http://link.href' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href "and a title").').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href "and a title").').nodes, [
'Some message with ',
{ label: 'link text', href: 'http://link.href', title: 'and a title' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href \'and a title\').').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href \'and a title\').').nodes, [
'Some message with ',
{ label: 'link text', href: 'http://link.href', title: 'and a title' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href "and a \'title\'").').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href "and a \'title\'").').nodes, [
'Some message with ',
{ label: 'link text', href: 'http://link.href', title: 'and a \'title\'' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href \'and a "title"\').').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href \'and a "title"\').').nodes, [
'Some message with ',
{ label: 'link text', href: 'http://link.href', title: 'and a "title"' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [link text](random stuff).').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [link text](random stuff).').nodes, [
'Some message with [link text](random stuff).'
]);
assert.deepEqual(parseLinkedText('Some message with [https link](https://link.href).').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [https link](https://link.href).').nodes, [
'Some message with ',
{ label: 'https link', href: 'https://link.href' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [https link](https:).').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [https link](https:).').nodes, [
'Some message with [https link](https:).'
]);
assert.deepEqual(parseLinkedText('Some message with [a command](command:foobar).').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [a command](command:foobar).').nodes, [
'Some message with ',
{ label: 'a command', href: 'command:foobar' },
'.'
]);
assert.deepEqual(parseLinkedText('Some message with [a command](command:).').nodes, [
assert.deepStrictEqual(parseLinkedText('Some message with [a command](command:).').nodes, [
'Some message with [a command](command:).'
]);
assert.deepEqual(parseLinkedText('link [one](command:foo "nice") and link [two](http://foo)...').nodes, [
assert.deepStrictEqual(parseLinkedText('link [one](command:foo "nice") and link [two](http://foo)...').nodes, [
'link ',
{ label: 'one', href: 'command:foo', title: 'nice' },
' and link ',
{ label: 'two', href: 'http://foo' },
'...'
]);
assert.deepEqual(parseLinkedText('link\n[one](command:foo "nice")\nand link [two](http://foo)...').nodes, [
assert.deepStrictEqual(parseLinkedText('link\n[one](command:foo "nice")\nand link [two](http://foo)...').nodes, [
'link\n',
{ label: 'one', href: 'command:foo', title: 'nice' },
'\nand link ',

View File

@@ -3,10 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceMap, TernarySearchTree, PathIterator, StringIterator, LinkedMap, Touch, LRUCache, UriIterator, ConfigKeysIterator } from 'vs/base/common/map';
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { ConfigKeysIterator, LinkedMap, LRUCache, PathIterator, ResourceMap, StringIterator, TernarySearchTree, Touch, UriIterator } from 'vs/base/common/map';
import { extUriIgnorePathCase } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
suite('Map', () => {

View File

@@ -19,52 +19,52 @@ suite('network', () => {
let browserUri = FileAccess.asBrowserUri(originalFileUri);
assert.ok(browserUri.authority.length > 0);
let fileUri = FileAccess.asFileUri(browserUri);
assert.equal(fileUri.authority.length, 0);
assert.strictEqual(fileUri.authority.length, 0);
assert(isEqual(originalFileUri, fileUri));
// asCodeUri() & asFileUri(): with authority
originalFileUri = URI.file('network.test.ts').with({ authority: 'test-authority' });
browserUri = FileAccess.asBrowserUri(originalFileUri);
assert.equal(browserUri.authority, originalFileUri.authority);
assert.strictEqual(browserUri.authority, originalFileUri.authority);
fileUri = FileAccess.asFileUri(browserUri);
assert(isEqual(originalFileUri, fileUri));
});
(!enableTest ? test.skip : test)('FileAccess: moduleId (native)', () => {
const browserUri = FileAccess.asBrowserUri('vs/base/test/node/network.test', require);
assert.equal(browserUri.scheme, Schemas.vscodeFileResource);
assert.strictEqual(browserUri.scheme, Schemas.vscodeFileResource);
const fileUri = FileAccess.asFileUri('vs/base/test/node/network.test', require);
assert.equal(fileUri.scheme, Schemas.file);
assert.strictEqual(fileUri.scheme, Schemas.file);
});
(!enableTest ? test.skip : test)('FileAccess: query and fragment is dropped (native)', () => {
let originalFileUri = URI.file('network.test.ts').with({ query: 'foo=bar', fragment: 'something' });
let browserUri = FileAccess.asBrowserUri(originalFileUri);
assert.equal(browserUri.query, '');
assert.equal(browserUri.fragment, '');
assert.strictEqual(browserUri.query, '');
assert.strictEqual(browserUri.fragment, '');
});
(!enableTest ? test.skip : test)('FileAccess: query and fragment is kept if URI is already of same scheme (native)', () => {
let originalFileUri = URI.file('network.test.ts').with({ query: 'foo=bar', fragment: 'something' });
let browserUri = FileAccess.asBrowserUri(originalFileUri.with({ scheme: Schemas.vscodeFileResource }));
assert.equal(browserUri.query, 'foo=bar');
assert.equal(browserUri.fragment, 'something');
assert.strictEqual(browserUri.query, 'foo=bar');
assert.strictEqual(browserUri.fragment, 'something');
let fileUri = FileAccess.asFileUri(originalFileUri);
assert.equal(fileUri.query, 'foo=bar');
assert.equal(fileUri.fragment, 'something');
assert.strictEqual(fileUri.query, 'foo=bar');
assert.strictEqual(fileUri.fragment, 'something');
});
(!enableTest ? test.skip : test)('FileAccess: web', () => {
const originalHttpsUri = URI.file('network.test.ts').with({ scheme: 'https' });
const browserUri = FileAccess.asBrowserUri(originalHttpsUri);
assert.equal(originalHttpsUri.toString(), browserUri.toString());
assert.strictEqual(originalHttpsUri.toString(), browserUri.toString());
});
test('FileAccess: remote URIs', () => {
const originalRemoteUri = URI.file('network.test.ts').with({ scheme: Schemas.vscodeRemote });
const browserUri = FileAccess.asBrowserUri(originalRemoteUri);
assert.notEqual(originalRemoteUri.scheme, browserUri.scheme);
assert.notStrictEqual(originalRemoteUri.scheme, browserUri.scheme);
});
});

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { isReadableStream, newWriteableStream, Readable, consumeReadable, peekReadable, consumeStream, ReadableStream, toStream, toReadable, transform, peekStream, isReadableBufferedStream, observe } from 'vs/base/common/stream';
import { isReadableStream, newWriteableStream, Readable, consumeReadable, peekReadable, consumeStream, ReadableStream, toStream, toReadable, transform, peekStream, isReadableBufferedStream, listenStream } from 'vs/base/common/stream';
import { timeout } from 'vs/base/common/async';
suite('Stream', () => {
@@ -69,6 +69,7 @@ suite('Stream', () => {
stream.end('Final Bit');
assert.strictEqual(chunks.length, 4);
assert.strictEqual(chunks[3], 'Final Bit');
assert.strictEqual(end, true);
stream.destroy();
@@ -76,6 +77,15 @@ suite('Stream', () => {
assert.strictEqual(chunks.length, 4);
});
test('WriteableStream - end with empty string works', async () => {
const reducer = (strings: string[]) => strings.length > 0 ? strings.join() : 'error';
const stream = newWriteableStream<string>(reducer);
stream.end('');
const result = await consumeStream(stream, reducer);
assert.strictEqual(result, '');
});
test('WriteableStream - removeListener', () => {
const stream = newWriteableStream<string>(strings => strings.join());
@@ -270,6 +280,56 @@ suite('Stream', () => {
assert.strictEqual(consumed, '1,2,3,4,5');
});
test('consumeStream - without reducer', async () => {
const stream = readableToStream(arrayToReadable(['1', '2', '3', '4', '5']));
const consumed = await consumeStream(stream);
assert.strictEqual(consumed, undefined);
});
test('consumeStream - without reducer and error', async () => {
const stream = newWriteableStream<string>(strings => strings.join());
stream.error(new Error());
const consumed = await consumeStream(stream);
assert.strictEqual(consumed, undefined);
});
test('listenStream', () => {
const stream = newWriteableStream<string>(strings => strings.join());
let error = false;
let end = false;
let data = '';
listenStream(stream, {
onData: d => {
data = d;
},
onError: e => {
error = true;
},
onEnd: () => {
end = true;
}
});
stream.write('Hello');
assert.strictEqual(data, 'Hello');
stream.write('World');
assert.strictEqual(data, 'World');
assert.strictEqual(error, false);
assert.strictEqual(end, false);
stream.error(new Error());
assert.strictEqual(error, true);
stream.end('Final Bit');
assert.strictEqual(end, true);
});
test('peekStream', async () => {
for (let i = 0; i < 5; i++) {
const stream = readableToStream(arrayToReadable(['1', '2', '3', '4', '5']));
@@ -335,30 +395,6 @@ suite('Stream', () => {
assert.strictEqual(consumed, '11,22,33,44,55');
});
test('observer', async () => {
const source1 = newWriteableStream<string>(strings => strings.join());
setTimeout(() => source1.error(new Error()));
await observe(source1).errorOrEnd();
const source2 = newWriteableStream<string>(strings => strings.join());
setTimeout(() => source2.end('Hello Test'));
await observe(source2).errorOrEnd();
const source3 = newWriteableStream<string>(strings => strings.join());
setTimeout(() => {
source3.write('Hello Test');
source3.error(new Error());
});
await observe(source3).errorOrEnd();
const source4 = newWriteableStream<string>(strings => strings.join());
setTimeout(() => {
source4.write('Hello Test');
source4.end();
});
await observe(source4).errorOrEnd();
});
test('events are delivered even if a listener is removed during delivery', () => {
const stream = newWriteableStream<string>(strings => strings.join());

View File

@@ -215,6 +215,11 @@ suite('Strings', () => {
assert.strictEqual(strings.containsEmoji('1F1F7 1F1F4 # 🇷🇴 Romania'), true);
});
test('issue #115221: isEmojiImprecise misses ⭐', () => {
const codePoint = strings.getNextCodePoint('⭐', '⭐'.length, 0);
assert.strictEqual(strings.isEmojiImprecise(codePoint), true);
});
test('isBasicASCII', () => {
function assertIsBasicASCII(str: string, expected: boolean): void {
assert.strictEqual(strings.isBasicASCII(str), expected, str + ` (${str.charCodeAt(0)})`);

View File

@@ -6,7 +6,8 @@
import { checksum } from 'vs/base/node/crypto';
import { join } from 'vs/base/common/path';
import { tmpdir } from 'os';
import { mkdirp, rimraf, writeFile } from 'vs/base/node/pfs';
import { promises } from 'fs';
import { rimraf, writeFile } from 'vs/base/node/pfs';
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
suite('Crypto', () => {
@@ -16,7 +17,7 @@ suite('Crypto', () => {
setup(function () {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'crypto');
return mkdirp(testDir);
return promises.mkdir(testDir, { recursive: true });
});
teardown(function () {

View File

@@ -5,7 +5,8 @@
import * as assert from 'assert';
import { tmpdir } from 'os';
import { mkdirp, rimraf } from 'vs/base/node/pfs';
import { promises } from 'fs';
import { rimraf } from 'vs/base/node/pfs';
import { realcaseSync, realpath, realpathSync } from 'vs/base/node/extpath';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
@@ -15,7 +16,7 @@ flakySuite('Extpath', () => {
setup(() => {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'extpath');
return mkdirp(testDir, 493);
return promises.mkdir(testDir, { recursive: true });
});
teardown(() => {

View File

@@ -8,12 +8,13 @@ import * as fs from 'fs';
import { tmpdir } from 'os';
import { join, sep } from 'vs/base/common/path';
import { generateUuid } from 'vs/base/common/uuid';
import { copy, exists, mkdirp, move, readdir, readDirsInDir, readdirWithFileTypes, readFile, renameIgnoreError, rimraf, RimRafMode, rimrafSync, statLink, writeFile, writeFileSync } from 'vs/base/node/pfs';
import { copy, exists, move, readdir, readDirsInDir, rimraf, RimRafMode, rimrafSync, SymlinkSupport, writeFile, writeFileSync } from 'vs/base/node/pfs';
import { timeout } from 'vs/base/common/async';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { canNormalize } from 'vs/base/common/normalization';
import { VSBuffer } from 'vs/base/common/buffer';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { isWindows } from 'vs/base/common/platform';
flakySuite('PFS', function () {
@@ -22,7 +23,7 @@ flakySuite('PFS', function () {
setup(() => {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
return mkdirp(testDir, 493);
return fs.promises.mkdir(testDir, { recursive: true });
});
teardown(() => {
@@ -36,7 +37,7 @@ flakySuite('PFS', function () {
await writeFile(testFile, 'Hello World', (null!));
assert.strictEqual((await readFile(testFile)).toString(), 'Hello World');
assert.strictEqual((await fs.promises.readFile(testFile)).toString(), 'Hello World');
});
test('writeFile - parallel write on different files works', async () => {
@@ -153,10 +154,6 @@ flakySuite('PFS', function () {
assert.ok(!fs.existsSync(testDir));
});
test('moveIgnoreError', () => {
return renameIgnoreError(join(testDir, 'foo'), join(testDir, 'bar'));
});
test('copy, move and delete', async () => {
const id = generateUuid();
const id2 = generateUuid();
@@ -165,7 +162,7 @@ flakySuite('PFS', function () {
const targetDir = join(parentDir, id);
const targetDir2 = join(parentDir, id2);
await copy(sourceDir, targetDir);
await copy(sourceDir, targetDir, { preserveSymlinks: true });
assert.ok(fs.existsSync(targetDir));
assert.ok(fs.existsSync(join(targetDir, 'index.html')));
@@ -194,33 +191,103 @@ flakySuite('PFS', function () {
assert.ok(!fs.existsSync(parentDir));
});
test('copy skips over dangling symbolic links', async () => {
test('copy handles symbolic links', async () => {
const id1 = generateUuid();
const symbolicLinkTarget = join(testDir, id1);
const id2 = generateUuid();
const symbolicLink = join(testDir, id2);
const symLink = join(testDir, id2);
const id3 = generateUuid();
const copyTarget = join(testDir, id3);
await mkdirp(symbolicLinkTarget, 493);
await fs.promises.mkdir(symbolicLinkTarget, { recursive: true });
fs.symlinkSync(symbolicLinkTarget, symbolicLink, 'junction');
fs.symlinkSync(symbolicLinkTarget, symLink, 'junction');
// Copy preserves symlinks if configured as such
//
// Windows: this test does not work because creating symlinks
// requires priviledged permissions (admin).
if (!isWindows) {
await copy(symLink, copyTarget, { preserveSymlinks: true });
assert.ok(fs.existsSync(copyTarget));
const { symbolicLink } = await SymlinkSupport.stat(copyTarget);
assert.ok(symbolicLink);
assert.ok(!symbolicLink.dangling);
const target = await fs.promises.readlink(copyTarget);
assert.strictEqual(target, symbolicLinkTarget);
// Copy does not preserve symlinks if configured as such
await rimraf(copyTarget);
await copy(symLink, copyTarget, { preserveSymlinks: false });
assert.ok(fs.existsSync(copyTarget));
const { symbolicLink: symbolicLink2 } = await SymlinkSupport.stat(copyTarget);
assert.ok(!symbolicLink2);
}
// Copy ignores dangling symlinks
await rimraf(copyTarget);
await rimraf(symbolicLinkTarget);
await copy(symbolicLink, copyTarget); // this should not throw
await copy(symLink, copyTarget, { preserveSymlinks: true }); // this should not throw
assert.ok(!fs.existsSync(copyTarget));
});
test('mkdirp', async () => {
const newDir = join(testDir, generateUuid());
test('copy handles symbolic links when the reference is inside source', async () => {
await mkdirp(newDir, 493);
// Source Folder
const sourceFolder = join(testDir, generateUuid(), 'copy-test'); // copy-test
const sourceLinkTestFolder = join(sourceFolder, 'link-test'); // copy-test/link-test
const sourceLinkMD5JSFolder = join(sourceLinkTestFolder, 'md5'); // copy-test/link-test/md5
const sourceLinkMD5JSFile = join(sourceLinkMD5JSFolder, 'md5.js'); // copy-test/link-test/md5/md5.js
await fs.promises.mkdir(sourceLinkMD5JSFolder, { recursive: true });
await writeFile(sourceLinkMD5JSFile, 'Hello from MD5');
assert.ok(fs.existsSync(newDir));
const sourceLinkMD5JSFolderLinked = join(sourceLinkTestFolder, 'md5-linked'); // copy-test/link-test/md5-linked
fs.symlinkSync(sourceLinkMD5JSFolder, sourceLinkMD5JSFolderLinked, 'junction');
// Target Folder
const targetLinkTestFolder = join(sourceFolder, 'link-test copy'); // copy-test/link-test copy
const targetLinkMD5JSFolder = join(targetLinkTestFolder, 'md5'); // copy-test/link-test copy/md5
const targetLinkMD5JSFile = join(targetLinkMD5JSFolder, 'md5.js'); // copy-test/link-test copy/md5/md5.js
const targetLinkMD5JSFolderLinked = join(targetLinkTestFolder, 'md5-linked'); // copy-test/link-test copy/md5-linked
// Copy with `preserveSymlinks: true` and verify result
//
// Windows: this test does not work because creating symlinks
// requires priviledged permissions (admin).
if (!isWindows) {
await copy(sourceLinkTestFolder, targetLinkTestFolder, { preserveSymlinks: true });
assert.ok(fs.existsSync(targetLinkTestFolder));
assert.ok(fs.existsSync(targetLinkMD5JSFolder));
assert.ok(fs.existsSync(targetLinkMD5JSFile));
assert.ok(fs.existsSync(targetLinkMD5JSFolderLinked));
assert.ok(fs.lstatSync(targetLinkMD5JSFolderLinked).isSymbolicLink());
const linkTarget = await fs.promises.readlink(targetLinkMD5JSFolderLinked);
assert.strictEqual(linkTarget, targetLinkMD5JSFolder);
await fs.promises.rmdir(targetLinkTestFolder, { recursive: true });
}
// Copy with `preserveSymlinks: false` and verify result
await copy(sourceLinkTestFolder, targetLinkTestFolder, { preserveSymlinks: false });
assert.ok(fs.existsSync(targetLinkTestFolder));
assert.ok(fs.existsSync(targetLinkMD5JSFolder));
assert.ok(fs.existsSync(targetLinkMD5JSFile));
assert.ok(fs.existsSync(targetLinkMD5JSFolderLinked));
assert.ok(fs.lstatSync(targetLinkMD5JSFolderLinked).isDirectory());
});
test('readDirsInDir', async () => {
@@ -244,14 +311,14 @@ flakySuite('PFS', function () {
const id2 = generateUuid();
const symbolicLink = join(testDir, id2);
await mkdirp(directory, 493);
await fs.promises.mkdir(directory, { recursive: true });
fs.symlinkSync(directory, symbolicLink, 'junction');
let statAndIsLink = await statLink(directory);
let statAndIsLink = await SymlinkSupport.stat(directory);
assert.ok(!statAndIsLink?.symbolicLink);
statAndIsLink = await statLink(symbolicLink);
statAndIsLink = await SymlinkSupport.stat(symbolicLink);
assert.ok(statAndIsLink?.symbolicLink);
assert.ok(!statAndIsLink?.symbolicLink?.dangling);
});
@@ -263,13 +330,13 @@ flakySuite('PFS', function () {
const id2 = generateUuid();
const symbolicLink = join(testDir, id2);
await mkdirp(directory, 493);
await fs.promises.mkdir(directory, { recursive: true });
fs.symlinkSync(directory, symbolicLink, 'junction');
await rimraf(directory);
const statAndIsLink = await statLink(symbolicLink);
const statAndIsLink = await SymlinkSupport.stat(symbolicLink);
assert.ok(statAndIsLink?.symbolicLink);
assert.ok(statAndIsLink?.symbolicLink?.dangling);
});
@@ -279,7 +346,7 @@ flakySuite('PFS', function () {
const id = generateUuid();
const newDir = join(testDir, 'pfs', id, 'öäü');
await mkdirp(newDir, 493);
await fs.promises.mkdir(newDir, { recursive: true });
assert.ok(fs.existsSync(newDir));
@@ -288,16 +355,16 @@ flakySuite('PFS', function () {
}
});
test('readdirWithFileTypes', async () => {
test('readdir (with file types)', async () => {
if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
const newDir = join(testDir, 'öäü');
await mkdirp(newDir, 493);
await fs.promises.mkdir(newDir, { recursive: true });
await writeFile(join(testDir, 'somefile.txt'), 'contents');
assert.ok(fs.existsSync(newDir));
const children = await readdirWithFileTypes(testDir);
const children = await readdir(testDir, { withFileTypes: true });
assert.strictEqual(children.some(n => n.name === 'öäü'), true); // Mac always converts to NFD, so
assert.strictEqual(children.some(n => n.isDirectory()), true);

View File

@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as fs from 'fs';
import * as os from 'os';
import * as platform from 'vs/base/common/platform';
import { enumeratePowerShellInstallations, getFirstAvailablePowerShellInstallation, IPowerShellExeDetails } from 'vs/base/node/powershell';
@@ -40,44 +39,20 @@ if (platform.isWindows) {
});
test('Can enumerate PowerShells', async () => {
const isOS64Bit = os.arch() === 'x64';
const pwshs = new Array<IPowerShellExeDetails>();
for await (const p of enumeratePowerShellInstallations()) {
pwshs.push(p);
}
const powershellLog = 'Found these PowerShells:\n' + pwshs.map(p => `${p.displayName}: ${p.exePath}`).join('\n');
assert.strictEqual(pwshs.length >= (isOS64Bit ? 2 : 1), true, powershellLog);
assert.strictEqual(pwshs.length >= 1, true, powershellLog);
for (const pwsh of pwshs) {
checkPath(pwsh.exePath);
}
const lastIndex = pwshs.length - 1;
const secondToLastIndex = pwshs.length - 2;
// 64bit process on 64bit OS
if (process.arch === 'x64') {
checkPath(pwshs[secondToLastIndex].exePath);
assert.strictEqual(pwshs[secondToLastIndex].displayName, 'Windows PowerShell', powershellLog);
checkPath(pwshs[lastIndex].exePath);
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell (x86)', powershellLog);
} else if (isOS64Bit) {
// 32bit process on 64bit OS
// Windows PowerShell x86 comes first if vscode is 32bit
checkPath(pwshs[secondToLastIndex].exePath);
assert.strictEqual(pwshs[secondToLastIndex].displayName, 'Windows PowerShell (x86)', powershellLog);
checkPath(pwshs[lastIndex].exePath);
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell', powershellLog);
} else {
// 32bit or ARM process
checkPath(pwshs[lastIndex].exePath);
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell (x86)', powershellLog);
}
// The last one should always be Windows PowerShell.
assert.strictEqual(pwshs[pwshs.length - 1].displayName, 'Windows PowerShell', powershellLog);
});
});
}

View File

@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { getDefaultUserDataPath } from 'vs/base/node/userDataPath';
suite('User data path', () => {
test('getDefaultUserDataPath', () => {
const path = getDefaultUserDataPath();
assert.ok(path.length > 0);
});
});

View File

@@ -6,8 +6,9 @@
import * as assert from 'assert';
import * as path from 'vs/base/common/path';
import { tmpdir } from 'os';
import { promises } from 'fs';
import { extract } from 'vs/base/node/zip';
import { rimraf, exists, mkdirp } from 'vs/base/node/pfs';
import { rimraf, exists } from 'vs/base/node/pfs';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { createCancelablePromise } from 'vs/base/common/async';
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
@@ -19,7 +20,7 @@ suite('Zip', () => {
setup(() => {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'zip');
return mkdirp(testDir);
return promises.mkdir(testDir, { recursive: true });
});
teardown(() => {