chore(vscode): update to 1.53.2

These conflicts will be resolved in the following commits. We do it this way so
that PR review is possible.
This commit is contained in:
Joe Previte
2021-02-25 11:27:27 -07:00
1900 changed files with 83066 additions and 64589 deletions

View File

@@ -33,28 +33,28 @@ suite('Actionbar', () => {
let a2 = new Action('a2');
actionbar.push(a1);
assert.equal(actionbar.hasAction(a1), true);
assert.equal(actionbar.hasAction(a2), false);
assert.strictEqual(actionbar.hasAction(a1), true);
assert.strictEqual(actionbar.hasAction(a2), false);
actionbar.pull(0);
assert.equal(actionbar.hasAction(a1), false);
assert.strictEqual(actionbar.hasAction(a1), false);
actionbar.push(a1, { index: 1 });
actionbar.push(a2, { index: 0 });
assert.equal(actionbar.hasAction(a1), true);
assert.equal(actionbar.hasAction(a2), true);
assert.strictEqual(actionbar.hasAction(a1), true);
assert.strictEqual(actionbar.hasAction(a2), true);
actionbar.pull(0);
assert.equal(actionbar.hasAction(a1), true);
assert.equal(actionbar.hasAction(a2), false);
assert.strictEqual(actionbar.hasAction(a1), true);
assert.strictEqual(actionbar.hasAction(a2), false);
actionbar.pull(0);
assert.equal(actionbar.hasAction(a1), false);
assert.equal(actionbar.hasAction(a2), false);
assert.strictEqual(actionbar.hasAction(a1), false);
assert.strictEqual(actionbar.hasAction(a2), false);
actionbar.push(a1);
assert.equal(actionbar.hasAction(a1), true);
assert.strictEqual(actionbar.hasAction(a1), true);
actionbar.clear();
assert.equal(actionbar.hasAction(a1), false);
assert.strictEqual(actionbar.hasAction(a1), false);
});
});

View File

@@ -123,8 +123,8 @@ suite('Comparers', () => {
// name-only comparisions
assert(compareFileExtensions('a', 'A') !== compareLocale('a', 'A'), 'the same letter of different case does not sort by locale');
assert(compareFileExtensions('â', 'Â') !== compareLocale('â', 'Â'), 'the same accented letter of different case does not sort by locale');
assert.notDeepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileExtensions), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases do not sort in locale order');
assert.notDeepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileExtensions), ['email', 'Email', 'émail', 'Émail'].sort((a, b) => a.localeCompare(b)), 'the same base characters with different case or accents do not sort in locale order');
assert.notDeepStrictEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileExtensions), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases do not sort in locale order');
assert.notDeepStrictEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileExtensions), ['email', 'Email', 'émail', 'Émail'].sort((a, b) => a.localeCompare(b)), 'the same base characters with different case or accents do not sort in locale order');
// name plus extension comparisons
assert(compareFileExtensions('a.MD', 'a.md') !== compareLocale('MD', 'md'), 'case differences in extensions do not sort by locale');
@@ -197,8 +197,7 @@ suite('Comparers', () => {
// name-only comparisons
assert(compareFileNamesDefault('a', 'A') === compareLocale('a', 'A'), 'the same letter sorts by locale');
assert(compareFileNamesDefault('â', 'Â') === compareLocale('â', 'Â'), 'the same accented letter sorts by locale');
// assert.deepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileNamesDefault), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases sort in locale order');
assert.deepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileNamesDefault), ['email', 'Email', 'émail', 'Émail'].sort(compareLocale), 'the same base characters with different case or accents sort in locale order');
assert.deepStrictEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileNamesDefault), ['email', 'Email', 'émail', 'Émail'].sort(compareLocale), 'the same base characters with different case or accents sort in locale order');
// numeric comparisons
assert(compareFileNamesDefault('abc02.txt', 'abc002.txt') < 0, 'filenames with equivalent numbers and leading zeros sort shortest number first');
@@ -259,8 +258,7 @@ suite('Comparers', () => {
// name-only comparisons
assert(compareFileExtensionsDefault('a', 'A') === compareLocale('a', 'A'), 'the same letter of different case sorts by locale');
assert(compareFileExtensionsDefault('â', 'Â') === compareLocale('â', 'Â'), 'the same accented letter of different case sorts by locale');
// assert.deepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileExtensionsDefault), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases sort in locale order');
assert.deepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileExtensionsDefault), ['email', 'Email', 'émail', 'Émail'].sort((a, b) => a.localeCompare(b)), 'the same base characters with different case or accents sort in locale order');
assert.deepStrictEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileExtensionsDefault), ['email', 'Email', 'émail', 'Émail'].sort((a, b) => a.localeCompare(b)), 'the same base characters with different case or accents sort in locale order');
// name plus extension comparisons
assert(compareFileExtensionsDefault('a.MD', 'a.md') === compareLocale('MD', 'md'), 'case differences in extensions sort by locale');

View File

@@ -73,8 +73,9 @@ suite('dom', () => {
});
test('multibyteAwareBtoa', () => {
assert.equal(dom.multibyteAwareBtoa('hello world'), dom.multibyteAwareBtoa('hello world'));
assert.ok(dom.multibyteAwareBtoa('平仮名'));
assert.ok(dom.multibyteAwareBtoa('hello world').length > 0);
assert.ok(dom.multibyteAwareBtoa('平仮名').length > 0);
assert.ok(dom.multibyteAwareBtoa(new Array(100000).fill('vs').join('')).length > 0); // https://github.com/microsoft/vscode/issues/112013
});
suite('$', () => {

View File

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

View File

@@ -53,7 +53,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, false);
assert.strictEqual(actual, false);
}
});
@@ -142,7 +142,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, false);
assert.strictEqual(actual, false);
}
});
@@ -202,7 +202,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, true);
assert.strictEqual(actual, true);
}
});
@@ -241,7 +241,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, true);
assert.strictEqual(actual, true);
}
});
@@ -285,7 +285,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, false);
assert.strictEqual(actual, false);
}
});
@@ -374,7 +374,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, true);
assert.strictEqual(actual, true);
}
});
@@ -464,7 +464,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, true);
assert.strictEqual(actual, true);
}
});
@@ -518,7 +518,7 @@ suite('MouseWheelClassifier', () => {
classifier.accept(timestamp, deltaX, deltaY);
const actual = classifier.isPhysicalMouseWheel();
assert.equal(actual, true);
assert.strictEqual(actual, true);
}
});
});

View File

@@ -10,52 +10,52 @@ suite('ScrollbarState', () => {
test('inflates slider size', () => {
let actual = new ScrollbarState(0, 14, 0, 339, 42423, 32787);
assert.equal(actual.getArrowSize(), 0);
assert.equal(actual.getScrollPosition(), 32787);
assert.equal(actual.getRectangleLargeSize(), 339);
assert.equal(actual.getRectangleSmallSize(), 14);
assert.equal(actual.isNeeded(), true);
assert.equal(actual.getSliderSize(), 20);
assert.equal(actual.getSliderPosition(), 249);
assert.strictEqual(actual.getArrowSize(), 0);
assert.strictEqual(actual.getScrollPosition(), 32787);
assert.strictEqual(actual.getRectangleLargeSize(), 339);
assert.strictEqual(actual.getRectangleSmallSize(), 14);
assert.strictEqual(actual.isNeeded(), true);
assert.strictEqual(actual.getSliderSize(), 20);
assert.strictEqual(actual.getSliderPosition(), 249);
assert.equal(actual.getDesiredScrollPositionFromOffset(259), 32849);
assert.strictEqual(actual.getDesiredScrollPositionFromOffset(259), 32849);
// 259 is greater than 230 so page down, 32787 + 339 = 33126
assert.equal(actual.getDesiredScrollPositionFromOffsetPaged(259), 33126);
assert.strictEqual(actual.getDesiredScrollPositionFromOffsetPaged(259), 33126);
actual.setScrollPosition(32849);
assert.equal(actual.getArrowSize(), 0);
assert.equal(actual.getScrollPosition(), 32849);
assert.equal(actual.getRectangleLargeSize(), 339);
assert.equal(actual.getRectangleSmallSize(), 14);
assert.equal(actual.isNeeded(), true);
assert.equal(actual.getSliderSize(), 20);
assert.equal(actual.getSliderPosition(), 249);
assert.strictEqual(actual.getArrowSize(), 0);
assert.strictEqual(actual.getScrollPosition(), 32849);
assert.strictEqual(actual.getRectangleLargeSize(), 339);
assert.strictEqual(actual.getRectangleSmallSize(), 14);
assert.strictEqual(actual.isNeeded(), true);
assert.strictEqual(actual.getSliderSize(), 20);
assert.strictEqual(actual.getSliderPosition(), 249);
});
test('inflates slider size with arrows', () => {
let actual = new ScrollbarState(12, 14, 0, 339, 42423, 32787);
assert.equal(actual.getArrowSize(), 12);
assert.equal(actual.getScrollPosition(), 32787);
assert.equal(actual.getRectangleLargeSize(), 339);
assert.equal(actual.getRectangleSmallSize(), 14);
assert.equal(actual.isNeeded(), true);
assert.equal(actual.getSliderSize(), 20);
assert.equal(actual.getSliderPosition(), 230);
assert.strictEqual(actual.getArrowSize(), 12);
assert.strictEqual(actual.getScrollPosition(), 32787);
assert.strictEqual(actual.getRectangleLargeSize(), 339);
assert.strictEqual(actual.getRectangleSmallSize(), 14);
assert.strictEqual(actual.isNeeded(), true);
assert.strictEqual(actual.getSliderSize(), 20);
assert.strictEqual(actual.getSliderPosition(), 230);
assert.equal(actual.getDesiredScrollPositionFromOffset(240 + 12), 32811);
assert.strictEqual(actual.getDesiredScrollPositionFromOffset(240 + 12), 32811);
// 240 + 12 = 252; greater than 230 so page down, 32787 + 339 = 33126
assert.equal(actual.getDesiredScrollPositionFromOffsetPaged(240 + 12), 33126);
assert.strictEqual(actual.getDesiredScrollPositionFromOffsetPaged(240 + 12), 33126);
actual.setScrollPosition(32811);
assert.equal(actual.getArrowSize(), 12);
assert.equal(actual.getScrollPosition(), 32811);
assert.equal(actual.getRectangleLargeSize(), 339);
assert.equal(actual.getRectangleSmallSize(), 14);
assert.equal(actual.isNeeded(), true);
assert.equal(actual.getSliderSize(), 20);
assert.equal(actual.getSliderPosition(), 230);
assert.strictEqual(actual.getArrowSize(), 12);
assert.strictEqual(actual.getScrollPosition(), 32811);
assert.strictEqual(actual.getRectangleLargeSize(), 339);
assert.strictEqual(actual.getRectangleSmallSize(), 14);
assert.strictEqual(actual.isNeeded(), true);
assert.strictEqual(actual.getSliderSize(), 20);
assert.strictEqual(actual.getSliderPosition(), 230);
});
});

View File

@@ -8,6 +8,7 @@ import { compress, ICompressedTreeElement, ICompressedTreeNode, decompress, Comp
import { Iterable } from 'vs/base/common/iterator';
import { ITreeNode } from 'vs/base/browser/ui/tree/tree';
import { IList } from 'vs/base/browser/ui/tree/indexTreeModel';
import { IObjectTreeModelSetChildrenOptions } from 'vs/base/browser/ui/tree/objectTreeModel';
interface IResolvedCompressedTreeElement<T> extends ICompressedTreeElement<T> {
readonly element: T;
@@ -304,6 +305,16 @@ suite('CompressedObjectTree', function () {
suite('CompressedObjectTreeModel', function () {
/**
* Calls that test function twice, once with an empty options and
* once with `diffIdentityProvider`.
*/
function withSmartSplice(fn: (options: IObjectTreeModelSetChildrenOptions<number, any>) => void) {
fn({});
fn({ diffIdentityProvider: { getId: n => String(n) } });
}
test('ctor', () => {
const list: ITreeNode<ICompressedTreeNode<number>>[] = [];
const model = new CompressedObjectTreeModel<number>('test', toList(list));
@@ -312,7 +323,7 @@ suite('CompressedObjectTree', function () {
assert.equal(model.size, 0);
});
test('flat', () => {
test('flat', () => withSmartSplice(options => {
const list: ITreeNode<ICompressedTreeNode<number>>[] = [];
const model = new CompressedObjectTreeModel<number>('test', toList(list));
@@ -320,7 +331,7 @@ suite('CompressedObjectTree', function () {
{ element: 0 },
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(toArray(list), [[0], [1], [2]]);
assert.equal(model.size, 3);
@@ -329,17 +340,17 @@ suite('CompressedObjectTree', function () {
{ element: 3 },
{ element: 4 },
{ element: 5 },
]);
], options);
assert.deepEqual(toArray(list), [[3], [4], [5]]);
assert.equal(model.size, 3);
model.setChildren(null);
model.setChildren(null, [], options);
assert.deepEqual(toArray(list), []);
assert.equal(model.size, 0);
});
}));
test('nested', () => {
test('nested', () => withSmartSplice(options => {
const list: ITreeNode<ICompressedTreeNode<number>>[] = [];
const model = new CompressedObjectTreeModel<number>('test', toList(list));
@@ -353,7 +364,7 @@ suite('CompressedObjectTree', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(toArray(list), [[0], [10], [11], [12], [1], [2]]);
assert.equal(model.size, 6);
@@ -361,21 +372,21 @@ suite('CompressedObjectTree', function () {
model.setChildren(12, [
{ element: 120 },
{ element: 121 }
]);
], options);
assert.deepEqual(toArray(list), [[0], [10], [11], [12], [120], [121], [1], [2]]);
assert.equal(model.size, 8);
model.setChildren(0);
model.setChildren(0, [], options);
assert.deepEqual(toArray(list), [[0], [1], [2]]);
assert.equal(model.size, 3);
model.setChildren(null);
model.setChildren(null, [], options);
assert.deepEqual(toArray(list), []);
assert.equal(model.size, 0);
});
}));
test('compressed', () => {
test('compressed', () => withSmartSplice(options => {
const list: ITreeNode<ICompressedTreeNode<number>>[] = [];
const model = new CompressedObjectTreeModel<number>('test', toList(list));
@@ -391,7 +402,7 @@ suite('CompressedObjectTree', function () {
}]
}]
}
]);
], options);
assert.deepEqual(toArray(list), [[1, 11, 111], [1111], [1112], [1113]]);
assert.equal(model.size, 6);
@@ -400,21 +411,21 @@ suite('CompressedObjectTree', function () {
{ element: 111 },
{ element: 112 },
{ element: 113 },
]);
], options);
assert.deepEqual(toArray(list), [[1, 11], [111], [112], [113]]);
assert.equal(model.size, 5);
model.setChildren(113, [
{ element: 1131 }
]);
], options);
assert.deepEqual(toArray(list), [[1, 11], [111], [112], [113, 1131]]);
assert.equal(model.size, 6);
model.setChildren(1131, [
{ element: 1132 }
]);
], options);
assert.deepEqual(toArray(list), [[1, 11], [111], [112], [113, 1131, 1132]]);
assert.equal(model.size, 7);
@@ -422,10 +433,10 @@ suite('CompressedObjectTree', function () {
model.setChildren(1131, [
{ element: 1132 },
{ element: 1133 },
]);
], options);
assert.deepEqual(toArray(list), [[1, 11], [111], [112], [113, 1131], [1132], [1133]]);
assert.equal(model.size, 8);
});
}));
});
});

View File

@@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { ITreeNode, ITreeFilter, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
import { IndexTreeModel, IIndexTreeNode, IList } from 'vs/base/browser/ui/tree/indexTreeModel';
import { ITreeNode, ITreeFilter, TreeVisibility, ITreeElement } from 'vs/base/browser/ui/tree/tree';
import { IndexTreeModel, IIndexTreeNode, IList, IIndexTreeModelSpliceOptions } from 'vs/base/browser/ui/tree/indexTreeModel';
function toList<T>(arr: T[]): IList<T> {
return {
@@ -20,7 +20,23 @@ function toArray<T>(list: ITreeNode<T>[]): T[] {
return list.map(i => i.element);
}
suite('IndexTreeModel', function () {
function toElements<T>(node: ITreeNode<T>): any {
return node.children?.length ? { e: node.element, children: node.children.map(toElements) } : node.element;
}
const diffIdentityProvider = { getId: (n: number) => String(n) };
/**
* Calls that test function twice, once with an empty options and
* once with `diffIdentityProvider`.
*/
function withSmartSplice(fn: (options: IIndexTreeModelSpliceOptions<number, any>) => void) {
fn({});
fn({ diffIdentityProvider });
}
suite('IndexTreeModel', () => {
test('ctor', () => {
const list: ITreeNode<number>[] = [];
@@ -29,7 +45,7 @@ suite('IndexTreeModel', function () {
assert.equal(list.length, 0);
});
test('insert', () => {
test('insert', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -37,7 +53,7 @@ suite('IndexTreeModel', function () {
{ element: 0 },
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 3);
assert.deepEqual(list[0].element, 0);
@@ -49,9 +65,9 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[2].element, 2);
assert.deepEqual(list[2].collapsed, false);
assert.deepEqual(list[2].depth, 1);
});
}));
test('deep insert', function () {
test('deep insert', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -86,9 +102,9 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[5].element, 2);
assert.deepEqual(list[5].collapsed, false);
assert.deepEqual(list[5].depth, 1);
});
}));
test('deep insert collapsed', function () {
test('deep insert collapsed', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -102,7 +118,7 @@ suite('IndexTreeModel', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 3);
assert.deepEqual(list[0].element, 0);
@@ -114,9 +130,9 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[2].element, 2);
assert.deepEqual(list[2].collapsed, false);
assert.deepEqual(list[2].depth, 1);
});
}));
test('delete', () => {
test('delete', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -124,11 +140,11 @@ suite('IndexTreeModel', function () {
{ element: 0 },
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 3);
model.splice([1], 1);
model.splice([1], 1, undefined, options);
assert.deepEqual(list.length, 2);
assert.deepEqual(list[0].element, 0);
assert.deepEqual(list[0].collapsed, false);
@@ -137,11 +153,11 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[1].collapsed, false);
assert.deepEqual(list[1].depth, 1);
model.splice([0], 2);
model.splice([0], 2, undefined, options);
assert.deepEqual(list.length, 0);
});
}));
test('nested delete', function () {
test('nested delete', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -155,11 +171,11 @@ suite('IndexTreeModel', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 6);
model.splice([1], 2);
model.splice([1], 2, undefined, options);
assert.deepEqual(list.length, 4);
assert.deepEqual(list[0].element, 0);
assert.deepEqual(list[0].collapsed, false);
@@ -173,9 +189,9 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[3].element, 12);
assert.deepEqual(list[3].collapsed, false);
assert.deepEqual(list[3].depth, 2);
});
}));
test('deep delete', function () {
test('deep delete', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -189,11 +205,11 @@ suite('IndexTreeModel', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 6);
model.splice([0], 1);
model.splice([0], 1, undefined, options);
assert.deepEqual(list.length, 2);
assert.deepEqual(list[0].element, 1);
assert.deepEqual(list[0].collapsed, false);
@@ -201,9 +217,43 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[1].element, 2);
assert.deepEqual(list[1].collapsed, false);
assert.deepEqual(list[1].depth, 1);
}));
test('smart splice deep', () => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
model.splice([0], 0, [
{ element: 0 },
{ element: 1 },
{ element: 2 },
{ element: 3 },
], { diffIdentityProvider });
assert.deepStrictEqual(list.filter(l => l.depth === 1).map(toElements), [
0,
1,
2,
3,
]);
model.splice([0], 3, [
{ element: -0.5 },
{ element: 0, children: [{ element: 0.1 }] },
{ element: 1 },
{ element: 2, children: [{ element: 2.1 }, { element: 2.2, children: [{ element: 2.21 }] }] },
], { diffIdentityProvider, diffDepth: Infinity });
assert.deepStrictEqual(list.filter(l => l.depth === 1).map(toElements), [
-0.5,
{ e: 0, children: [0.1] },
1,
{ e: 2, children: [2.1, { e: 2.2, children: [2.21] }] },
3,
]);
});
test('hidden delete', function () {
test('hidden delete', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -217,18 +267,18 @@ suite('IndexTreeModel', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 3);
model.splice([0, 1], 1);
model.splice([0, 1], 1, undefined, options);
assert.deepEqual(list.length, 3);
model.splice([0, 0], 2);
model.splice([0, 0], 2, undefined, options);
assert.deepEqual(list.length, 3);
});
}));
test('collapse', () => {
test('collapse', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -242,7 +292,7 @@ suite('IndexTreeModel', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 6);
@@ -257,9 +307,33 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[2].element, 2);
assert.deepEqual(list[2].collapsed, false);
assert.deepEqual(list[2].depth, 1);
});
}));
test('expand', () => {
test('updates collapsible', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
model.splice([0], 0, [
{
element: 0, children: [
{ element: 1 },
]
},
], options);
assert.strictEqual(list[0].collapsible, true);
assert.strictEqual(list[1].collapsible, false);
model.splice([0, 0], 1, [], options);
assert.strictEqual(list[0].collapsible, false);
assert.strictEqual(list[1], undefined);
model.splice([0, 0], 0, [{ element: 1 }], options);
assert.strictEqual(list[0].collapsible, true);
assert.strictEqual(list[1].collapsible, false);
}));
test('expand', () => withSmartSplice(options => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -273,7 +347,7 @@ suite('IndexTreeModel', function () {
},
{ element: 1 },
{ element: 2 }
]);
], options);
assert.deepEqual(list.length, 3);
@@ -297,9 +371,52 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[5].element, 2);
assert.deepEqual(list[5].collapsed, false);
assert.deepEqual(list[5].depth, 1);
}));
test('smart diff consistency', () => {
const times = 500;
const minEdits = 1;
const maxEdits = 10;
const maxInserts = 5;
for (let i = 0; i < times; i++) {
const list: ITreeNode<number>[] = [];
const options = { diffIdentityProvider: { getId: (n: number) => String(n) } };
const model = new IndexTreeModel<number>('test', toList(list), -1);
const changes = [];
const expected: number[] = [];
let elementCounter = 0;
for (let edits = Math.random() * (maxEdits - minEdits) + minEdits; edits > 0; edits--) {
const spliceIndex = Math.floor(Math.random() * list.length);
const deleteCount = Math.ceil(Math.random() * (list.length - spliceIndex));
const insertCount = Math.floor(Math.random() * maxInserts + 1);
let inserts: ITreeElement<number>[] = [];
for (let i = 0; i < insertCount; i++) {
const element = elementCounter++;
inserts.push({ element, children: [] });
}
// move existing items
if (Math.random() < 0.5) {
const elements = list.slice(spliceIndex, spliceIndex + Math.floor(deleteCount / 2));
inserts.push(...elements.map(({ element }) => ({ element, children: [] })));
}
model.splice([spliceIndex], deleteCount, inserts, options);
expected.splice(spliceIndex, deleteCount, ...inserts.map(i => i.element));
const listElements = list.map(l => l.element);
changes.push(`splice(${spliceIndex}, ${deleteCount}, [${inserts.map(e => e.element).join(', ')}]) -> ${listElements.join(', ')}`);
assert.deepStrictEqual(expected, listElements, `Expected ${listElements.join(', ')} to equal ${expected.join(', ')}. Steps:\n\n${changes.join('\n')}`);
}
}
});
test('collapse should recursively adjust visible count', function () {
test('collapse should recursively adjust visible count', () => {
const list: ITreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -395,7 +512,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list[1].collapsed, false);
});
test('simple filter', function () {
test('simple filter', () => {
const list: ITreeNode<number>[] = [];
const filter = new class implements ITreeFilter<number> {
filter(element: number): TreeVisibility {
@@ -429,7 +546,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(toArray(list), [0, 2, 4, 6]);
});
test('recursive filter on initial model', function () {
test('recursive filter on initial model', () => {
const list: ITreeNode<number>[] = [];
const filter = new class implements ITreeFilter<number> {
filter(element: number): TreeVisibility {
@@ -451,7 +568,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(toArray(list), []);
});
test('refilter', function () {
test('refilter', () => {
const list: ITreeNode<number>[] = [];
let shouldFilter = false;
const filter = new class implements ITreeFilter<number> {
@@ -490,7 +607,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(toArray(list), [0, 1, 2, 3, 4, 5, 6, 7]);
});
test('recursive filter', function () {
test('recursive filter', () => {
const list: ITreeNode<string>[] = [];
let query = new RegExp('');
const filter = new class implements ITreeFilter<string> {
@@ -536,7 +653,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(toArray(list), ['vscode', '.build', 'github', 'build.js', 'build']);
});
test('recursive filter with collapse', function () {
test('recursive filter with collapse', () => {
const list: ITreeNode<string>[] = [];
let query = new RegExp('');
const filter = new class implements ITreeFilter<string> {
@@ -582,7 +699,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(toArray(list), ['vscode']);
});
test('recursive filter while collapsed', function () {
test('recursive filter while collapsed', () => {
const list: ITreeNode<string>[] = [];
let query = new RegExp('');
const filter = new class implements ITreeFilter<string> {
@@ -635,9 +752,9 @@ suite('IndexTreeModel', function () {
assert.deepEqual(list.length, 10);
});
suite('getNodeLocation', function () {
suite('getNodeLocation', () => {
test('simple', function () {
test('simple', () => {
const list: IIndexTreeNode<number>[] = [];
const model = new IndexTreeModel<number>('test', toList(list), -1);
@@ -661,7 +778,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(model.getNodeLocation(list[5]), [2]);
});
test('with filter', function () {
test('with filter', () => {
const list: IIndexTreeNode<number>[] = [];
const filter = new class implements ITreeFilter<number> {
filter(element: number): TreeVisibility {
@@ -692,7 +809,7 @@ suite('IndexTreeModel', function () {
});
});
test('refilter with filtered out nodes', function () {
test('refilter with filtered out nodes', () => {
const list: ITreeNode<string>[] = [];
let query = new RegExp('');
const filter = new class implements ITreeFilter<string> {
@@ -726,7 +843,7 @@ suite('IndexTreeModel', function () {
assert.deepEqual(toArray(list), ['platinum']);
});
test('explicit hidden nodes should have renderNodeCount == 0, issue #83211', function () {
test('explicit hidden nodes should have renderNodeCount == 0, issue #83211', () => {
const list: ITreeNode<string>[] = [];
let query = new RegExp('');
const filter = new class implements ITreeFilter<string> {

View File

@@ -59,30 +59,30 @@ suite('ObjectTree', function () {
const navigator = tree.navigate();
assert.equal(navigator.current(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.current(), 0);
assert.equal(navigator.next(), 10);
assert.equal(navigator.current(), 10);
assert.equal(navigator.next(), 11);
assert.equal(navigator.current(), 11);
assert.equal(navigator.next(), 12);
assert.equal(navigator.current(), 12);
assert.equal(navigator.next(), 1);
assert.equal(navigator.current(), 1);
assert.equal(navigator.next(), 2);
assert.equal(navigator.current(), 2);
assert.equal(navigator.previous(), 1);
assert.equal(navigator.current(), 1);
assert.equal(navigator.previous(), 12);
assert.equal(navigator.previous(), 11);
assert.equal(navigator.previous(), 10);
assert.equal(navigator.previous(), 0);
assert.equal(navigator.previous(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.next(), 10);
assert.equal(navigator.first(), 0);
assert.equal(navigator.last(), 2);
assert.strictEqual(navigator.current(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.current(), 0);
assert.strictEqual(navigator.next(), 10);
assert.strictEqual(navigator.current(), 10);
assert.strictEqual(navigator.next(), 11);
assert.strictEqual(navigator.current(), 11);
assert.strictEqual(navigator.next(), 12);
assert.strictEqual(navigator.current(), 12);
assert.strictEqual(navigator.next(), 1);
assert.strictEqual(navigator.current(), 1);
assert.strictEqual(navigator.next(), 2);
assert.strictEqual(navigator.current(), 2);
assert.strictEqual(navigator.previous(), 1);
assert.strictEqual(navigator.current(), 1);
assert.strictEqual(navigator.previous(), 12);
assert.strictEqual(navigator.previous(), 11);
assert.strictEqual(navigator.previous(), 10);
assert.strictEqual(navigator.previous(), 0);
assert.strictEqual(navigator.previous(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.next(), 10);
assert.strictEqual(navigator.first(), 0);
assert.strictEqual(navigator.last(), 2);
});
test('should skip collapsed nodes', () => {
@@ -100,18 +100,18 @@ suite('ObjectTree', function () {
const navigator = tree.navigate();
assert.equal(navigator.current(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.next(), 1);
assert.equal(navigator.next(), 2);
assert.equal(navigator.next(), null);
assert.equal(navigator.previous(), 2);
assert.equal(navigator.previous(), 1);
assert.equal(navigator.previous(), 0);
assert.equal(navigator.previous(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.first(), 0);
assert.equal(navigator.last(), 2);
assert.strictEqual(navigator.current(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.next(), 1);
assert.strictEqual(navigator.next(), 2);
assert.strictEqual(navigator.next(), null);
assert.strictEqual(navigator.previous(), 2);
assert.strictEqual(navigator.previous(), 1);
assert.strictEqual(navigator.previous(), 0);
assert.strictEqual(navigator.previous(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.first(), 0);
assert.strictEqual(navigator.last(), 2);
});
test('should skip filtered elements', () => {
@@ -131,21 +131,21 @@ suite('ObjectTree', function () {
const navigator = tree.navigate();
assert.equal(navigator.current(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.next(), 10);
assert.equal(navigator.next(), 12);
assert.equal(navigator.next(), 2);
assert.equal(navigator.next(), null);
assert.equal(navigator.previous(), 2);
assert.equal(navigator.previous(), 12);
assert.equal(navigator.previous(), 10);
assert.equal(navigator.previous(), 0);
assert.equal(navigator.previous(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.next(), 10);
assert.equal(navigator.first(), 0);
assert.equal(navigator.last(), 2);
assert.strictEqual(navigator.current(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.next(), 10);
assert.strictEqual(navigator.next(), 12);
assert.strictEqual(navigator.next(), 2);
assert.strictEqual(navigator.next(), null);
assert.strictEqual(navigator.previous(), 2);
assert.strictEqual(navigator.previous(), 12);
assert.strictEqual(navigator.previous(), 10);
assert.strictEqual(navigator.previous(), 0);
assert.strictEqual(navigator.previous(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.next(), 10);
assert.strictEqual(navigator.first(), 0);
assert.strictEqual(navigator.last(), 2);
});
test('should be able to start from node', () => {
@@ -163,20 +163,20 @@ suite('ObjectTree', function () {
const navigator = tree.navigate(1);
assert.equal(navigator.current(), 1);
assert.equal(navigator.next(), 2);
assert.equal(navigator.current(), 2);
assert.equal(navigator.previous(), 1);
assert.equal(navigator.current(), 1);
assert.equal(navigator.previous(), 12);
assert.equal(navigator.previous(), 11);
assert.equal(navigator.previous(), 10);
assert.equal(navigator.previous(), 0);
assert.equal(navigator.previous(), null);
assert.equal(navigator.next(), 0);
assert.equal(navigator.next(), 10);
assert.equal(navigator.first(), 0);
assert.equal(navigator.last(), 2);
assert.strictEqual(navigator.current(), 1);
assert.strictEqual(navigator.next(), 2);
assert.strictEqual(navigator.current(), 2);
assert.strictEqual(navigator.previous(), 1);
assert.strictEqual(navigator.current(), 1);
assert.strictEqual(navigator.previous(), 12);
assert.strictEqual(navigator.previous(), 11);
assert.strictEqual(navigator.previous(), 10);
assert.strictEqual(navigator.previous(), 0);
assert.strictEqual(navigator.previous(), null);
assert.strictEqual(navigator.next(), 0);
assert.strictEqual(navigator.next(), 10);
assert.strictEqual(navigator.first(), 0);
assert.strictEqual(navigator.last(), 2);
});
});
@@ -219,10 +219,10 @@ suite('ObjectTree', function () {
});
});
function toArray(list: NodeList): Node[] {
const result: Node[] = [];
list.forEach(node => result.push(node));
return result;
function getRowsTextContent(container: HTMLElement): string[] {
const rows = [...container.querySelectorAll('.monaco-list-row')];
rows.sort((a, b) => parseInt(a.getAttribute('data-index')!) - parseInt(b.getAttribute('data-index')!));
return rows.map(row => row.querySelector('.monaco-tl-contents')!.textContent!);
}
suite('CompressibleObjectTree', function () {
@@ -254,8 +254,7 @@ suite('CompressibleObjectTree', function () {
const tree = new CompressibleObjectTree<number>('test', container, new Delegate(), [new Renderer()]);
tree.layout(200);
const rows = toArray(container.querySelectorAll('.monaco-tl-contents'));
assert.equal(rows.length, 0);
assert.strictEqual(getRowsTextContent(container).length, 0);
});
test('simple', function () {
@@ -278,8 +277,7 @@ suite('CompressibleObjectTree', function () {
{ element: 2 }
]);
const rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['0', '10', '11', '12', '1', '2']);
assert.deepStrictEqual(getRowsTextContent(container), ['0', '10', '11', '12', '1', '2']);
});
test('compressed', () => {
@@ -304,8 +302,7 @@ suite('CompressibleObjectTree', function () {
}
]);
let rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11/111', '1111', '1112', '1113']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11/111', '1111', '1112', '1113']);
tree.setChildren(11, [
{ element: 111 },
@@ -313,30 +310,26 @@ suite('CompressibleObjectTree', function () {
{ element: 113 },
]);
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11', '111', '112', '113']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11', '111', '112', '113']);
tree.setChildren(113, [
{ element: 1131 }
]);
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11', '111', '112', '113/1131']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11', '111', '112', '113/1131']);
tree.setChildren(1131, [
{ element: 1132 }
]);
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11', '111', '112', '113/1131/1132']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11', '111', '112', '113/1131/1132']);
tree.setChildren(1131, [
{ element: 1132 },
{ element: 1133 },
]);
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11', '111', '112', '113/1131', '1132', '1133']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11', '111', '112', '113/1131', '1132', '1133']);
});
test('enableCompression', () => {
@@ -361,15 +354,12 @@ suite('CompressibleObjectTree', function () {
}
]);
let rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11/111', '1111', '1112', '1113']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11/111', '1111', '1112', '1113']);
tree.updateOptions({ compressionEnabled: false });
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1', '11', '111', '1111', '1112', '1113']);
assert.deepStrictEqual(getRowsTextContent(container), ['1', '11', '111', '1111', '1112', '1113']);
tree.updateOptions({ compressionEnabled: true });
rows = toArray(container.querySelectorAll('.monaco-tl-contents')).map(row => row.textContent);
assert.deepEqual(rows, ['1/11/111', '1111', '1112', '1113']);
assert.deepStrictEqual(getRowsTextContent(container), ['1/11/111', '1111', '1112', '1113']);
});
});

View File

@@ -10,25 +10,25 @@ suite('Arrays', () => {
const array = [1, 4, 5, 7, 55, 59, 60, 61, 64, 69];
let idx = arrays.findFirstInSorted(array, e => e >= 0);
assert.equal(array[idx], 1);
assert.strictEqual(array[idx], 1);
idx = arrays.findFirstInSorted(array, e => e > 1);
assert.equal(array[idx], 4);
assert.strictEqual(array[idx], 4);
idx = arrays.findFirstInSorted(array, e => e >= 8);
assert.equal(array[idx], 55);
assert.strictEqual(array[idx], 55);
idx = arrays.findFirstInSorted(array, e => e >= 61);
assert.equal(array[idx], 61);
assert.strictEqual(array[idx], 61);
idx = arrays.findFirstInSorted(array, e => e >= 69);
assert.equal(array[idx], 69);
assert.strictEqual(array[idx], 69);
idx = arrays.findFirstInSorted(array, e => e >= 70);
assert.equal(idx, array.length);
assert.strictEqual(idx, array.length);
idx = arrays.findFirstInSorted([], e => e >= 0);
assert.equal(array[idx], 1);
assert.strictEqual(array[idx], 1);
});
test('quickSelect', () => {
@@ -36,10 +36,10 @@ suite('Arrays', () => {
function assertMedian(expexted: number, data: number[], nth: number = Math.floor(data.length / 2)) {
const compare = (a: number, b: number) => a - b;
let actual1 = arrays.quickSelect(nth, data, compare);
assert.equal(actual1, expexted);
assert.strictEqual(actual1, expexted);
let actual2 = data.slice().sort(compare)[nth];
assert.equal(actual2, expexted);
assert.strictEqual(actual2, expexted);
}
assertMedian(5, [9, 1, 0, 2, 3, 4, 6, 8, 7, 10, 5]);
@@ -72,18 +72,18 @@ suite('Arrays', () => {
test('mergeSort', () => {
let data = arrays.mergeSort([6, 5, 3, 1, 8, 7, 2, 4], (a, b) => a - b);
assert.deepEqual(data, [1, 2, 3, 4, 5, 6, 7, 8]);
assert.deepStrictEqual(data, [1, 2, 3, 4, 5, 6, 7, 8]);
});
test('mergeSort, sorted array', function () {
let data = arrays.mergeSort([1, 2, 3, 4, 5, 6], (a, b) => a - b);
assert.deepEqual(data, [1, 2, 3, 4, 5, 6]);
assert.deepStrictEqual(data, [1, 2, 3, 4, 5, 6]);
});
test('mergeSort, is stable', function () {
let numbers = arrays.mergeSort([33, 22, 11, 4, 99, 1], (a, b) => 0);
assert.deepEqual(numbers, [33, 22, 11, 4, 99, 1]);
assert.deepStrictEqual(numbers, [33, 22, 11, 4, 99, 1]);
});
test('mergeSort, many random numbers', function () {
@@ -129,40 +129,40 @@ suite('Arrays', () => {
}
let d = arrays.sortedDiff([1, 2, 4], [], compare);
assert.deepEqual(d, [
assert.deepStrictEqual(d, [
{ start: 0, deleteCount: 3, toInsert: [] }
]);
d = arrays.sortedDiff([], [1, 2, 4], compare);
assert.deepEqual(d, [
assert.deepStrictEqual(d, [
{ start: 0, deleteCount: 0, toInsert: [1, 2, 4] }
]);
d = arrays.sortedDiff([1, 2, 4], [1, 2, 4], compare);
assert.deepEqual(d, []);
assert.deepStrictEqual(d, []);
d = arrays.sortedDiff([1, 2, 4], [2, 3, 4, 5], compare);
assert.deepEqual(d, [
assert.deepStrictEqual(d, [
{ start: 0, deleteCount: 1, toInsert: [] },
{ start: 2, deleteCount: 0, toInsert: [3] },
{ start: 3, deleteCount: 0, toInsert: [5] },
]);
d = arrays.sortedDiff([2, 3, 4, 5], [1, 2, 4], compare);
assert.deepEqual(d, [
assert.deepStrictEqual(d, [
{ start: 0, deleteCount: 0, toInsert: [1] },
{ start: 1, deleteCount: 1, toInsert: [] },
{ start: 3, deleteCount: 1, toInsert: [] },
]);
d = arrays.sortedDiff([1, 3, 5, 7], [5, 9, 11], compare);
assert.deepEqual(d, [
assert.deepStrictEqual(d, [
{ start: 0, deleteCount: 2, toInsert: [] },
{ start: 3, deleteCount: 1, toInsert: [9, 11] }
]);
d = arrays.sortedDiff([1, 3, 7], [5, 9, 11], compare);
assert.deepEqual(d, [
assert.deepStrictEqual(d, [
{ start: 0, deleteCount: 3, toInsert: [5, 9, 11] }
]);
});
@@ -173,32 +173,32 @@ suite('Arrays', () => {
}
let d = arrays.delta([1, 2, 4], [], compare);
assert.deepEqual(d.removed, [1, 2, 4]);
assert.deepEqual(d.added, []);
assert.deepStrictEqual(d.removed, [1, 2, 4]);
assert.deepStrictEqual(d.added, []);
d = arrays.delta([], [1, 2, 4], compare);
assert.deepEqual(d.removed, []);
assert.deepEqual(d.added, [1, 2, 4]);
assert.deepStrictEqual(d.removed, []);
assert.deepStrictEqual(d.added, [1, 2, 4]);
d = arrays.delta([1, 2, 4], [1, 2, 4], compare);
assert.deepEqual(d.removed, []);
assert.deepEqual(d.added, []);
assert.deepStrictEqual(d.removed, []);
assert.deepStrictEqual(d.added, []);
d = arrays.delta([1, 2, 4], [2, 3, 4, 5], compare);
assert.deepEqual(d.removed, [1]);
assert.deepEqual(d.added, [3, 5]);
assert.deepStrictEqual(d.removed, [1]);
assert.deepStrictEqual(d.added, [3, 5]);
d = arrays.delta([2, 3, 4, 5], [1, 2, 4], compare);
assert.deepEqual(d.removed, [3, 5]);
assert.deepEqual(d.added, [1]);
assert.deepStrictEqual(d.removed, [3, 5]);
assert.deepStrictEqual(d.added, [1]);
d = arrays.delta([1, 3, 5, 7], [5, 9, 11], compare);
assert.deepEqual(d.removed, [1, 3, 7]);
assert.deepEqual(d.added, [9, 11]);
assert.deepStrictEqual(d.removed, [1, 3, 7]);
assert.deepStrictEqual(d.added, [9, 11]);
d = arrays.delta([1, 3, 7], [5, 9, 11], compare);
assert.deepEqual(d.removed, [1, 3, 7]);
assert.deepEqual(d.added, [5, 9, 11]);
assert.deepStrictEqual(d.removed, [1, 3, 7]);
assert.deepStrictEqual(d.added, [5, 9, 11]);
});
test('binarySearch', () => {
@@ -207,13 +207,13 @@ suite('Arrays', () => {
}
const array = [1, 4, 5, 7, 55, 59, 60, 61, 64, 69];
assert.equal(arrays.binarySearch(array, 1, compare), 0);
assert.equal(arrays.binarySearch(array, 5, compare), 2);
assert.strictEqual(arrays.binarySearch(array, 1, compare), 0);
assert.strictEqual(arrays.binarySearch(array, 5, compare), 2);
// insertion point
assert.equal(arrays.binarySearch(array, 0, compare), ~0);
assert.equal(arrays.binarySearch(array, 6, compare), ~3);
assert.equal(arrays.binarySearch(array, 70, compare), ~10);
assert.strictEqual(arrays.binarySearch(array, 0, compare), ~0);
assert.strictEqual(arrays.binarySearch(array, 6, compare), ~3);
assert.strictEqual(arrays.binarySearch(array, 70, compare), ~10);
});
@@ -222,11 +222,11 @@ suite('Arrays', () => {
return a;
}
assert.deepEqual(arrays.distinct(['32', '4', '5'], compare), ['32', '4', '5']);
assert.deepEqual(arrays.distinct(['32', '4', '5', '4'], compare), ['32', '4', '5']);
assert.deepEqual(arrays.distinct(['32', 'constructor', '5', '1'], compare), ['32', 'constructor', '5', '1']);
assert.deepEqual(arrays.distinct(['32', 'constructor', 'proto', 'proto', 'constructor'], compare), ['32', 'constructor', 'proto']);
assert.deepEqual(arrays.distinct(['32', '4', '5', '32', '4', '5', '32', '4', '5', '5'], compare), ['32', '4', '5']);
assert.deepStrictEqual(arrays.distinct(['32', '4', '5'], compare), ['32', '4', '5']);
assert.deepStrictEqual(arrays.distinct(['32', '4', '5', '4'], compare), ['32', '4', '5']);
assert.deepStrictEqual(arrays.distinct(['32', 'constructor', '5', '1'], compare), ['32', 'constructor', '5', '1']);
assert.deepStrictEqual(arrays.distinct(['32', 'constructor', 'proto', 'proto', 'constructor'], compare), ['32', 'constructor', 'proto']);
assert.deepStrictEqual(arrays.distinct(['32', '4', '5', '32', '4', '5', '32', '4', '5', '5'], compare), ['32', '4', '5']);
});
test('top', () => {
@@ -236,13 +236,13 @@ suite('Arrays', () => {
return a - b;
};
assert.deepEqual(arrays.top([], cmp, 1), []);
assert.deepEqual(arrays.top([1], cmp, 0), []);
assert.deepEqual(arrays.top([1, 2], cmp, 1), [1]);
assert.deepEqual(arrays.top([2, 1], cmp, 1), [1]);
assert.deepEqual(arrays.top([1, 3, 2], cmp, 2), [1, 2]);
assert.deepEqual(arrays.top([3, 2, 1], cmp, 3), [1, 2, 3]);
assert.deepEqual(arrays.top([4, 6, 2, 7, 8, 3, 5, 1], cmp, 3), [1, 2, 3]);
assert.deepStrictEqual(arrays.top([], cmp, 1), []);
assert.deepStrictEqual(arrays.top([1], cmp, 0), []);
assert.deepStrictEqual(arrays.top([1, 2], cmp, 1), [1]);
assert.deepStrictEqual(arrays.top([2, 1], cmp, 1), [1]);
assert.deepStrictEqual(arrays.top([1, 3, 2], cmp, 2), [1, 2]);
assert.deepStrictEqual(arrays.top([3, 2, 1], cmp, 3), [1, 2, 3]);
assert.deepStrictEqual(arrays.top([4, 6, 2, 7, 8, 3, 5, 1], cmp, 3), [1, 2, 3]);
});
test('topAsync', async () => {
@@ -259,56 +259,56 @@ suite('Arrays', () => {
async function testTopAsync(cmp: any, m: number) {
{
const result = await arrays.topAsync([], cmp, 1, m);
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
}
{
const result = await arrays.topAsync([1], cmp, 0, m);
assert.deepEqual(result, []);
assert.deepStrictEqual(result, []);
}
{
const result = await arrays.topAsync([1, 2], cmp, 1, m);
assert.deepEqual(result, [1]);
assert.deepStrictEqual(result, [1]);
}
{
const result = await arrays.topAsync([2, 1], cmp, 1, m);
assert.deepEqual(result, [1]);
assert.deepStrictEqual(result, [1]);
}
{
const result = await arrays.topAsync([1, 3, 2], cmp, 2, m);
assert.deepEqual(result, [1, 2]);
assert.deepStrictEqual(result, [1, 2]);
}
{
const result = await arrays.topAsync([3, 2, 1], cmp, 3, m);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
}
{
const result = await arrays.topAsync([4, 6, 2, 7, 8, 3, 5, 1], cmp, 3, m);
assert.deepEqual(result, [1, 2, 3]);
assert.deepStrictEqual(result, [1, 2, 3]);
}
}
test('coalesce', () => {
let a: Array<number | null> = arrays.coalesce([null, 1, null, 2, 3]);
assert.equal(a.length, 3);
assert.equal(a[0], 1);
assert.equal(a[1], 2);
assert.equal(a[2], 3);
assert.strictEqual(a.length, 3);
assert.strictEqual(a[0], 1);
assert.strictEqual(a[1], 2);
assert.strictEqual(a[2], 3);
arrays.coalesce([null, 1, null, undefined, undefined, 2, 3]);
assert.equal(a.length, 3);
assert.equal(a[0], 1);
assert.equal(a[1], 2);
assert.equal(a[2], 3);
assert.strictEqual(a.length, 3);
assert.strictEqual(a[0], 1);
assert.strictEqual(a[1], 2);
assert.strictEqual(a[2], 3);
let b: number[] = [];
b[10] = 1;
b[20] = 2;
b[30] = 3;
b = arrays.coalesce(b);
assert.equal(b.length, 3);
assert.equal(b[0], 1);
assert.equal(b[1], 2);
assert.equal(b[2], 3);
assert.strictEqual(b.length, 3);
assert.strictEqual(b[0], 1);
assert.strictEqual(b[1], 2);
assert.strictEqual(b[2], 3);
let sparse: number[] = [];
sparse[0] = 1;
@@ -317,36 +317,36 @@ suite('Arrays', () => {
sparse[1000] = 1;
sparse[1001] = 1;
assert.equal(sparse.length, 1002);
assert.strictEqual(sparse.length, 1002);
sparse = arrays.coalesce(sparse);
assert.equal(sparse.length, 5);
assert.strictEqual(sparse.length, 5);
});
test('coalesce - inplace', function () {
let a: Array<number | null> = [null, 1, null, 2, 3];
arrays.coalesceInPlace(a);
assert.equal(a.length, 3);
assert.equal(a[0], 1);
assert.equal(a[1], 2);
assert.equal(a[2], 3);
assert.strictEqual(a.length, 3);
assert.strictEqual(a[0], 1);
assert.strictEqual(a[1], 2);
assert.strictEqual(a[2], 3);
a = [null, 1, null, undefined!, undefined!, 2, 3];
arrays.coalesceInPlace(a);
assert.equal(a.length, 3);
assert.equal(a[0], 1);
assert.equal(a[1], 2);
assert.equal(a[2], 3);
assert.strictEqual(a.length, 3);
assert.strictEqual(a[0], 1);
assert.strictEqual(a[1], 2);
assert.strictEqual(a[2], 3);
let b: number[] = [];
b[10] = 1;
b[20] = 2;
b[30] = 3;
arrays.coalesceInPlace(b);
assert.equal(b.length, 3);
assert.equal(b[0], 1);
assert.equal(b[1], 2);
assert.equal(b[2], 3);
assert.strictEqual(b.length, 3);
assert.strictEqual(b[0], 1);
assert.strictEqual(b[1], 2);
assert.strictEqual(b[2], 3);
let sparse: number[] = [];
sparse[0] = 1;
@@ -355,18 +355,18 @@ suite('Arrays', () => {
sparse[1000] = 1;
sparse[1001] = 1;
assert.equal(sparse.length, 1002);
assert.strictEqual(sparse.length, 1002);
arrays.coalesceInPlace(sparse);
assert.equal(sparse.length, 5);
assert.strictEqual(sparse.length, 5);
});
test('insert, remove', function () {
const array: string[] = [];
const remove = arrays.insert(array, 'foo');
assert.equal(array[0], 'foo');
assert.strictEqual(array[0], 'foo');
remove();
assert.equal(array.length, 0);
assert.strictEqual(array.length, 0);
});
});

View File

@@ -18,7 +18,7 @@ suite('Async', () => {
return new Promise(resolve => { /*never*/ });
});
let result = promise.then(_ => assert.ok(false), err => {
assert.equal(canceled, 1);
assert.strictEqual(canceled, 1);
assert.ok(isPromiseCanceledError(err));
});
promise.cancel();
@@ -33,7 +33,7 @@ suite('Async', () => {
return Promise.resolve(1234);
});
let result = promise.then(_ => assert.ok(false), err => {
assert.equal(canceled, 1);
assert.strictEqual(canceled, 1);
assert.ok(isPromiseCanceledError(err));
});
promise.cancel();
@@ -60,7 +60,7 @@ suite('Async', () => {
cancellablePromise.cancel();
order.push('afterCancel');
return promise.then(() => assert.deepEqual(order, ['in callback', 'afterCreate', 'cancelled', 'afterCancel', 'finally']));
return promise.then(() => assert.deepStrictEqual(order, ['in callback', 'afterCreate', 'cancelled', 'afterCancel', 'finally']));
});
// Cancelling an async cancelable promise is just the same as a sync cancellable promise.
@@ -82,7 +82,7 @@ suite('Async', () => {
cancellablePromise.cancel();
order.push('afterCancel');
return promise.then(() => assert.deepEqual(order, ['in callback', 'afterCreate', 'cancelled', 'afterCancel', 'finally']));
return promise.then(() => assert.deepStrictEqual(order, ['in callback', 'afterCreate', 'cancelled', 'afterCancel', 'finally']));
});
test('cancelablePromise - get inner result', async function () {
@@ -91,7 +91,7 @@ suite('Async', () => {
});
let result = await promise;
assert.equal(result, 1234);
assert.strictEqual(result, 1234);
});
test('Throttler - non async', function () {
@@ -103,12 +103,12 @@ suite('Async', () => {
let throttler = new async.Throttler();
return Promise.all([
throttler.queue(factory).then((result) => { assert.equal(result, 1); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); })
]).then(() => assert.equal(count, 2));
throttler.queue(factory).then((result) => { assert.strictEqual(result, 1); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); })
]).then(() => assert.strictEqual(count, 2));
});
test('Throttler', () => {
@@ -118,18 +118,18 @@ suite('Async', () => {
let throttler = new async.Throttler();
return Promise.all([
throttler.queue(factory).then((result) => { assert.equal(result, 1); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); })
throttler.queue(factory).then((result) => { assert.strictEqual(result, 1); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 2); })
]).then(() => {
return Promise.all([
throttler.queue(factory).then((result) => { assert.equal(result, 3); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); }),
throttler.queue(factory).then((result) => { assert.equal(result, 4); })
throttler.queue(factory).then((result) => { assert.strictEqual(result, 3); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 4); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 4); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 4); }),
throttler.queue(factory).then((result) => { assert.strictEqual(result, 4); })
]);
});
});
@@ -143,9 +143,9 @@ suite('Async', () => {
let promises: Promise<any>[] = [];
promises.push(throttler.queue(factoryFactory(1)).then((n) => { assert.equal(n, 1); }));
promises.push(throttler.queue(factoryFactory(2)).then((n) => { assert.equal(n, 3); }));
promises.push(throttler.queue(factoryFactory(3)).then((n) => { assert.equal(n, 3); }));
promises.push(throttler.queue(factoryFactory(1)).then((n) => { assert.strictEqual(n, 1); }));
promises.push(throttler.queue(factoryFactory(2)).then((n) => { assert.strictEqual(n, 3); }));
promises.push(throttler.queue(factoryFactory(3)).then((n) => { assert.strictEqual(n, 3); }));
return Promise.all(promises);
});
@@ -161,13 +161,13 @@ suite('Async', () => {
assert(!delayer.isTriggered());
promises.push(delayer.trigger(factory).then((result) => { assert.equal(result, 1); assert(!delayer.isTriggered()); }));
promises.push(delayer.trigger(factory).then((result) => { assert.strictEqual(result, 1); assert(!delayer.isTriggered()); }));
assert(delayer.isTriggered());
promises.push(delayer.trigger(factory).then((result) => { assert.equal(result, 1); assert(!delayer.isTriggered()); }));
promises.push(delayer.trigger(factory).then((result) => { assert.strictEqual(result, 1); assert(!delayer.isTriggered()); }));
assert(delayer.isTriggered());
promises.push(delayer.trigger(factory).then((result) => { assert.equal(result, 1); assert(!delayer.isTriggered()); }));
promises.push(delayer.trigger(factory).then((result) => { assert.strictEqual(result, 1); assert(!delayer.isTriggered()); }));
assert(delayer.isTriggered());
return Promise.all(promises).then(() => {
@@ -237,7 +237,7 @@ suite('Async', () => {
assert(!delayer.isTriggered());
const p = delayer.trigger(factory).then((result) => {
assert.equal(result, 1);
assert.strictEqual(result, 1);
assert(!delayer.isTriggered());
promises.push(delayer.trigger(factory).then(undefined, () => { assert(true, 'yes, it was cancelled'); }));
@@ -253,10 +253,10 @@ suite('Async', () => {
assert(!delayer.isTriggered());
promises.push(delayer.trigger(factory).then(() => { assert.equal(result, 1); assert(!delayer.isTriggered()); }));
promises.push(delayer.trigger(factory).then(() => { assert.strictEqual(result, 1); assert(!delayer.isTriggered()); }));
assert(delayer.isTriggered());
promises.push(delayer.trigger(factory).then(() => { assert.equal(result, 1); assert(!delayer.isTriggered()); }));
promises.push(delayer.trigger(factory).then(() => { assert.strictEqual(result, 1); assert(!delayer.isTriggered()); }));
assert(delayer.isTriggered());
const p = Promise.all(promises).then(() => {
@@ -286,9 +286,9 @@ suite('Async', () => {
assert(!delayer.isTriggered());
promises.push(delayer.trigger(factoryFactory(1)).then((n) => { assert.equal(n, 3); }));
promises.push(delayer.trigger(factoryFactory(2)).then((n) => { assert.equal(n, 3); }));
promises.push(delayer.trigger(factoryFactory(3)).then((n) => { assert.equal(n, 3); }));
promises.push(delayer.trigger(factoryFactory(1)).then((n) => { assert.strictEqual(n, 3); }));
promises.push(delayer.trigger(factoryFactory(2)).then((n) => { assert.strictEqual(n, 3); }));
promises.push(delayer.trigger(factoryFactory(3)).then((n) => { assert.strictEqual(n, 3); }));
const p = Promise.all(promises).then(() => {
assert(!delayer.isTriggered());
@@ -311,12 +311,12 @@ suite('Async', () => {
factoryFactory(4),
factoryFactory(5),
]).then((result) => {
assert.equal(5, result.length);
assert.equal(1, result[0]);
assert.equal(2, result[1]);
assert.equal(3, result[2]);
assert.equal(4, result[3]);
assert.equal(5, result[4]);
assert.strictEqual(5, result.length);
assert.strictEqual(1, result[0]);
assert.strictEqual(2, result[1]);
assert.strictEqual(3, result[2]);
assert.strictEqual(4, result[3]);
assert.strictEqual(5, result[4]);
});
});
@@ -331,7 +331,7 @@ suite('Async', () => {
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return Promise.all(promises).then((res) => {
assert.equal(10, res.length);
assert.strictEqual(10, res.length);
limiter = new async.Limiter(100);
@@ -339,7 +339,7 @@ suite('Async', () => {
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return Promise.all(promises).then((res) => {
assert.equal(10, res.length);
assert.strictEqual(10, res.length);
});
});
});
@@ -352,7 +352,7 @@ suite('Async', () => {
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return Promise.all(promises).then((res) => {
assert.equal(10, res.length);
assert.strictEqual(10, res.length);
limiter = new async.Limiter(100);
@@ -360,7 +360,7 @@ suite('Async', () => {
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return Promise.all(promises).then((res) => {
assert.equal(10, res.length);
assert.strictEqual(10, res.length);
});
});
});
@@ -379,8 +379,8 @@ suite('Async', () => {
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return Promise.all(promises).then((res) => {
assert.equal(10, res.length);
assert.deepEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], res);
assert.strictEqual(10, res.length);
assert.deepStrictEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], res);
});
});
@@ -393,15 +393,15 @@ suite('Async', () => {
let asyncPromise = false;
let f2 = () => async.timeout(10).then(() => asyncPromise = true);
assert.equal(queue.size, 0);
assert.strictEqual(queue.size, 0);
queue.queue(f1);
assert.equal(queue.size, 1);
assert.strictEqual(queue.size, 1);
const p = queue.queue(f2);
assert.equal(queue.size, 2);
assert.strictEqual(queue.size, 2);
return p.then(() => {
assert.equal(queue.size, 0);
assert.strictEqual(queue.size, 0);
assert.ok(syncPromise);
assert.ok(asyncPromise);
});
@@ -423,11 +423,11 @@ suite('Async', () => {
queue.queue(f3);
queue.queue(f4);
return queue.queue(f5).then(() => {
assert.equal(res[0], 1);
assert.equal(res[1], 2);
assert.equal(res[2], 3);
assert.equal(res[3], 4);
assert.equal(res[4], 5);
assert.strictEqual(res[0], 1);
assert.strictEqual(res[1], 2);
assert.strictEqual(res[2], 3);
assert.strictEqual(res[3], 4);
assert.strictEqual(res[4], 5);
});
});
@@ -448,11 +448,11 @@ suite('Async', () => {
queue.queue(f3).then(undefined, () => error = true);
queue.queue(f4);
return queue.queue(f5).then(() => {
assert.equal(res[0], 1);
assert.equal(res[1], 2);
assert.strictEqual(res[0], 1);
assert.strictEqual(res[1], 2);
assert.ok(error);
assert.equal(res[2], 4);
assert.equal(res[3], 5);
assert.strictEqual(res[2], 4);
assert.strictEqual(res[3], 5);
});
});
@@ -472,11 +472,11 @@ suite('Async', () => {
return queue.queue(f3).then(() => {
return queue.queue(f4).then(() => {
return queue.queue(f5).then(() => {
assert.equal(res[0], 1);
assert.equal(res[1], 2);
assert.equal(res[2], 3);
assert.equal(res[3], 4);
assert.equal(res[4], 5);
assert.strictEqual(res[0], 1);
assert.strictEqual(res[1], 2);
assert.strictEqual(res[2], 3);
assert.strictEqual(res[3], 4);
assert.strictEqual(res[4], 5);
});
});
});
@@ -521,7 +521,7 @@ suite('Async', () => {
assert.ok(r1Queue);
assert.ok(r2Queue);
assert.equal(r1Queue, queue.queueFor(URI.file('/some/path'))); // same queue returned
assert.strictEqual(r1Queue, queue.queueFor(URI.file('/some/path'))); // same queue returned
let syncPromiseFactory = () => Promise.resolve(undefined);
@@ -545,7 +545,7 @@ suite('Async', () => {
return Promise.resolve(true);
}, 10, 3);
assert.equal(res, true);
assert.strictEqual(res, true);
});
test('retry - error case', async () => {
@@ -555,7 +555,7 @@ suite('Async', () => {
return Promise.reject(expectedError);
}, 10, 3);
} catch (error) {
assert.equal(error, error);
assert.strictEqual(error, error);
}
});
@@ -576,12 +576,12 @@ suite('Async', () => {
sequentializer.setPending(2, async.timeout(1));
assert.ok(sequentializer.hasPending());
assert.ok(sequentializer.hasPending(2));
assert.ok(!sequentializer.hasPending(1));
assert.strictEqual(sequentializer.hasPending(1), false);
assert.ok(sequentializer.pending);
await async.timeout(2);
assert.ok(!sequentializer.hasPending());
assert.ok(!sequentializer.hasPending(2));
assert.strictEqual(sequentializer.hasPending(), false);
assert.strictEqual(sequentializer.hasPending(2), false);
assert.ok(!sequentializer.pending);
});
@@ -673,7 +673,7 @@ suite('Async', () => {
await p1;
assert.ok(!triggered);
assert.equal(timedout, true);
assert.strictEqual(timedout, true);
// promise wins
timedout = false;
@@ -684,38 +684,42 @@ suite('Async', () => {
await p2;
assert.ok(triggered);
assert.equal(timedout, false);
assert.strictEqual(timedout, false);
});
test('SequencerByKey', async () => {
const s = new async.SequencerByKey<string>();
const r1 = await s.queue('key1', () => Promise.resolve('hello'));
assert.equal(r1, 'hello');
assert.strictEqual(r1, 'hello');
await s.queue('key2', () => Promise.reject(new Error('failed'))).then(() => {
throw new Error('should not be resolved');
}, err => {
// Expected error
assert.equal(err.message, 'failed');
assert.strictEqual(err.message, 'failed');
});
// Still works after a queued promise is rejected
const r3 = await s.queue('key2', () => Promise.resolve('hello'));
assert.equal(r3, 'hello');
assert.strictEqual(r3, 'hello');
});
test('IntervalCounter', async () => {
const counter = new async.IntervalCounter(10);
assert.equal(counter.increment(), 1);
assert.equal(counter.increment(), 2);
assert.equal(counter.increment(), 3);
assert.strictEqual(counter.increment(), 1);
assert.strictEqual(counter.increment(), 2);
assert.strictEqual(counter.increment(), 3);
const now = Date.now();
await async.timeout(20);
if (Date.now() - now < 11) {
return; // Firefox in Playwright seems to have a flaky timeout implementation (https://github.com/microsoft/vscode/issues/114028)
}
assert.equal(counter.increment(), 1);
assert.equal(counter.increment(), 2);
assert.equal(counter.increment(), 3);
assert.strictEqual(counter.increment(), 1);
assert.strictEqual(counter.increment(), 2);
assert.strictEqual(counter.increment(), 3);
});
test('firstParallel - simple', async () => {
@@ -724,19 +728,19 @@ suite('Async', () => {
Promise.resolve(2),
Promise.resolve(3),
], v => v === 2);
assert.equal(a, 2);
assert.strictEqual(a, 2);
});
test('firstParallel - uses null default', async () => {
assert.equal(await async.firstParallel([Promise.resolve(1)], v => v === 2), null);
assert.strictEqual(await async.firstParallel([Promise.resolve(1)], v => v === 2), null);
});
test('firstParallel - uses value default', async () => {
assert.equal(await async.firstParallel([Promise.resolve(1)], v => v === 2, 4), 4);
assert.strictEqual(await async.firstParallel([Promise.resolve(1)], v => v === 2, 4), 4);
});
test('firstParallel - empty', async () => {
assert.equal(await async.firstParallel([], v => v === 2, 4), 4);
assert.strictEqual(await async.firstParallel([], v => v === 2, 4), 4);
});
test('firstParallel - cancels', async () => {
@@ -753,9 +757,9 @@ suite('Async', () => {
return 2;
});
assert.equal(await async.firstParallel([p1, p2], v => v === 2, 4), 2);
assert.equal(ct1!.isCancellationRequested, true, 'should cancel a');
assert.equal(ct2!.isCancellationRequested, true, 'should cancel b');
assert.strictEqual(await async.firstParallel([p1, p2], v => v === 2, 4), 2);
assert.strictEqual(ct1!.isCancellationRequested, true, 'should cancel a');
assert.strictEqual(ct2!.isCancellationRequested, true, 'should cancel b');
});
test('firstParallel - rejection handling', async () => {
@@ -772,8 +776,35 @@ suite('Async', () => {
throw new Error('oh no');
});
assert.equal(await async.firstParallel([p1, p2], v => v === 2, 4).catch(() => 'ok'), 'ok');
assert.equal(ct1!.isCancellationRequested, true, 'should cancel a');
assert.equal(ct2!.isCancellationRequested, true, 'should cancel b');
assert.strictEqual(await async.firstParallel([p1, p2], v => v === 2, 4).catch(() => 'ok'), 'ok');
assert.strictEqual(ct1!.isCancellationRequested, true, 'should cancel a');
assert.strictEqual(ct2!.isCancellationRequested, true, 'should cancel b');
});
suite('DeferredPromise', () => {
test('resolves', async () => {
const deferred = new async.DeferredPromise<number>();
assert.strictEqual(deferred.isResolved, false);
deferred.complete(42);
assert.strictEqual(await deferred.p, 42);
assert.strictEqual(deferred.isResolved, true);
});
test('rejects', async () => {
const deferred = new async.DeferredPromise<number>();
assert.strictEqual(deferred.isRejected, false);
const err = new Error('oh no!');
deferred.error(err);
assert.strictEqual(await deferred.p.catch(e => e), err);
assert.strictEqual(deferred.isRejected, true);
});
test('cancels', async () => {
const deferred = new async.DeferredPromise<number>();
assert.strictEqual(deferred.isRejected, false);
deferred.cancel();
assert.strictEqual((await deferred.p.catch(e => e)).name, 'Canceled');
assert.strictEqual(deferred.isRejected, true);
});
});
});

View File

@@ -13,28 +13,28 @@ suite('Buffer', () => {
test('issue #71993 - VSBuffer#toString returns numbers', () => {
const data = new Uint8Array([1, 2, 3, 'h'.charCodeAt(0), 'i'.charCodeAt(0), 4, 5]).buffer;
const buffer = VSBuffer.wrap(new Uint8Array(data, 3, 2));
assert.deepEqual(buffer.toString(), 'hi');
assert.deepStrictEqual(buffer.toString(), 'hi');
});
test('bufferToReadable / readableToBuffer', () => {
const content = 'Hello World';
const readable = bufferToReadable(VSBuffer.fromString(content));
assert.equal(readableToBuffer(readable).toString(), content);
assert.strictEqual(readableToBuffer(readable).toString(), content);
});
test('bufferToStream / streamToBuffer', async () => {
const content = 'Hello World';
const stream = bufferToStream(VSBuffer.fromString(content));
assert.equal((await streamToBuffer(stream)).toString(), content);
assert.strictEqual((await streamToBuffer(stream)).toString(), content);
});
test('bufferedStreamToBuffer', async () => {
const content = 'Hello World';
const stream = await peekStream(bufferToStream(VSBuffer.fromString(content)), 1);
assert.equal((await bufferedStreamToBuffer(stream)).toString(), content);
assert.strictEqual((await bufferedStreamToBuffer(stream)).toString(), content);
});
test('bufferWriteableStream - basics (no error)', async () => {
@@ -60,11 +60,11 @@ suite('Buffer', () => {
await timeout(0);
stream.end(VSBuffer.fromString('World'));
assert.equal(chunks.length, 2);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(chunks[1].toString(), 'World');
assert.equal(ended, true);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 2);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(chunks[1].toString(), 'World');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 0);
});
test('bufferWriteableStream - basics (error)', async () => {
@@ -90,10 +90,10 @@ suite('Buffer', () => {
await timeout(0);
stream.end(new Error());
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(ended, true);
assert.equal(errors.length, 1);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 1);
});
test('bufferWriteableStream - buffers data when no listener', async () => {
@@ -119,10 +119,10 @@ suite('Buffer', () => {
errors.push(error);
});
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'HelloWorld');
assert.equal(ended, true);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'HelloWorld');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 0);
});
test('bufferWriteableStream - buffers errors when no listener', async () => {
@@ -150,10 +150,10 @@ suite('Buffer', () => {
stream.end();
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(ended, true);
assert.equal(errors.length, 1);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 1);
});
test('bufferWriteableStream - buffers end when no listener', async () => {
@@ -179,10 +179,10 @@ suite('Buffer', () => {
errors.push(error);
});
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'HelloWorld');
assert.equal(ended, true);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'HelloWorld');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 0);
});
test('bufferWriteableStream - nothing happens after end()', async () => {
@@ -220,13 +220,13 @@ suite('Buffer', () => {
await timeout(0);
stream.end(VSBuffer.fromString('World'));
assert.equal(dataCalledAfterEnd, false);
assert.equal(errorCalledAfterEnd, false);
assert.equal(endCalledAfterEnd, false);
assert.strictEqual(dataCalledAfterEnd, false);
assert.strictEqual(errorCalledAfterEnd, false);
assert.strictEqual(endCalledAfterEnd, false);
assert.equal(chunks.length, 2);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(chunks[1].toString(), 'World');
assert.strictEqual(chunks.length, 2);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(chunks[1].toString(), 'World');
});
test('bufferWriteableStream - pause/resume (simple)', async () => {
@@ -254,16 +254,16 @@ suite('Buffer', () => {
await timeout(0);
stream.end(VSBuffer.fromString('World'));
assert.equal(chunks.length, 0);
assert.equal(errors.length, 0);
assert.equal(ended, false);
assert.strictEqual(chunks.length, 0);
assert.strictEqual(errors.length, 0);
assert.strictEqual(ended, false);
stream.resume();
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'HelloWorld');
assert.equal(ended, true);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'HelloWorld');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 0);
});
test('bufferWriteableStream - pause/resume (pause after first write)', async () => {
@@ -292,18 +292,18 @@ suite('Buffer', () => {
await timeout(0);
stream.end(VSBuffer.fromString('World'));
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(errors.length, 0);
assert.equal(ended, false);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(errors.length, 0);
assert.strictEqual(ended, false);
stream.resume();
assert.equal(chunks.length, 2);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(chunks[1].toString(), 'World');
assert.equal(ended, true);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 2);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(chunks[1].toString(), 'World');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 0);
});
test('bufferWriteableStream - pause/resume (error)', async () => {
@@ -331,16 +331,16 @@ suite('Buffer', () => {
await timeout(0);
stream.end(new Error());
assert.equal(chunks.length, 0);
assert.equal(ended, false);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 0);
assert.strictEqual(ended, false);
assert.strictEqual(errors.length, 0);
stream.resume();
assert.equal(chunks.length, 1);
assert.equal(chunks[0].toString(), 'Hello');
assert.equal(ended, true);
assert.equal(errors.length, 1);
assert.strictEqual(chunks.length, 1);
assert.strictEqual(chunks[0].toString(), 'Hello');
assert.strictEqual(ended, true);
assert.strictEqual(errors.length, 1);
});
test('bufferWriteableStream - destroy', async () => {
@@ -368,46 +368,46 @@ suite('Buffer', () => {
await timeout(0);
stream.end(VSBuffer.fromString('World'));
assert.equal(chunks.length, 0);
assert.equal(ended, false);
assert.equal(errors.length, 0);
assert.strictEqual(chunks.length, 0);
assert.strictEqual(ended, false);
assert.strictEqual(errors.length, 0);
});
test('Performance issue with VSBuffer#slice #76076', function () {
test('Performance issue with VSBuffer#slice #76076', function () { // TODO@alexdima this test seems to fail in web (https://github.com/microsoft/vscode/issues/114042)
// Buffer#slice creates a view
{
if (typeof Buffer !== 'undefined') {
const buff = Buffer.from([10, 20, 30, 40]);
const b2 = buff.slice(1, 3);
assert.equal(buff[1], 20);
assert.equal(b2[0], 20);
assert.strictEqual(buff[1], 20);
assert.strictEqual(b2[0], 20);
buff[1] = 17; // modify buff AND b2
assert.equal(buff[1], 17);
assert.equal(b2[0], 17);
assert.strictEqual(buff[1], 17);
assert.strictEqual(b2[0], 17);
}
// TypedArray#slice creates a copy
{
const unit = new Uint8Array([10, 20, 30, 40]);
const u2 = unit.slice(1, 3);
assert.equal(unit[1], 20);
assert.equal(u2[0], 20);
assert.strictEqual(unit[1], 20);
assert.strictEqual(u2[0], 20);
unit[1] = 17; // modify unit, NOT b2
assert.equal(unit[1], 17);
assert.equal(u2[0], 20);
assert.strictEqual(unit[1], 17);
assert.strictEqual(u2[0], 20);
}
// TypedArray#subarray creates a view
{
const unit = new Uint8Array([10, 20, 30, 40]);
const u2 = unit.subarray(1, 3);
assert.equal(unit[1], 20);
assert.equal(u2[0], 20);
assert.strictEqual(unit[1], 20);
assert.strictEqual(u2[0], 20);
unit[1] = 17; // modify unit AND b2
assert.equal(unit[1], 17);
assert.equal(u2[0], 17);
assert.strictEqual(unit[1], 17);
assert.strictEqual(u2[0], 17);
}
});
});

View File

@@ -8,17 +8,17 @@ import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cance
suite('CancellationToken', function () {
test('None', () => {
assert.equal(CancellationToken.None.isCancellationRequested, false);
assert.equal(typeof CancellationToken.None.onCancellationRequested, 'function');
assert.strictEqual(CancellationToken.None.isCancellationRequested, false);
assert.strictEqual(typeof CancellationToken.None.onCancellationRequested, 'function');
});
test('cancel before token', function (done) {
const source = new CancellationTokenSource();
assert.equal(source.token.isCancellationRequested, false);
assert.strictEqual(source.token.isCancellationRequested, false);
source.cancel();
assert.equal(source.token.isCancellationRequested, true);
assert.strictEqual(source.token.isCancellationRequested, true);
source.token.onCancellationRequested(function () {
assert.ok(true);
@@ -29,7 +29,7 @@ suite('CancellationToken', function () {
test('cancel happens only once', function () {
let source = new CancellationTokenSource();
assert.equal(source.token.isCancellationRequested, false);
assert.strictEqual(source.token.isCancellationRequested, false);
let cancelCount = 0;
function onCancel() {
@@ -41,7 +41,7 @@ suite('CancellationToken', function () {
source.cancel();
source.cancel();
assert.equal(cancelCount, 1);
assert.strictEqual(cancelCount, 1);
});
test('cancel calls all listeners', function () {
@@ -60,7 +60,7 @@ suite('CancellationToken', function () {
});
source.cancel();
assert.equal(count, 3);
assert.strictEqual(count, 3);
});
test('token stays the same', function () {
@@ -92,7 +92,7 @@ suite('CancellationToken', function () {
source.dispose();
source.cancel();
assert.equal(count, 0);
assert.strictEqual(count, 0);
});
test('dispose calls no listeners (unless told to cancel)', function () {
@@ -106,7 +106,7 @@ suite('CancellationToken', function () {
source.dispose(true);
// source.cancel();
assert.equal(count, 1);
assert.strictEqual(count, 1);
});
test('parent cancels child', function () {
@@ -119,8 +119,8 @@ suite('CancellationToken', function () {
parent.cancel();
assert.equal(count, 1);
assert.equal(child.token.isCancellationRequested, true);
assert.equal(parent.token.isCancellationRequested, true);
assert.strictEqual(count, 1);
assert.strictEqual(child.token.isCancellationRequested, true);
assert.strictEqual(parent.token.isCancellationRequested, true);
});
});

View File

@@ -10,7 +10,7 @@ suite('CharCode', () => {
test('has good values', () => {
function assertValue(actual: CharCode, expected: string): void {
assert.equal(actual, expected.charCodeAt(0), 'char code ok for <<' + expected + '>>');
assert.strictEqual(actual, expected.charCodeAt(0), 'char code ok for <<' + expected + '>>');
}
assertValue(CharCode.Tab, '\t');

View File

@@ -1,78 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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 { IMatch } from 'vs/base/common/filters';
import { matchesFuzzyCodiconAware, parseCodicons, IParsedCodicons } from 'vs/base/common/codicon';
import { stripCodicons } from 'vs/base/common/codicons';
export interface ICodiconFilter {
// Returns null if word doesn't match.
(query: string, target: IParsedCodicons): IMatch[] | null;
}
function filterOk(filter: ICodiconFilter, word: string, target: IParsedCodicons, highlights?: { start: number; end: number; }[]) {
let r = filter(word, target);
assert(r);
if (highlights) {
assert.deepEqual(r, highlights);
}
}
suite('Codicon', () => {
test('matchesFuzzzyCodiconAware', () => {
// Camel Case
filterOk(matchesFuzzyCodiconAware, 'ccr', parseCodicons('$(codicon)CamelCaseRocks$(codicon)'), [
{ start: 10, end: 11 },
{ start: 15, end: 16 },
{ start: 19, end: 20 }
]);
filterOk(matchesFuzzyCodiconAware, 'ccr', parseCodicons('$(codicon) CamelCaseRocks $(codicon)'), [
{ start: 11, end: 12 },
{ start: 16, end: 17 },
{ start: 20, end: 21 }
]);
filterOk(matchesFuzzyCodiconAware, 'iut', parseCodicons('$(codicon) Indent $(octico) Using $(octic) Tpaces'), [
{ start: 11, end: 12 },
{ start: 28, end: 29 },
{ start: 43, end: 44 },
]);
// Prefix
filterOk(matchesFuzzyCodiconAware, 'using', parseCodicons('$(codicon) Indent Using Spaces'), [
{ start: 18, end: 23 },
]);
// Broken Codicon
filterOk(matchesFuzzyCodiconAware, 'codicon', parseCodicons('This $(codicon Indent Using Spaces'), [
{ start: 7, end: 14 },
]);
filterOk(matchesFuzzyCodiconAware, 'indent', parseCodicons('This $codicon Indent Using Spaces'), [
{ start: 14, end: 20 },
]);
// Testing #59343
filterOk(matchesFuzzyCodiconAware, 'unt', parseCodicons('$(primitive-dot) $(file-text) Untitled-1'), [
{ start: 30, end: 33 },
]);
});
});
suite('Codicons', () => {
test('stripCodicons', () => {
assert.equal(stripCodicons('Hello World'), 'Hello World');
assert.equal(stripCodicons('$(Hello World'), '$(Hello World');
assert.equal(stripCodicons('$(Hello) World'), ' World');
assert.equal(stripCodicons('$(Hello) W$(oi)rld'), ' Wrld');
});
});

View File

@@ -45,4 +45,4 @@ suite('Console', () => {
assert.equal(frame.line, 18);
assert.equal(frame.column, 17);
});
});
});

View File

@@ -49,11 +49,11 @@ function assertAnswer(originalStr: string, modifiedStr: string, changes: IDiffCh
let modifiedAnswer = maskBasedSubstring(modifiedStr, modifiedMask);
if (onlyLength) {
assert.equal(originalAnswer.length, answerStr.length);
assert.equal(modifiedAnswer.length, answerStr.length);
assert.strictEqual(originalAnswer.length, answerStr.length);
assert.strictEqual(modifiedAnswer.length, answerStr.length);
} else {
assert.equal(originalAnswer, answerStr);
assert.equal(modifiedAnswer, answerStr);
assert.strictEqual(originalAnswer, answerStr);
assert.strictEqual(modifiedAnswer, answerStr);
}
}
@@ -106,18 +106,18 @@ suite('Diff - Ported from VS', () => {
let predicateCallCount = 0;
let diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, longestMatchSoFar) {
assert.equal(predicateCallCount, 0);
assert.strictEqual(predicateCallCount, 0);
predicateCallCount++;
assert.equal(leftIndex, 1);
assert.strictEqual(leftIndex, 1);
// cancel processing
return false;
});
let changes = diff.ComputeDiff(true).changes;
assert.equal(predicateCallCount, 1);
assert.strictEqual(predicateCallCount, 1);
// Doesn't include 'c', 'd', or 'e', since we quit on the first request
assertAnswer(left, right, changes, 'abf');

View File

@@ -11,39 +11,37 @@ import { CharCode } from 'vs/base/common/charCode';
suite('Paths', () => {
test('toForwardSlashes', () => {
assert.equal(extpath.toSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path');
assert.equal(extpath.toSlashes('c:\\test'), 'c:/test');
assert.equal(extpath.toSlashes('foo\\bar'), 'foo/bar');
assert.equal(extpath.toSlashes('/user/far'), '/user/far');
assert.strictEqual(extpath.toSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path');
assert.strictEqual(extpath.toSlashes('c:\\test'), 'c:/test');
assert.strictEqual(extpath.toSlashes('foo\\bar'), 'foo/bar');
assert.strictEqual(extpath.toSlashes('/user/far'), '/user/far');
});
test('getRoot', () => {
assert.equal(extpath.getRoot('/user/far'), '/');
assert.equal(extpath.getRoot('\\\\server\\share\\some\\path'), '//server/share/');
assert.equal(extpath.getRoot('//server/share/some/path'), '//server/share/');
assert.equal(extpath.getRoot('//server/share'), '/');
assert.equal(extpath.getRoot('//server'), '/');
assert.equal(extpath.getRoot('//server//'), '/');
assert.equal(extpath.getRoot('c:/user/far'), 'c:/');
assert.equal(extpath.getRoot('c:user/far'), 'c:');
assert.equal(extpath.getRoot('http://www'), '');
assert.equal(extpath.getRoot('http://www/'), 'http://www/');
assert.equal(extpath.getRoot('file:///foo'), 'file:///');
assert.equal(extpath.getRoot('file://foo'), '');
assert.strictEqual(extpath.getRoot('/user/far'), '/');
assert.strictEqual(extpath.getRoot('\\\\server\\share\\some\\path'), '//server/share/');
assert.strictEqual(extpath.getRoot('//server/share/some/path'), '//server/share/');
assert.strictEqual(extpath.getRoot('//server/share'), '/');
assert.strictEqual(extpath.getRoot('//server'), '/');
assert.strictEqual(extpath.getRoot('//server//'), '/');
assert.strictEqual(extpath.getRoot('c:/user/far'), 'c:/');
assert.strictEqual(extpath.getRoot('c:user/far'), 'c:');
assert.strictEqual(extpath.getRoot('http://www'), '');
assert.strictEqual(extpath.getRoot('http://www/'), 'http://www/');
assert.strictEqual(extpath.getRoot('file:///foo'), 'file:///');
assert.strictEqual(extpath.getRoot('file://foo'), '');
});
test('isUNC', () => {
if (platform.isWindows) {
assert.ok(!extpath.isUNC('foo'));
assert.ok(!extpath.isUNC('/foo'));
assert.ok(!extpath.isUNC('\\foo'));
assert.ok(!extpath.isUNC('\\\\foo'));
assert.ok(extpath.isUNC('\\\\a\\b'));
assert.ok(!extpath.isUNC('//a/b'));
assert.ok(extpath.isUNC('\\\\server\\share'));
assert.ok(extpath.isUNC('\\\\server\\share\\'));
assert.ok(extpath.isUNC('\\\\server\\share\\path'));
}
(!platform.isWindows ? test.skip : test)('isUNC', () => {
assert.ok(!extpath.isUNC('foo'));
assert.ok(!extpath.isUNC('/foo'));
assert.ok(!extpath.isUNC('\\foo'));
assert.ok(!extpath.isUNC('\\\\foo'));
assert.ok(extpath.isUNC('\\\\a\\b'));
assert.ok(!extpath.isUNC('//a/b'));
assert.ok(extpath.isUNC('\\\\server\\share'));
assert.ok(extpath.isUNC('\\\\server\\share\\'));
assert.ok(extpath.isUNC('\\\\server\\share\\path'));
});
test('isValidBasename', () => {
@@ -75,41 +73,41 @@ suite('Paths', () => {
test('sanitizeFilePath', () => {
if (platform.isWindows) {
assert.equal(extpath.sanitizeFilePath('.', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.equal(extpath.sanitizeFilePath('', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.strictEqual(extpath.sanitizeFilePath('.', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.strictEqual(extpath.sanitizeFilePath('', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.equal(extpath.sanitizeFilePath('C:', 'C:\\the\\cwd'), 'C:\\');
assert.equal(extpath.sanitizeFilePath('C:\\', 'C:\\the\\cwd'), 'C:\\');
assert.equal(extpath.sanitizeFilePath('C:\\\\', 'C:\\the\\cwd'), 'C:\\');
assert.strictEqual(extpath.sanitizeFilePath('C:', 'C:\\the\\cwd'), 'C:\\');
assert.strictEqual(extpath.sanitizeFilePath('C:\\', 'C:\\the\\cwd'), 'C:\\');
assert.strictEqual(extpath.sanitizeFilePath('C:\\\\', 'C:\\the\\cwd'), 'C:\\');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my.txt', 'C:\\the\\cwd'), 'C:\\folder\\my.txt');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\..\\my', 'C:\\the\\cwd'), 'C:\\my');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my\\', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my\\\\\\', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.strictEqual(extpath.sanitizeFilePath('C:\\folder\\my.txt', 'C:\\the\\cwd'), 'C:\\folder\\my.txt');
assert.strictEqual(extpath.sanitizeFilePath('C:\\folder\\my', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.strictEqual(extpath.sanitizeFilePath('C:\\folder\\..\\my', 'C:\\the\\cwd'), 'C:\\my');
assert.strictEqual(extpath.sanitizeFilePath('C:\\folder\\my\\', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.strictEqual(extpath.sanitizeFilePath('C:\\folder\\my\\\\\\', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.equal(extpath.sanitizeFilePath('my.txt', 'C:\\the\\cwd'), 'C:\\the\\cwd\\my.txt');
assert.equal(extpath.sanitizeFilePath('my.txt\\', 'C:\\the\\cwd'), 'C:\\the\\cwd\\my.txt');
assert.strictEqual(extpath.sanitizeFilePath('my.txt', 'C:\\the\\cwd'), 'C:\\the\\cwd\\my.txt');
assert.strictEqual(extpath.sanitizeFilePath('my.txt\\', 'C:\\the\\cwd'), 'C:\\the\\cwd\\my.txt');
assert.equal(extpath.sanitizeFilePath('\\\\localhost\\folder\\my', 'C:\\the\\cwd'), '\\\\localhost\\folder\\my');
assert.equal(extpath.sanitizeFilePath('\\\\localhost\\folder\\my\\', 'C:\\the\\cwd'), '\\\\localhost\\folder\\my');
assert.strictEqual(extpath.sanitizeFilePath('\\\\localhost\\folder\\my', 'C:\\the\\cwd'), '\\\\localhost\\folder\\my');
assert.strictEqual(extpath.sanitizeFilePath('\\\\localhost\\folder\\my\\', 'C:\\the\\cwd'), '\\\\localhost\\folder\\my');
} else {
assert.equal(extpath.sanitizeFilePath('.', '/the/cwd'), '/the/cwd');
assert.equal(extpath.sanitizeFilePath('', '/the/cwd'), '/the/cwd');
assert.equal(extpath.sanitizeFilePath('/', '/the/cwd'), '/');
assert.strictEqual(extpath.sanitizeFilePath('.', '/the/cwd'), '/the/cwd');
assert.strictEqual(extpath.sanitizeFilePath('', '/the/cwd'), '/the/cwd');
assert.strictEqual(extpath.sanitizeFilePath('/', '/the/cwd'), '/');
assert.equal(extpath.sanitizeFilePath('/folder/my.txt', '/the/cwd'), '/folder/my.txt');
assert.equal(extpath.sanitizeFilePath('/folder/my', '/the/cwd'), '/folder/my');
assert.equal(extpath.sanitizeFilePath('/folder/../my', '/the/cwd'), '/my');
assert.equal(extpath.sanitizeFilePath('/folder/my/', '/the/cwd'), '/folder/my');
assert.equal(extpath.sanitizeFilePath('/folder/my///', '/the/cwd'), '/folder/my');
assert.strictEqual(extpath.sanitizeFilePath('/folder/my.txt', '/the/cwd'), '/folder/my.txt');
assert.strictEqual(extpath.sanitizeFilePath('/folder/my', '/the/cwd'), '/folder/my');
assert.strictEqual(extpath.sanitizeFilePath('/folder/../my', '/the/cwd'), '/my');
assert.strictEqual(extpath.sanitizeFilePath('/folder/my/', '/the/cwd'), '/folder/my');
assert.strictEqual(extpath.sanitizeFilePath('/folder/my///', '/the/cwd'), '/folder/my');
assert.equal(extpath.sanitizeFilePath('my.txt', '/the/cwd'), '/the/cwd/my.txt');
assert.equal(extpath.sanitizeFilePath('my.txt/', '/the/cwd'), '/the/cwd/my.txt');
assert.strictEqual(extpath.sanitizeFilePath('my.txt', '/the/cwd'), '/the/cwd/my.txt');
assert.strictEqual(extpath.sanitizeFilePath('my.txt/', '/the/cwd'), '/the/cwd/my.txt');
}
});
test('isRoot', () => {
test('isRootOrDriveLetter', () => {
if (platform.isWindows) {
assert.ok(extpath.isRootOrDriveLetter('c:'));
assert.ok(extpath.isRootOrDriveLetter('D:'));
@@ -123,6 +121,34 @@ suite('Paths', () => {
}
});
test('hasDriveLetter', () => {
if (platform.isWindows) {
assert.ok(extpath.hasDriveLetter('c:'));
assert.ok(extpath.hasDriveLetter('D:'));
assert.ok(extpath.hasDriveLetter('D:/'));
assert.ok(extpath.hasDriveLetter('D:\\'));
assert.ok(extpath.hasDriveLetter('D:\\path'));
assert.ok(extpath.hasDriveLetter('D:/path'));
} else {
assert.ok(!extpath.hasDriveLetter('/'));
assert.ok(!extpath.hasDriveLetter('/path'));
}
});
test('getDriveLetter', () => {
if (platform.isWindows) {
assert.strictEqual(extpath.getDriveLetter('c:'), 'c');
assert.strictEqual(extpath.getDriveLetter('D:'), 'D');
assert.strictEqual(extpath.getDriveLetter('D:/'), 'D');
assert.strictEqual(extpath.getDriveLetter('D:\\'), 'D');
assert.strictEqual(extpath.getDriveLetter('D:\\path'), 'D');
assert.strictEqual(extpath.getDriveLetter('D:/path'), 'D');
} else {
assert.ok(!extpath.getDriveLetter('/'));
assert.ok(!extpath.getDriveLetter('/path'));
}
});
test('isWindowsDriveLetter', () => {
assert.ok(!extpath.isWindowsDriveLetter(0));
assert.ok(!extpath.isWindowsDriveLetter(-1));
@@ -131,47 +157,47 @@ suite('Paths', () => {
});
test('indexOfPath', () => {
assert.equal(extpath.indexOfPath('/foo', '/bar', true), -1);
assert.equal(extpath.indexOfPath('/foo', '/FOO', false), -1);
assert.equal(extpath.indexOfPath('/foo', '/FOO', true), 0);
assert.equal(extpath.indexOfPath('/some/long/path', '/some/long', false), 0);
assert.equal(extpath.indexOfPath('/some/long/path', '/PATH', true), 10);
assert.strictEqual(extpath.indexOfPath('/foo', '/bar', true), -1);
assert.strictEqual(extpath.indexOfPath('/foo', '/FOO', false), -1);
assert.strictEqual(extpath.indexOfPath('/foo', '/FOO', true), 0);
assert.strictEqual(extpath.indexOfPath('/some/long/path', '/some/long', false), 0);
assert.strictEqual(extpath.indexOfPath('/some/long/path', '/PATH', true), 10);
});
test('parseLineAndColumnAware', () => {
let res = extpath.parseLineAndColumnAware('/foo/bar');
assert.equal(res.path, '/foo/bar');
assert.equal(res.line, undefined);
assert.equal(res.column, undefined);
assert.strictEqual(res.path, '/foo/bar');
assert.strictEqual(res.line, undefined);
assert.strictEqual(res.column, undefined);
res = extpath.parseLineAndColumnAware('/foo/bar:33');
assert.equal(res.path, '/foo/bar');
assert.equal(res.line, 33);
assert.equal(res.column, 1);
assert.strictEqual(res.path, '/foo/bar');
assert.strictEqual(res.line, 33);
assert.strictEqual(res.column, 1);
res = extpath.parseLineAndColumnAware('/foo/bar:33:34');
assert.equal(res.path, '/foo/bar');
assert.equal(res.line, 33);
assert.equal(res.column, 34);
assert.strictEqual(res.path, '/foo/bar');
assert.strictEqual(res.line, 33);
assert.strictEqual(res.column, 34);
res = extpath.parseLineAndColumnAware('C:\\foo\\bar');
assert.equal(res.path, 'C:\\foo\\bar');
assert.equal(res.line, undefined);
assert.equal(res.column, undefined);
assert.strictEqual(res.path, 'C:\\foo\\bar');
assert.strictEqual(res.line, undefined);
assert.strictEqual(res.column, undefined);
res = extpath.parseLineAndColumnAware('C:\\foo\\bar:33');
assert.equal(res.path, 'C:\\foo\\bar');
assert.equal(res.line, 33);
assert.equal(res.column, 1);
assert.strictEqual(res.path, 'C:\\foo\\bar');
assert.strictEqual(res.line, 33);
assert.strictEqual(res.column, 1);
res = extpath.parseLineAndColumnAware('C:\\foo\\bar:33:34');
assert.equal(res.path, 'C:\\foo\\bar');
assert.equal(res.line, 33);
assert.equal(res.column, 34);
assert.strictEqual(res.path, 'C:\\foo\\bar');
assert.strictEqual(res.line, 33);
assert.strictEqual(res.column, 34);
res = extpath.parseLineAndColumnAware('/foo/bar:abb');
assert.equal(res.path, '/foo/bar:abb');
assert.equal(res.line, undefined);
assert.equal(res.column, undefined);
assert.strictEqual(res.path, '/foo/bar:abb');
assert.strictEqual(res.line, undefined);
assert.strictEqual(res.column, undefined);
});
});

View File

@@ -3,13 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as filters from 'vs/base/common/filters';
import { data } from './filters.perf.data';
import { data } from 'vs/base/test/common/filters.perf.data';
const patterns = ['cci', 'ida', 'pos', 'CCI', 'enbled', 'callback', 'gGame', 'cons', 'zyx', 'aBc'];
const _enablePerf = false;
function perfSuite(name: string, callback: (this: Mocha.ISuiteCallbackContext) => void) {
function perfSuite(name: string, callback: (this: Mocha.Suite) => void) {
if (_enablePerf) {
suite(name, callback);
}
@@ -17,6 +17,9 @@ function perfSuite(name: string, callback: (this: Mocha.ISuiteCallbackContext) =
perfSuite('Performance - fuzzyMatch', function () {
// suiteSetup(() => console.profile());
// suiteTeardown(() => console.profileEnd());
console.log(`Matching ${data.length} items against ${patterns.length} patterns (${data.length * patterns.length} operations) `);
function perfTest(name: string, match: filters.FuzzyScorer) {

View File

@@ -3,13 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore, IMatch, fuzzyScoreGraceful, fuzzyScoreGracefulAggressive, FuzzyScorer, createMatches } from 'vs/base/common/filters';
import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore, IMatch, fuzzyScoreGraceful, fuzzyScoreGracefulAggressive, FuzzyScorer, createMatches, anyScore } from 'vs/base/common/filters';
function filterOk(filter: IFilter, word: string, wordToMatchAgainst: string, highlights?: { start: number; end: number; }[]) {
let r = filter(word, wordToMatchAgainst);
assert(r, `${word} didn't match ${wordToMatchAgainst}`);
if (highlights) {
assert.deepEqual(r, highlights);
assert.deepStrictEqual(r, highlights);
}
}
@@ -233,7 +233,7 @@ suite('Filters', () => {
pos = match.end;
}
actualWord += word.substring(pos);
assert.equal(actualWord, decoratedWord);
assert.strictEqual(actualWord, decoratedWord);
}
}
@@ -285,7 +285,7 @@ suite('Filters', () => {
assertMatches('LLLL', 'SVisualLoggerLogsList', undefined, fuzzyScore);
assertMatches('TEdit', 'TextEdit', '^Text^E^d^i^t', fuzzyScore);
assertMatches('TEdit', 'TextEditor', '^Text^E^d^i^tor', fuzzyScore);
assertMatches('TEdit', 'Textedit', '^T^exte^d^i^t', fuzzyScore);
assertMatches('TEdit', 'Textedit', '^Text^e^d^i^t', fuzzyScore);
assertMatches('TEdit', 'text_edit', '^text_^e^d^i^t', fuzzyScore);
assertMatches('TEditDit', 'TextEditorDecorationType', '^Text^E^d^i^tor^Decorat^ion^Type', fuzzyScore);
assertMatches('TEdit', 'TextEditorDecorationType', '^Text^E^d^i^torDecorationType', fuzzyScore);
@@ -442,7 +442,7 @@ suite('Filters', () => {
}
}
}
assert.equal(topIdx, expected, `${pattern} -> actual=${words[topIdx]} <> expected=${words[expected]}`);
assert.strictEqual(topIdx, expected, `${pattern} -> actual=${words[topIdx]} <> expected=${words[expected]}`);
}
test('topScore - fuzzyScore', function () {
@@ -521,6 +521,12 @@ suite('Filters', () => {
'ffffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_^f^o^o',
fuzzyScore
);
assertMatches(
'Aoo',
'Affffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_foo',
'^Affffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_f^o^o',
fuzzyScore
);
assertMatches(
'foo',
'Gffffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_foo',
@@ -534,8 +540,19 @@ suite('Filters', () => {
assert.ok(Boolean(match));
});
test('Wrong highlight after emoji #113404', function () {
assertMatches('di', '✨div classname=""></div>', '✨^d^iv classname=""></div>', fuzzyScore);
assertMatches('di', 'adiv classname=""></div>', 'adiv classname=""></^d^iv>', fuzzyScore);
});
test('Suggestion is not highlighted #85826', function () {
assertMatches('SemanticTokens', 'SemanticTokensEdits', '^S^e^m^a^n^t^i^c^T^o^k^e^n^sEdits', fuzzyScore);
assertMatches('SemanticTokens', 'SemanticTokensEdits', '^S^e^m^a^n^t^i^c^T^o^k^e^n^sEdits', fuzzyScoreGracefulAggressive);
});
test('IntelliSense completion not correctly highlighting text in front of cursor #115250', function () {
assertMatches('lo', 'log', '^l^og', fuzzyScore);
assertMatches('.lo', 'log', '^l^og', anyScore);
assertMatches('.', 'log', 'log', anyScore);
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -63,10 +63,12 @@ suite('Glob', () => {
function assertGlobMatch(pattern: string | glob.IRelativePattern, input: string) {
assert(glob.match(pattern, input), `${pattern} should match ${input}`);
assert(glob.match(pattern, nativeSep(input)), `${pattern} should match ${nativeSep(input)}`);
}
function assertNoGlobMatch(pattern: string | glob.IRelativePattern, input: string) {
assert(!glob.match(pattern, input), `${pattern} should not match ${input}`);
assert(!glob.match(pattern, nativeSep(input)), `${pattern} should not match ${nativeSep(input)}`);
}
test('simple', () => {
@@ -538,9 +540,13 @@ suite('Glob', () => {
});
test('full path', function () {
let p = 'testing/this/foo.txt';
assertGlobMatch('testing/this/foo.txt', 'testing/this/foo.txt');
// assertGlobMatch('testing/this/foo.txt', 'testing\\this\\foo.txt');
});
assert(glob.match(p, nativeSep('testing/this/foo.txt')));
test('ending path', function () {
assertGlobMatch('**/testing/this/foo.txt', 'some/path/testing/this/foo.txt');
// assertGlobMatch('**/testing/this/foo.txt', 'some\\path\\testing\\this\\foo.txt');
});
test('prefix agnostic', function () {

View File

@@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------------------------
* 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 { IMatch } from 'vs/base/common/filters';
import { matchesFuzzyIconAware, parseLabelWithIcons, IParsedLabelWithIcons, stripIcons } from 'vs/base/common/iconLabels';
export interface IIconFilter {
// Returns null if word doesn't match.
(query: string, target: IParsedLabelWithIcons): IMatch[] | null;
}
function filterOk(filter: IIconFilter, word: string, target: IParsedLabelWithIcons, highlights?: { start: number; end: number; }[]) {
let r = filter(word, target);
assert(r);
if (highlights) {
assert.deepEqual(r, highlights);
}
}
suite('Icon Labels', () => {
test('matchesFuzzyIconAware', () => {
// Camel Case
filterOk(matchesFuzzyIconAware, 'ccr', parseLabelWithIcons('$(codicon)CamelCaseRocks$(codicon)'), [
{ start: 10, end: 11 },
{ start: 15, end: 16 },
{ start: 19, end: 20 }
]);
filterOk(matchesFuzzyIconAware, 'ccr', parseLabelWithIcons('$(codicon) CamelCaseRocks $(codicon)'), [
{ start: 11, end: 12 },
{ start: 16, end: 17 },
{ start: 20, end: 21 }
]);
filterOk(matchesFuzzyIconAware, 'iut', parseLabelWithIcons('$(codicon) Indent $(octico) Using $(octic) Tpaces'), [
{ start: 11, end: 12 },
{ start: 28, end: 29 },
{ start: 43, end: 44 },
]);
// Prefix
filterOk(matchesFuzzyIconAware, 'using', parseLabelWithIcons('$(codicon) Indent Using Spaces'), [
{ start: 18, end: 23 },
]);
// Broken Codicon
filterOk(matchesFuzzyIconAware, 'codicon', parseLabelWithIcons('This $(codicon Indent Using Spaces'), [
{ start: 7, end: 14 },
]);
filterOk(matchesFuzzyIconAware, 'indent', parseLabelWithIcons('This $codicon Indent Using Spaces'), [
{ start: 14, end: 20 },
]);
// Testing #59343
filterOk(matchesFuzzyIconAware, 'unt', parseLabelWithIcons('$(primitive-dot) $(file-text) Untitled-1'), [
{ start: 30, end: 33 },
]);
});
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');
});
});

View File

@@ -10,7 +10,7 @@ import { OperatingSystem } from 'vs/base/common/platform';
suite('keyCodes', () => {
function testBinaryEncoding(expected: Keybinding | null, k: number, OS: OperatingSystem): void {
assert.deepEqual(createKeybinding(k, OS), expected);
assert.deepStrictEqual(createKeybinding(k, OS), expected);
}
test('MAC binary encoding', () => {

View File

@@ -8,106 +8,98 @@ import * as labels from 'vs/base/common/labels';
import * as platform from 'vs/base/common/platform';
suite('Labels', () => {
test('shorten - windows', () => {
if (!platform.isWindows) {
assert.ok(true);
return;
}
(!platform.isWindows ? test.skip : test)('shorten - windows', () => {
// nothing to shorten
assert.deepEqual(labels.shorten(['a']), ['a']);
assert.deepEqual(labels.shorten(['a', 'b']), ['a', 'b']);
assert.deepEqual(labels.shorten(['a', 'b', 'c']), ['a', 'b', 'c']);
assert.deepStrictEqual(labels.shorten(['a']), ['a']);
assert.deepStrictEqual(labels.shorten(['a', 'b']), ['a', 'b']);
assert.deepStrictEqual(labels.shorten(['a', 'b', 'c']), ['a', 'b', 'c']);
// completely different paths
assert.deepEqual(labels.shorten(['a\\b', 'c\\d', 'e\\f']), ['…\\b', '…\\d', '…\\f']);
assert.deepStrictEqual(labels.shorten(['a\\b', 'c\\d', 'e\\f']), ['…\\b', '…\\d', '…\\f']);
// same beginning
assert.deepEqual(labels.shorten(['a', 'a\\b']), ['a', '…\\b']);
assert.deepEqual(labels.shorten(['a\\b', 'a\\b\\c']), ['…\\b', '…\\c']);
assert.deepEqual(labels.shorten(['a', 'a\\b', 'a\\b\\c']), ['a', '…\\b', '…\\c']);
assert.deepEqual(labels.shorten(['x:\\a\\b', 'x:\\a\\c']), ['x:\\…\\b', 'x:\\…\\c']);
assert.deepEqual(labels.shorten(['\\\\a\\b', '\\\\a\\c']), ['\\\\a\\b', '\\\\a\\c']);
assert.deepStrictEqual(labels.shorten(['a', 'a\\b']), ['a', '…\\b']);
assert.deepStrictEqual(labels.shorten(['a\\b', 'a\\b\\c']), ['…\\b', '…\\c']);
assert.deepStrictEqual(labels.shorten(['a', 'a\\b', 'a\\b\\c']), ['a', '…\\b', '…\\c']);
assert.deepStrictEqual(labels.shorten(['x:\\a\\b', 'x:\\a\\c']), ['x:\\…\\b', 'x:\\…\\c']);
assert.deepStrictEqual(labels.shorten(['\\\\a\\b', '\\\\a\\c']), ['\\\\a\\b', '\\\\a\\c']);
// same ending
assert.deepEqual(labels.shorten(['a', 'b\\a']), ['a', 'b\\…']);
assert.deepEqual(labels.shorten(['a\\b\\c', 'd\\b\\c']), ['a\\…', 'd\\…']);
assert.deepEqual(labels.shorten(['a\\b\\c\\d', 'f\\b\\c\\d']), ['a\\…', 'f\\…']);
assert.deepEqual(labels.shorten(['d\\e\\a\\b\\c', 'd\\b\\c']), ['…\\a\\…', 'd\\b\\…']);
assert.deepEqual(labels.shorten(['a\\b\\c\\d', 'a\\f\\b\\c\\d']), ['a\\b\\…', '…\\f\\…']);
assert.deepEqual(labels.shorten(['a\\b\\a', 'b\\b\\a']), ['a\\b\\…', 'b\\b\\…']);
assert.deepEqual(labels.shorten(['d\\f\\a\\b\\c', 'h\\d\\b\\c']), ['…\\a\\…', 'h\\…']);
assert.deepEqual(labels.shorten(['a\\b\\c', 'x:\\0\\a\\b\\c']), ['a\\b\\c', 'x:\\0\\…']);
assert.deepEqual(labels.shorten(['x:\\a\\b\\c', 'x:\\0\\a\\b\\c']), ['x:\\a\\…', 'x:\\0\\…']);
assert.deepEqual(labels.shorten(['x:\\a\\b', 'y:\\a\\b']), ['x:\\…', 'y:\\…']);
assert.deepEqual(labels.shorten(['x:\\a', 'x:\\c']), ['x:\\a', 'x:\\c']);
assert.deepEqual(labels.shorten(['x:\\a\\b', 'y:\\x\\a\\b']), ['x:\\…', 'y:\\…']);
assert.deepEqual(labels.shorten(['\\\\x\\b', '\\\\y\\b']), ['\\\\x\\…', '\\\\y\\…']);
assert.deepEqual(labels.shorten(['\\\\x\\a', '\\\\x\\b']), ['\\\\x\\a', '\\\\x\\b']);
assert.deepStrictEqual(labels.shorten(['a', 'b\\a']), ['a', 'b\\…']);
assert.deepStrictEqual(labels.shorten(['a\\b\\c', 'd\\b\\c']), ['a\\…', 'd\\…']);
assert.deepStrictEqual(labels.shorten(['a\\b\\c\\d', 'f\\b\\c\\d']), ['a\\…', 'f\\…']);
assert.deepStrictEqual(labels.shorten(['d\\e\\a\\b\\c', 'd\\b\\c']), ['…\\a\\…', 'd\\b\\…']);
assert.deepStrictEqual(labels.shorten(['a\\b\\c\\d', 'a\\f\\b\\c\\d']), ['a\\b\\…', '…\\f\\…']);
assert.deepStrictEqual(labels.shorten(['a\\b\\a', 'b\\b\\a']), ['a\\b\\…', 'b\\b\\…']);
assert.deepStrictEqual(labels.shorten(['d\\f\\a\\b\\c', 'h\\d\\b\\c']), ['…\\a\\…', 'h\\…']);
assert.deepStrictEqual(labels.shorten(['a\\b\\c', 'x:\\0\\a\\b\\c']), ['a\\b\\c', 'x:\\0\\…']);
assert.deepStrictEqual(labels.shorten(['x:\\a\\b\\c', 'x:\\0\\a\\b\\c']), ['x:\\a\\…', 'x:\\0\\…']);
assert.deepStrictEqual(labels.shorten(['x:\\a\\b', 'y:\\a\\b']), ['x:\\…', 'y:\\…']);
assert.deepStrictEqual(labels.shorten(['x:\\a', 'x:\\c']), ['x:\\a', 'x:\\c']);
assert.deepStrictEqual(labels.shorten(['x:\\a\\b', 'y:\\x\\a\\b']), ['x:\\…', 'y:\\…']);
assert.deepStrictEqual(labels.shorten(['\\\\x\\b', '\\\\y\\b']), ['\\\\x\\…', '\\\\y\\…']);
assert.deepStrictEqual(labels.shorten(['\\\\x\\a', '\\\\x\\b']), ['\\\\x\\a', '\\\\x\\b']);
// same name ending
assert.deepEqual(labels.shorten(['a\\b', 'a\\c', 'a\\e-b']), ['…\\b', '…\\c', '…\\e-b']);
assert.deepStrictEqual(labels.shorten(['a\\b', 'a\\c', 'a\\e-b']), ['…\\b', '…\\c', '…\\e-b']);
// same in the middle
assert.deepEqual(labels.shorten(['a\\b\\c', 'd\\b\\e']), ['…\\c', '…\\e']);
assert.deepStrictEqual(labels.shorten(['a\\b\\c', 'd\\b\\e']), ['…\\c', '…\\e']);
// case-sensetive
assert.deepEqual(labels.shorten(['a\\b\\c', 'd\\b\\C']), ['…\\c', '…\\C']);
assert.deepStrictEqual(labels.shorten(['a\\b\\c', 'd\\b\\C']), ['…\\c', '…\\C']);
// empty or null
assert.deepEqual(labels.shorten(['', null!]), ['.\\', null]);
assert.deepStrictEqual(labels.shorten(['', null!]), ['.\\', null]);
assert.deepEqual(labels.shorten(['a', 'a\\b', 'a\\b\\c', 'd\\b\\c', 'd\\b']), ['a', 'a\\b', 'a\\b\\c', 'd\\b\\c', 'd\\b']);
assert.deepEqual(labels.shorten(['a', 'a\\b', 'b']), ['a', 'a\\b', 'b']);
assert.deepEqual(labels.shorten(['', 'a', 'b', 'b\\c', 'a\\c']), ['.\\', 'a', 'b', 'b\\c', 'a\\c']);
assert.deepEqual(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\\…']);
assert.deepStrictEqual(labels.shorten(['a', 'a\\b', 'a\\b\\c', 'd\\b\\c', 'd\\b']), ['a', 'a\\b', 'a\\b\\c', 'd\\b\\c', 'd\\b']);
assert.deepStrictEqual(labels.shorten(['a', 'a\\b', 'b']), ['a', 'a\\b', 'b']);
assert.deepStrictEqual(labels.shorten(['', 'a', 'b', 'b\\c', 'a\\c']), ['.\\', 'a', 'b', 'b\\c', 'a\\c']);
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\\…']);
});
test('shorten - not windows', () => {
if (platform.isWindows) {
assert.ok(true);
return;
}
(platform.isWindows ? test.skip : test)('shorten - not windows', () => {
// nothing to shorten
assert.deepEqual(labels.shorten(['a']), ['a']);
assert.deepEqual(labels.shorten(['a', 'b']), ['a', 'b']);
assert.deepEqual(labels.shorten(['a', 'b', 'c']), ['a', 'b', 'c']);
assert.deepStrictEqual(labels.shorten(['a']), ['a']);
assert.deepStrictEqual(labels.shorten(['a', 'b']), ['a', 'b']);
assert.deepStrictEqual(labels.shorten(['a', 'b', 'c']), ['a', 'b', 'c']);
// completely different paths
assert.deepEqual(labels.shorten(['a/b', 'c/d', 'e/f']), ['…/b', '…/d', '…/f']);
assert.deepStrictEqual(labels.shorten(['a/b', 'c/d', 'e/f']), ['…/b', '…/d', '…/f']);
// same beginning
assert.deepEqual(labels.shorten(['a', 'a/b']), ['a', '…/b']);
assert.deepEqual(labels.shorten(['a/b', 'a/b/c']), ['…/b', '…/c']);
assert.deepEqual(labels.shorten(['a', 'a/b', 'a/b/c']), ['a', '…/b', '…/c']);
assert.deepEqual(labels.shorten(['/a/b', '/a/c']), ['/a/b', '/a/c']);
assert.deepStrictEqual(labels.shorten(['a', 'a/b']), ['a', '…/b']);
assert.deepStrictEqual(labels.shorten(['a/b', 'a/b/c']), ['…/b', '…/c']);
assert.deepStrictEqual(labels.shorten(['a', 'a/b', 'a/b/c']), ['a', '…/b', '…/c']);
assert.deepStrictEqual(labels.shorten(['/a/b', '/a/c']), ['/a/b', '/a/c']);
// same ending
assert.deepEqual(labels.shorten(['a', 'b/a']), ['a', 'b/…']);
assert.deepEqual(labels.shorten(['a/b/c', 'd/b/c']), ['a/…', 'd/…']);
assert.deepEqual(labels.shorten(['a/b/c/d', 'f/b/c/d']), ['a/…', 'f/…']);
assert.deepEqual(labels.shorten(['d/e/a/b/c', 'd/b/c']), ['…/a/…', 'd/b/…']);
assert.deepEqual(labels.shorten(['a/b/c/d', 'a/f/b/c/d']), ['a/b/…', '…/f/…']);
assert.deepEqual(labels.shorten(['a/b/a', 'b/b/a']), ['a/b/…', 'b/b/…']);
assert.deepEqual(labels.shorten(['d/f/a/b/c', 'h/d/b/c']), ['…/a/…', 'h/…']);
assert.deepEqual(labels.shorten(['/x/b', '/y/b']), ['/x/…', '/y/…']);
assert.deepStrictEqual(labels.shorten(['a', 'b/a']), ['a', 'b/…']);
assert.deepStrictEqual(labels.shorten(['a/b/c', 'd/b/c']), ['a/…', 'd/…']);
assert.deepStrictEqual(labels.shorten(['a/b/c/d', 'f/b/c/d']), ['a/…', 'f/…']);
assert.deepStrictEqual(labels.shorten(['d/e/a/b/c', 'd/b/c']), ['…/a/…', 'd/b/…']);
assert.deepStrictEqual(labels.shorten(['a/b/c/d', 'a/f/b/c/d']), ['a/b/…', '…/f/…']);
assert.deepStrictEqual(labels.shorten(['a/b/a', 'b/b/a']), ['a/b/…', 'b/b/…']);
assert.deepStrictEqual(labels.shorten(['d/f/a/b/c', 'h/d/b/c']), ['…/a/…', 'h/…']);
assert.deepStrictEqual(labels.shorten(['/x/b', '/y/b']), ['/x/…', '/y/…']);
// same name ending
assert.deepEqual(labels.shorten(['a/b', 'a/c', 'a/e-b']), ['…/b', '…/c', '…/e-b']);
assert.deepStrictEqual(labels.shorten(['a/b', 'a/c', 'a/e-b']), ['…/b', '…/c', '…/e-b']);
// same in the middle
assert.deepEqual(labels.shorten(['a/b/c', 'd/b/e']), ['…/c', '…/e']);
assert.deepStrictEqual(labels.shorten(['a/b/c', 'd/b/e']), ['…/c', '…/e']);
// case-sensitive
assert.deepEqual(labels.shorten(['a/b/c', 'd/b/C']), ['…/c', '…/C']);
assert.deepStrictEqual(labels.shorten(['a/b/c', 'd/b/C']), ['…/c', '…/C']);
// empty or null
assert.deepEqual(labels.shorten(['', null!]), ['./', null]);
assert.deepStrictEqual(labels.shorten(['', null!]), ['./', null]);
assert.deepEqual(labels.shorten(['a', 'a/b', 'a/b/c', 'd/b/c', 'd/b']), ['a', 'a/b', 'a/b/c', 'd/b/c', 'd/b']);
assert.deepEqual(labels.shorten(['a', 'a/b', 'b']), ['a', 'a/b', 'b']);
assert.deepEqual(labels.shorten(['', 'a', 'b', 'b/c', 'a/c']), ['./', 'a', 'b', 'b/c', 'a/c']);
assert.deepStrictEqual(labels.shorten(['a', 'a/b', 'a/b/c', 'd/b/c', 'd/b']), ['a', 'a/b', 'a/b/c', 'd/b/c', 'd/b']);
assert.deepStrictEqual(labels.shorten(['a', 'a/b', 'b']), ['a', 'a/b', 'b']);
assert.deepStrictEqual(labels.shorten(['', 'a', 'b', 'b/c', 'a/c']), ['./', 'a', 'b', 'b/c', 'a/c']);
});
test('template', () => {
@@ -142,41 +134,32 @@ 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');
});
test('getBaseLabel - unix', () => {
if (platform.isWindows) {
assert.ok(true);
return;
}
assert.equal(labels.getBaseLabel('/some/folder/file.txt'), 'file.txt');
assert.equal(labels.getBaseLabel('/some/folder'), 'folder');
assert.equal(labels.getBaseLabel('/'), '/');
(platform.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('/'), '/');
});
test('getBaseLabel - windows', () => {
if (!platform.isWindows) {
assert.ok(true);
return;
}
assert.equal(labels.getBaseLabel('c:'), 'C:');
assert.equal(labels.getBaseLabel('c:\\'), 'C:');
assert.equal(labels.getBaseLabel('c:\\some\\folder\\file.txt'), 'file.txt');
assert.equal(labels.getBaseLabel('c:\\some\\folder'), 'folder');
(!platform.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');
assert.strictEqual(labels.getBaseLabel('c:\\some\\folder'), 'folder');
assert.strictEqual(labels.getBaseLabel('c:\\some\\f:older'), 'f:older'); // https://github.com/microsoft/vscode-remote-release/issues/4227
});
test('mnemonicButtonLabel', () => {
assert.equal(labels.mnemonicButtonLabel('Hello World'), 'Hello World');
assert.equal(labels.mnemonicButtonLabel(''), '');
assert.strictEqual(labels.mnemonicButtonLabel('Hello World'), 'Hello World');
assert.strictEqual(labels.mnemonicButtonLabel(''), '');
if (platform.isWindows) {
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello && World');
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do &not Save && Continue');
assert.strictEqual(labels.mnemonicButtonLabel('Hello & World'), 'Hello && World');
assert.strictEqual(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do &not Save && Continue');
} else if (platform.isMacintosh) {
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do not Save & Continue');
assert.strictEqual(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.strictEqual(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do not Save & Continue');
} else {
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do _not Save & Continue');
assert.strictEqual(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.strictEqual(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do _not Save & Continue');
}
});
});
});

View File

@@ -11,19 +11,19 @@ suite('LinkedList', function () {
function assertElements<E>(list: LinkedList<E>, ...elements: E[]) {
// check size
assert.equal(list.size, elements.length);
assert.strictEqual(list.size, elements.length);
// assert toArray
assert.deepEqual(Array.from(list), elements);
assert.deepStrictEqual(Array.from(list), elements);
// assert Symbol.iterator (1)
assert.deepEqual([...list], elements);
assert.deepStrictEqual([...list], elements);
// assert Symbol.iterator (2)
for (const item of list) {
assert.equal(item, elements.shift());
assert.strictEqual(item, elements.shift());
}
assert.equal(elements.length, 0);
assert.strictEqual(elements.length, 0);
}
test('Push/Iter', () => {
@@ -123,14 +123,14 @@ suite('LinkedList', function () {
assertElements(list, 'a', 'b');
let a = list.shift();
assert.equal(a, 'a');
assert.strictEqual(a, 'a');
assertElements(list, 'b');
list.unshift('a');
assertElements(list, 'a', 'b');
let b = list.pop();
assert.equal(b, 'b');
assert.strictEqual(b, 'b');
assertElements(list, 'a');
});

View File

@@ -16,8 +16,8 @@ suite('Map', () => {
map.set('bk', 'bv');
assert.deepStrictEqual([...map.keys()], ['ak', 'bk']);
assert.deepStrictEqual([...map.values()], ['av', 'bv']);
assert.equal(map.first, 'av');
assert.equal(map.last, 'bv');
assert.strictEqual(map.first, 'av');
assert.strictEqual(map.last, 'bv');
});
test('LinkedMap - Touch Old one', () => {
@@ -77,7 +77,7 @@ suite('Map', () => {
test('LinkedMap - basics', function () {
const map = new LinkedMap<string, any>();
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
map.set('1', 1);
map.set('2', '2');
@@ -89,23 +89,23 @@ suite('Map', () => {
const date = Date.now();
map.set('5', date);
assert.equal(map.size, 5);
assert.equal(map.get('1'), 1);
assert.equal(map.get('2'), '2');
assert.equal(map.get('3'), true);
assert.equal(map.get('4'), obj);
assert.equal(map.get('5'), date);
assert.strictEqual(map.size, 5);
assert.strictEqual(map.get('1'), 1);
assert.strictEqual(map.get('2'), '2');
assert.strictEqual(map.get('3'), true);
assert.strictEqual(map.get('4'), obj);
assert.strictEqual(map.get('5'), date);
assert.ok(!map.get('6'));
map.delete('6');
assert.equal(map.size, 5);
assert.equal(map.delete('1'), true);
assert.equal(map.delete('2'), true);
assert.equal(map.delete('3'), true);
assert.equal(map.delete('4'), true);
assert.equal(map.delete('5'), true);
assert.strictEqual(map.size, 5);
assert.strictEqual(map.delete('1'), true);
assert.strictEqual(map.delete('2'), true);
assert.strictEqual(map.delete('3'), true);
assert.strictEqual(map.delete('4'), true);
assert.strictEqual(map.delete('5'), true);
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
assert.ok(!map.get('5'));
assert.ok(!map.get('4'));
assert.ok(!map.get('3'));
@@ -117,13 +117,13 @@ suite('Map', () => {
map.set('3', true);
assert.ok(map.has('1'));
assert.equal(map.get('1'), 1);
assert.equal(map.get('2'), '2');
assert.equal(map.get('3'), true);
assert.strictEqual(map.get('1'), 1);
assert.strictEqual(map.get('2'), '2');
assert.strictEqual(map.get('3'), true);
map.clear();
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
assert.ok(!map.get('1'));
assert.ok(!map.get('2'));
assert.ok(!map.get('3'));
@@ -231,7 +231,7 @@ suite('Map', () => {
for (let i = 11; i <= 20; i++) {
cache.set(i, i);
}
assert.deepEqual(cache.size, 15);
assert.deepStrictEqual(cache.size, 15);
let values: number[] = [];
for (let i = 6; i <= 20; i++) {
values.push(cache.get(i)!);
@@ -269,14 +269,14 @@ suite('Map', () => {
let i = 0;
map.forEach((value, key) => {
if (i === 0) {
assert.equal(key, 'ak');
assert.equal(value, 'av');
assert.strictEqual(key, 'ak');
assert.strictEqual(value, 'av');
} else if (i === 1) {
assert.equal(key, 'bk');
assert.equal(value, 'bv');
assert.strictEqual(key, 'bk');
assert.strictEqual(value, 'bv');
} else if (i === 2) {
assert.equal(key, 'ck');
assert.equal(value, 'cv');
assert.strictEqual(key, 'ck');
assert.strictEqual(value, 'cv');
}
i++;
});
@@ -285,44 +285,44 @@ suite('Map', () => {
test('LinkedMap - delete Head and Tail', function () {
const map = new LinkedMap<string, number>();
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
map.set('1', 1);
assert.equal(map.size, 1);
assert.strictEqual(map.size, 1);
map.delete('1');
assert.equal(map.get('1'), undefined);
assert.equal(map.size, 0);
assert.equal([...map.keys()].length, 0);
assert.strictEqual(map.get('1'), undefined);
assert.strictEqual(map.size, 0);
assert.strictEqual([...map.keys()].length, 0);
});
test('LinkedMap - delete Head', function () {
const map = new LinkedMap<string, number>();
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
map.set('1', 1);
map.set('2', 2);
assert.equal(map.size, 2);
assert.strictEqual(map.size, 2);
map.delete('1');
assert.equal(map.get('2'), 2);
assert.equal(map.size, 1);
assert.equal([...map.keys()].length, 1);
assert.equal([...map.keys()][0], 2);
assert.strictEqual(map.get('2'), 2);
assert.strictEqual(map.size, 1);
assert.strictEqual([...map.keys()].length, 1);
assert.strictEqual([...map.keys()][0], '2');
});
test('LinkedMap - delete Tail', function () {
const map = new LinkedMap<string, number>();
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
map.set('1', 1);
map.set('2', 2);
assert.equal(map.size, 2);
assert.strictEqual(map.size, 2);
map.delete('2');
assert.equal(map.get('1'), 1);
assert.equal(map.size, 1);
assert.equal([...map.keys()].length, 1);
assert.equal([...map.keys()][0], 1);
assert.strictEqual(map.get('1'), 1);
assert.strictEqual(map.size, 1);
assert.strictEqual([...map.keys()].length, 1);
assert.strictEqual([...map.keys()][0], '1');
});
@@ -330,100 +330,100 @@ suite('Map', () => {
const iter = new PathIterator();
iter.reset('file:///usr/bin/file.txt');
assert.equal(iter.value(), 'file:');
assert.equal(iter.hasNext(), true);
assert.equal(iter.cmp('file:'), 0);
assert.strictEqual(iter.value(), 'file:');
assert.strictEqual(iter.hasNext(), true);
assert.strictEqual(iter.cmp('file:'), 0);
assert.ok(iter.cmp('a') < 0);
assert.ok(iter.cmp('aile:') < 0);
assert.ok(iter.cmp('z') > 0);
assert.ok(iter.cmp('zile:') > 0);
iter.next();
assert.equal(iter.value(), 'usr');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'usr');
assert.strictEqual(iter.hasNext(), true);
iter.next();
assert.equal(iter.value(), 'bin');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'bin');
assert.strictEqual(iter.hasNext(), true);
iter.next();
assert.equal(iter.value(), 'file.txt');
assert.equal(iter.hasNext(), false);
assert.strictEqual(iter.value(), 'file.txt');
assert.strictEqual(iter.hasNext(), false);
iter.next();
assert.equal(iter.value(), '');
assert.equal(iter.hasNext(), false);
assert.strictEqual(iter.value(), '');
assert.strictEqual(iter.hasNext(), false);
iter.next();
assert.equal(iter.value(), '');
assert.equal(iter.hasNext(), false);
assert.strictEqual(iter.value(), '');
assert.strictEqual(iter.hasNext(), false);
//
iter.reset('/foo/bar/');
assert.equal(iter.value(), 'foo');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'foo');
assert.strictEqual(iter.hasNext(), true);
iter.next();
assert.equal(iter.value(), 'bar');
assert.equal(iter.hasNext(), false);
assert.strictEqual(iter.value(), 'bar');
assert.strictEqual(iter.hasNext(), false);
});
test('URIIterator', function () {
const iter = new UriIterator(() => false);
iter.reset(URI.parse('file:///usr/bin/file.txt'));
assert.equal(iter.value(), 'file');
// assert.equal(iter.cmp('FILE'), 0);
assert.equal(iter.cmp('file'), 0);
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'file');
// assert.strictEqual(iter.cmp('FILE'), 0);
assert.strictEqual(iter.cmp('file'), 0);
assert.strictEqual(iter.hasNext(), true);
iter.next();
assert.equal(iter.value(), 'usr');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'usr');
assert.strictEqual(iter.hasNext(), true);
iter.next();
assert.equal(iter.value(), 'bin');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'bin');
assert.strictEqual(iter.hasNext(), true);
iter.next();
assert.equal(iter.value(), 'file.txt');
assert.equal(iter.hasNext(), false);
assert.strictEqual(iter.value(), 'file.txt');
assert.strictEqual(iter.hasNext(), false);
iter.reset(URI.parse('file://share/usr/bin/file.txt?foo'));
// scheme
assert.equal(iter.value(), 'file');
// assert.equal(iter.cmp('FILE'), 0);
assert.equal(iter.cmp('file'), 0);
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'file');
// assert.strictEqual(iter.cmp('FILE'), 0);
assert.strictEqual(iter.cmp('file'), 0);
assert.strictEqual(iter.hasNext(), true);
iter.next();
// authority
assert.equal(iter.value(), 'share');
assert.equal(iter.cmp('SHARe'), 0);
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'share');
assert.strictEqual(iter.cmp('SHARe'), 0);
assert.strictEqual(iter.hasNext(), true);
iter.next();
// path
assert.equal(iter.value(), 'usr');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'usr');
assert.strictEqual(iter.hasNext(), true);
iter.next();
// path
assert.equal(iter.value(), 'bin');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'bin');
assert.strictEqual(iter.hasNext(), true);
iter.next();
// path
assert.equal(iter.value(), 'file.txt');
assert.equal(iter.hasNext(), true);
assert.strictEqual(iter.value(), 'file.txt');
assert.strictEqual(iter.hasNext(), true);
iter.next();
// query
assert.equal(iter.value(), 'foo');
assert.equal(iter.cmp('z') > 0, true);
assert.equal(iter.cmp('a') < 0, true);
assert.equal(iter.hasNext(), false);
assert.strictEqual(iter.value(), 'foo');
assert.strictEqual(iter.cmp('z') > 0, true);
assert.strictEqual(iter.cmp('a') < 0, true);
assert.strictEqual(iter.hasNext(), false);
});
function assertTernarySearchTree<E>(trie: TernarySearchTree<string, E>, ...elements: [string, E][]) {
@@ -432,24 +432,24 @@ suite('Map', () => {
map.set(key, value);
}
map.forEach((value, key) => {
assert.equal(trie.get(key), value);
assert.strictEqual(trie.get(key), value);
});
// forEach
let forEachCount = 0;
trie.forEach((element, key) => {
assert.equal(element, map.get(key));
assert.strictEqual(element, map.get(key));
forEachCount++;
});
assert.equal(map.size, forEachCount);
assert.strictEqual(map.size, forEachCount);
// iterator
let iterCount = 0;
for (let [key, value] of trie) {
assert.equal(value, map.get(key));
assert.strictEqual(value, map.get(key));
iterCount++;
}
assert.equal(map.size, iterCount);
assert.strictEqual(map.size, iterCount);
}
test('TernarySearchTree - set', function () {
@@ -493,13 +493,13 @@ suite('Map', () => {
trie.set('foobar', 2);
trie.set('foobaz', 3);
assert.equal(trie.findSubstr('f'), undefined);
assert.equal(trie.findSubstr('z'), undefined);
assert.equal(trie.findSubstr('foo'), 1);
assert.equal(trie.findSubstr('fooö'), 1);
assert.equal(trie.findSubstr('fooba'), 1);
assert.equal(trie.findSubstr('foobarr'), 2);
assert.equal(trie.findSubstr('foobazrr'), 3);
assert.strictEqual(trie.findSubstr('f'), undefined);
assert.strictEqual(trie.findSubstr('z'), undefined);
assert.strictEqual(trie.findSubstr('foo'), 1);
assert.strictEqual(trie.findSubstr('fooö'), 1);
assert.strictEqual(trie.findSubstr('fooba'), 1);
assert.strictEqual(trie.findSubstr('foobarr'), 2);
assert.strictEqual(trie.findSubstr('foobazrr'), 3);
});
test('TernarySearchTree - basics', function () {
@@ -509,27 +509,27 @@ suite('Map', () => {
trie.set('bar', 2);
trie.set('foobar', 3);
assert.equal(trie.get('foo'), 1);
assert.equal(trie.get('bar'), 2);
assert.equal(trie.get('foobar'), 3);
assert.equal(trie.get('foobaz'), undefined);
assert.equal(trie.get('foobarr'), undefined);
assert.strictEqual(trie.get('foo'), 1);
assert.strictEqual(trie.get('bar'), 2);
assert.strictEqual(trie.get('foobar'), 3);
assert.strictEqual(trie.get('foobaz'), undefined);
assert.strictEqual(trie.get('foobarr'), undefined);
assert.equal(trie.findSubstr('fo'), undefined);
assert.equal(trie.findSubstr('foo'), 1);
assert.equal(trie.findSubstr('foooo'), 1);
assert.strictEqual(trie.findSubstr('fo'), undefined);
assert.strictEqual(trie.findSubstr('foo'), 1);
assert.strictEqual(trie.findSubstr('foooo'), 1);
trie.delete('foobar');
trie.delete('bar');
assert.equal(trie.get('foobar'), undefined);
assert.equal(trie.get('bar'), undefined);
assert.strictEqual(trie.get('foobar'), undefined);
assert.strictEqual(trie.get('bar'), undefined);
trie.set('foobar', 17);
trie.set('barr', 18);
assert.equal(trie.get('foobar'), 17);
assert.equal(trie.get('barr'), 18);
assert.equal(trie.get('bar'), undefined);
assert.strictEqual(trie.get('foobar'), 17);
assert.strictEqual(trie.get('barr'), 18);
assert.strictEqual(trie.get('bar'), undefined);
});
test('TernarySearchTree - delete & cleanup', function () {
@@ -576,20 +576,20 @@ suite('Map', () => {
trie.set('/user/foo', 2);
trie.set('/user/foo/flip/flop', 3);
assert.equal(trie.get('/user/foo/bar'), 1);
assert.equal(trie.get('/user/foo'), 2);
assert.equal(trie.get('/user//foo'), 2);
assert.equal(trie.get('/user\\foo'), 2);
assert.equal(trie.get('/user/foo/flip/flop'), 3);
assert.strictEqual(trie.get('/user/foo/bar'), 1);
assert.strictEqual(trie.get('/user/foo'), 2);
assert.strictEqual(trie.get('/user//foo'), 2);
assert.strictEqual(trie.get('/user\\foo'), 2);
assert.strictEqual(trie.get('/user/foo/flip/flop'), 3);
assert.equal(trie.findSubstr('/user/bar'), undefined);
assert.equal(trie.findSubstr('/user/foo'), 2);
assert.equal(trie.findSubstr('\\user\\foo'), 2);
assert.equal(trie.findSubstr('/user//foo'), 2);
assert.equal(trie.findSubstr('/user/foo/ba'), 2);
assert.equal(trie.findSubstr('/user/foo/far/boo'), 2);
assert.equal(trie.findSubstr('/user/foo/bar'), 1);
assert.equal(trie.findSubstr('/user/foo/bar/far/boo'), 1);
assert.strictEqual(trie.findSubstr('/user/bar'), undefined);
assert.strictEqual(trie.findSubstr('/user/foo'), 2);
assert.strictEqual(trie.findSubstr('\\user\\foo'), 2);
assert.strictEqual(trie.findSubstr('/user//foo'), 2);
assert.strictEqual(trie.findSubstr('/user/foo/ba'), 2);
assert.strictEqual(trie.findSubstr('/user/foo/far/boo'), 2);
assert.strictEqual(trie.findSubstr('/user/foo/bar'), 1);
assert.strictEqual(trie.findSubstr('/user/foo/bar/far/boo'), 1);
});
test('TernarySearchTree (PathSegments) - lookup', function () {
@@ -599,11 +599,11 @@ suite('Map', () => {
map.set('/user/foo', 2);
map.set('/user/foo/flip/flop', 3);
assert.equal(map.get('/foo'), undefined);
assert.equal(map.get('/user'), undefined);
assert.equal(map.get('/user/foo'), 2);
assert.equal(map.get('/user/foo/bar'), 1);
assert.equal(map.get('/user/foo/bar/boo'), undefined);
assert.strictEqual(map.get('/foo'), undefined);
assert.strictEqual(map.get('/user'), undefined);
assert.strictEqual(map.get('/user/foo'), 2);
assert.strictEqual(map.get('/user/foo/bar'), 1);
assert.strictEqual(map.get('/user/foo/bar/boo'), undefined);
});
test('TernarySearchTree (PathSegments) - superstr', function () {
@@ -618,31 +618,31 @@ suite('Map', () => {
let iter = map.findSuperstr('/user');
item = iter!.next();
assert.equal(item.value[1], 2);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 2);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value[1], 1);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 1);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value[1], 3);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 3);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value, undefined);
assert.equal(item.done, true);
assert.strictEqual(item.value, undefined);
assert.strictEqual(item.done, true);
iter = map.findSuperstr('/usr');
item = iter!.next();
assert.equal(item.value[1], 4);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 4);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value, undefined);
assert.equal(item.done, true);
assert.strictEqual(item.value, undefined);
assert.strictEqual(item.done, true);
assert.equal(map.findSuperstr('/not'), undefined);
assert.equal(map.findSuperstr('/us'), undefined);
assert.equal(map.findSuperstr('/usrr'), undefined);
assert.equal(map.findSuperstr('/userr'), undefined);
assert.strictEqual(map.findSuperstr('/not'), undefined);
assert.strictEqual(map.findSuperstr('/us'), undefined);
assert.strictEqual(map.findSuperstr('/usrr'), undefined);
assert.strictEqual(map.findSuperstr('/userr'), undefined);
});
@@ -688,16 +688,16 @@ suite('Map', () => {
trie.set(URI.file('/user/foo'), 2);
trie.set(URI.file('/user/foo/flip/flop'), 3);
assert.equal(trie.get(URI.file('/user/foo/bar')), 1);
assert.equal(trie.get(URI.file('/user/foo')), 2);
assert.equal(trie.get(URI.file('/user/foo/flip/flop')), 3);
assert.strictEqual(trie.get(URI.file('/user/foo/bar')), 1);
assert.strictEqual(trie.get(URI.file('/user/foo')), 2);
assert.strictEqual(trie.get(URI.file('/user/foo/flip/flop')), 3);
assert.equal(trie.findSubstr(URI.file('/user/bar')), undefined);
assert.equal(trie.findSubstr(URI.file('/user/foo')), 2);
assert.equal(trie.findSubstr(URI.file('/user/foo/ba')), 2);
assert.equal(trie.findSubstr(URI.file('/user/foo/far/boo')), 2);
assert.equal(trie.findSubstr(URI.file('/user/foo/bar')), 1);
assert.equal(trie.findSubstr(URI.file('/user/foo/bar/far/boo')), 1);
assert.strictEqual(trie.findSubstr(URI.file('/user/bar')), undefined);
assert.strictEqual(trie.findSubstr(URI.file('/user/foo')), 2);
assert.strictEqual(trie.findSubstr(URI.file('/user/foo/ba')), 2);
assert.strictEqual(trie.findSubstr(URI.file('/user/foo/far/boo')), 2);
assert.strictEqual(trie.findSubstr(URI.file('/user/foo/bar')), 1);
assert.strictEqual(trie.findSubstr(URI.file('/user/foo/bar/far/boo')), 1);
});
test('TernarySearchTree (URI) - lookup', function () {
@@ -708,23 +708,23 @@ suite('Map', () => {
map.set(URI.parse('http://foo.bar/user/foo?QUERY'), 3);
map.set(URI.parse('http://foo.bar/user/foo/flip/flop'), 3);
assert.equal(map.get(URI.parse('http://foo.bar/foo')), undefined);
assert.equal(map.get(URI.parse('http://foo.bar/user')), undefined);
assert.equal(map.get(URI.parse('http://foo.bar/user/foo/bar')), 1);
assert.equal(map.get(URI.parse('http://foo.bar/user/foo?query')), 2);
assert.equal(map.get(URI.parse('http://foo.bar/user/foo?Query')), undefined);
assert.equal(map.get(URI.parse('http://foo.bar/user/foo?QUERY')), 3);
assert.equal(map.get(URI.parse('http://foo.bar/user/foo/bar/boo')), undefined);
assert.strictEqual(map.get(URI.parse('http://foo.bar/foo')), undefined);
assert.strictEqual(map.get(URI.parse('http://foo.bar/user')), undefined);
assert.strictEqual(map.get(URI.parse('http://foo.bar/user/foo/bar')), 1);
assert.strictEqual(map.get(URI.parse('http://foo.bar/user/foo?query')), 2);
assert.strictEqual(map.get(URI.parse('http://foo.bar/user/foo?Query')), undefined);
assert.strictEqual(map.get(URI.parse('http://foo.bar/user/foo?QUERY')), 3);
assert.strictEqual(map.get(URI.parse('http://foo.bar/user/foo/bar/boo')), undefined);
});
test('TernarySearchTree (URI) - lookup, casing', function () {
const map = new TernarySearchTree<URI, number>(new UriIterator(uri => /^https?$/.test(uri.scheme)));
map.set(URI.parse('http://foo.bar/user/foo/bar'), 1);
assert.equal(map.get(URI.parse('http://foo.bar/USER/foo/bar')), 1);
assert.strictEqual(map.get(URI.parse('http://foo.bar/USER/foo/bar')), 1);
map.set(URI.parse('foo://foo.bar/user/foo/bar'), 1);
assert.equal(map.get(URI.parse('foo://foo.bar/USER/foo/bar')), undefined);
assert.strictEqual(map.get(URI.parse('foo://foo.bar/USER/foo/bar')), undefined);
});
test('TernarySearchTree (URI) - superstr', function () {
@@ -739,48 +739,48 @@ suite('Map', () => {
let iter = map.findSuperstr(URI.file('/user'))!;
item = iter.next();
assert.equal(item.value[1], 2);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 2);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value[1], 1);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 1);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value[1], 3);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 3);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value, undefined);
assert.equal(item.done, true);
assert.strictEqual(item.value, undefined);
assert.strictEqual(item.done, true);
iter = map.findSuperstr(URI.file('/usr'))!;
item = iter.next();
assert.equal(item.value[1], 4);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 4);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value, undefined);
assert.equal(item.done, true);
assert.strictEqual(item.value, undefined);
assert.strictEqual(item.done, true);
iter = map.findSuperstr(URI.file('/'))!;
item = iter.next();
assert.equal(item.value[1], 2);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 2);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value[1], 1);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 1);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value[1], 3);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 3);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value[1], 4);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 4);
assert.strictEqual(item.done, false);
item = iter.next();
assert.equal(item.value, undefined);
assert.equal(item.done, true);
assert.strictEqual(item.value, undefined);
assert.strictEqual(item.done, true);
assert.equal(map.findSuperstr(URI.file('/not')), undefined);
assert.equal(map.findSuperstr(URI.file('/us')), undefined);
assert.equal(map.findSuperstr(URI.file('/usrr')), undefined);
assert.equal(map.findSuperstr(URI.file('/userr')), undefined);
assert.strictEqual(map.findSuperstr(URI.file('/not')), undefined);
assert.strictEqual(map.findSuperstr(URI.file('/us')), undefined);
assert.strictEqual(map.findSuperstr(URI.file('/usrr')), undefined);
assert.strictEqual(map.findSuperstr(URI.file('/userr')), undefined);
});
test('TernarySearchTree (ConfigKeySegments) - basics', function () {
@@ -790,16 +790,16 @@ suite('Map', () => {
trie.set('config.foo', 2);
trie.set('config.foo.flip.flop', 3);
assert.equal(trie.get('config.foo.bar'), 1);
assert.equal(trie.get('config.foo'), 2);
assert.equal(trie.get('config.foo.flip.flop'), 3);
assert.strictEqual(trie.get('config.foo.bar'), 1);
assert.strictEqual(trie.get('config.foo'), 2);
assert.strictEqual(trie.get('config.foo.flip.flop'), 3);
assert.equal(trie.findSubstr('config.bar'), undefined);
assert.equal(trie.findSubstr('config.foo'), 2);
assert.equal(trie.findSubstr('config.foo.ba'), 2);
assert.equal(trie.findSubstr('config.foo.far.boo'), 2);
assert.equal(trie.findSubstr('config.foo.bar'), 1);
assert.equal(trie.findSubstr('config.foo.bar.far.boo'), 1);
assert.strictEqual(trie.findSubstr('config.bar'), undefined);
assert.strictEqual(trie.findSubstr('config.foo'), 2);
assert.strictEqual(trie.findSubstr('config.foo.ba'), 2);
assert.strictEqual(trie.findSubstr('config.foo.far.boo'), 2);
assert.strictEqual(trie.findSubstr('config.foo.bar'), 1);
assert.strictEqual(trie.findSubstr('config.foo.bar.far.boo'), 1);
});
test('TernarySearchTree (ConfigKeySegments) - lookup', function () {
@@ -809,11 +809,11 @@ suite('Map', () => {
map.set('config.foo', 2);
map.set('config.foo.flip.flop', 3);
assert.equal(map.get('foo'), undefined);
assert.equal(map.get('config'), undefined);
assert.equal(map.get('config.foo'), 2);
assert.equal(map.get('config.foo.bar'), 1);
assert.equal(map.get('config.foo.bar.boo'), undefined);
assert.strictEqual(map.get('foo'), undefined);
assert.strictEqual(map.get('config'), undefined);
assert.strictEqual(map.get('config.foo'), 2);
assert.strictEqual(map.get('config.foo.bar'), 1);
assert.strictEqual(map.get('config.foo.bar.boo'), undefined);
});
test('TernarySearchTree (ConfigKeySegments) - superstr', function () {
@@ -828,21 +828,21 @@ suite('Map', () => {
let iter = map.findSuperstr('config');
item = iter!.next();
assert.equal(item.value[1], 2);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 2);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value[1], 1);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 1);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value[1], 3);
assert.equal(item.done, false);
assert.strictEqual(item.value[1], 3);
assert.strictEqual(item.done, false);
item = iter!.next();
assert.equal(item.value, undefined);
assert.equal(item.done, true);
assert.strictEqual(item.value, undefined);
assert.strictEqual(item.done, true);
assert.equal(map.findSuperstr('foo'), undefined);
assert.equal(map.findSuperstr('config.foo.no'), undefined);
assert.equal(map.findSuperstr('config.foop'), undefined);
assert.strictEqual(map.findSuperstr('foo'), undefined);
assert.strictEqual(map.findSuperstr('config.foo.no'), undefined);
assert.strictEqual(map.findSuperstr('config.foop'), undefined);
});
@@ -891,7 +891,7 @@ suite('Map', () => {
const resource5 = URI.parse('some://5');
const resource6 = URI.parse('some://6');
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
let res = map.set(resource1, 1);
assert.ok(res === map);
@@ -899,13 +899,13 @@ suite('Map', () => {
map.set(resource3, true);
const values = [...map.values()];
assert.equal(values[0], 1);
assert.equal(values[1], '2');
assert.equal(values[2], true);
assert.strictEqual(values[0], 1);
assert.strictEqual(values[1], '2');
assert.strictEqual(values[2], true);
let counter = 0;
map.forEach((value, key, mapObj) => {
assert.equal(value, values[counter++]);
assert.strictEqual(value, values[counter++]);
assert.ok(URI.isUri(key));
assert.ok(map === mapObj);
});
@@ -916,23 +916,23 @@ suite('Map', () => {
const date = Date.now();
map.set(resource5, date);
assert.equal(map.size, 5);
assert.equal(map.get(resource1), 1);
assert.equal(map.get(resource2), '2');
assert.equal(map.get(resource3), true);
assert.equal(map.get(resource4), obj);
assert.equal(map.get(resource5), date);
assert.strictEqual(map.size, 5);
assert.strictEqual(map.get(resource1), 1);
assert.strictEqual(map.get(resource2), '2');
assert.strictEqual(map.get(resource3), true);
assert.strictEqual(map.get(resource4), obj);
assert.strictEqual(map.get(resource5), date);
assert.ok(!map.get(resource6));
map.delete(resource6);
assert.equal(map.size, 5);
assert.strictEqual(map.size, 5);
assert.ok(map.delete(resource1));
assert.ok(map.delete(resource2));
assert.ok(map.delete(resource3));
assert.ok(map.delete(resource4));
assert.ok(map.delete(resource5));
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
assert.ok(!map.get(resource5));
assert.ok(!map.get(resource4));
assert.ok(!map.get(resource3));
@@ -944,13 +944,13 @@ suite('Map', () => {
map.set(resource3, true);
assert.ok(map.has(resource1));
assert.equal(map.get(resource1), 1);
assert.equal(map.get(resource2), '2');
assert.equal(map.get(resource3), true);
assert.strictEqual(map.get(resource1), 1);
assert.strictEqual(map.get(resource2), '2');
assert.strictEqual(map.get(resource3), true);
map.clear();
assert.equal(map.size, 0);
assert.strictEqual(map.size, 0);
assert.ok(!map.get(resource1));
assert.ok(!map.get(resource2));
assert.ok(!map.get(resource3));
@@ -971,16 +971,16 @@ suite('Map', () => {
const fileAUpper = URI.parse('file://SOME/FILEA');
map.set(fileA, 'true');
assert.equal(map.get(fileA), 'true');
assert.strictEqual(map.get(fileA), 'true');
assert.ok(!map.get(fileAUpper));
assert.ok(!map.get(fileB));
map.set(fileAUpper, 'false');
assert.equal(map.get(fileAUpper), 'false');
assert.strictEqual(map.get(fileAUpper), 'false');
assert.equal(map.get(fileA), 'true');
assert.strictEqual(map.get(fileA), 'true');
const windowsFile = URI.file('c:\\test with %25\\c#code');
const uncFile = URI.file('\\\\shäres\\path\\c#\\plugin.json');
@@ -988,8 +988,8 @@ suite('Map', () => {
map.set(windowsFile, 'true');
map.set(uncFile, 'true');
assert.equal(map.get(windowsFile), 'true');
assert.equal(map.get(uncFile), 'true');
assert.strictEqual(map.get(windowsFile), 'true');
assert.strictEqual(map.get(uncFile), 'true');
});
test('ResourceMap - files (ignorecase)', function () {
@@ -1000,16 +1000,16 @@ suite('Map', () => {
const fileAUpper = URI.parse('file://SOME/FILEA');
map.set(fileA, 'true');
assert.equal(map.get(fileA), 'true');
assert.strictEqual(map.get(fileA), 'true');
assert.equal(map.get(fileAUpper), 'true');
assert.strictEqual(map.get(fileAUpper), 'true');
assert.ok(!map.get(fileB));
map.set(fileAUpper, 'false');
assert.equal(map.get(fileAUpper), 'false');
assert.strictEqual(map.get(fileAUpper), 'false');
assert.equal(map.get(fileA), 'false');
assert.strictEqual(map.get(fileA), 'false');
const windowsFile = URI.file('c:\\test with %25\\c#code');
const uncFile = URI.file('\\\\shäres\\path\\c#\\plugin.json');
@@ -1017,7 +1017,7 @@ suite('Map', () => {
map.set(windowsFile, 'true');
map.set(uncFile, 'true');
assert.equal(map.get(windowsFile), 'true');
assert.equal(map.get(uncFile), 'true');
assert.strictEqual(map.get(windowsFile), 'true');
assert.strictEqual(map.get(uncFile), 'true');
});
});

View File

@@ -11,13 +11,13 @@ suite('MarkdownString', () => {
test('Escape leading whitespace', function () {
const mds = new MarkdownString();
mds.appendText('Hello\n Not a code block');
assert.equal(mds.value, 'Hello\n\n&nbsp;&nbsp;&nbsp;&nbsp;Not&nbsp;a&nbsp;code&nbsp;block');
assert.strictEqual(mds.value, 'Hello\n\n&nbsp;&nbsp;&nbsp;&nbsp;Not&nbsp;a&nbsp;code&nbsp;block');
});
test('MarkdownString.appendText doesn\'t escape quote #109040', function () {
const mds = new MarkdownString();
mds.appendText('> Text\n>More');
assert.equal(mds.value, '\\>&nbsp;Text\n\n\\>More');
assert.strictEqual(mds.value, '\\>&nbsp;Text\n\n\\>More');
});
test('appendText', () => {
@@ -25,7 +25,7 @@ suite('MarkdownString', () => {
const mds = new MarkdownString();
mds.appendText('# foo\n*bar*');
assert.equal(mds.value, '\\#&nbsp;foo\n\n\\*bar\\*');
assert.strictEqual(mds.value, '\\#&nbsp;foo\n\n\\*bar\\*');
});
suite('ThemeIcons', () => {
@@ -36,21 +36,21 @@ suite('MarkdownString', () => {
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
mds.appendText('$(zap) $(not a theme icon) $(add)');
assert.equal(mds.value, '\\\\$\\(zap\\)&nbsp;$\\(not&nbsp;a&nbsp;theme&nbsp;icon\\)&nbsp;\\\\$\\(add\\)');
assert.strictEqual(mds.value, '\\\\$\\(zap\\)&nbsp;$\\(not&nbsp;a&nbsp;theme&nbsp;icon\\)&nbsp;\\\\$\\(add\\)');
});
test('appendMarkdown', () => {
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
mds.appendMarkdown('$(zap) $(not a theme icon) $(add)');
assert.equal(mds.value, '$(zap) $(not a theme icon) $(add)');
assert.strictEqual(mds.value, '$(zap) $(not a theme icon) $(add)');
});
test('appendMarkdown with escaped icon', () => {
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
mds.appendMarkdown('\\$(zap) $(not a theme icon) $(add)');
assert.equal(mds.value, '\\$(zap) $(not a theme icon) $(add)');
assert.strictEqual(mds.value, '\\$(zap) $(not a theme icon) $(add)');
});
});
@@ -61,21 +61,21 @@ suite('MarkdownString', () => {
const mds = new MarkdownString(undefined, { supportThemeIcons: false });
mds.appendText('$(zap) $(not a theme icon) $(add)');
assert.equal(mds.value, '$\\(zap\\)&nbsp;$\\(not&nbsp;a&nbsp;theme&nbsp;icon\\)&nbsp;$\\(add\\)');
assert.strictEqual(mds.value, '$\\(zap\\)&nbsp;$\\(not&nbsp;a&nbsp;theme&nbsp;icon\\)&nbsp;$\\(add\\)');
});
test('appendMarkdown', () => {
const mds = new MarkdownString(undefined, { supportThemeIcons: false });
mds.appendMarkdown('$(zap) $(not a theme icon) $(add)');
assert.equal(mds.value, '$(zap) $(not a theme icon) $(add)');
assert.strictEqual(mds.value, '$(zap) $(not a theme icon) $(add)');
});
test('appendMarkdown with escaped icon', () => {
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
mds.appendMarkdown('\\$(zap) $(not a theme icon) $(add)');
assert.equal(mds.value, '\\$(zap) $(not a theme icon) $(add)');
assert.strictEqual(mds.value, '\\$(zap) $(not a theme icon) $(add)');
});
});

View File

@@ -11,38 +11,38 @@ suite('Mime', () => {
test('Dynamically Register Text Mime', () => {
let guess = guessMimeTypes(URI.file('foo.monaco'));
assert.deepEqual(guess, ['application/unknown']);
assert.deepStrictEqual(guess, ['application/unknown']);
registerTextMime({ id: 'monaco', extension: '.monaco', mime: 'text/monaco' });
guess = guessMimeTypes(URI.file('foo.monaco'));
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
guess = guessMimeTypes(URI.file('.monaco'));
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
registerTextMime({ id: 'codefile', filename: 'Codefile', mime: 'text/code' });
guess = guessMimeTypes(URI.file('Codefile'));
assert.deepEqual(guess, ['text/code', 'text/plain']);
assert.deepStrictEqual(guess, ['text/code', 'text/plain']);
guess = guessMimeTypes(URI.file('foo.Codefile'));
assert.deepEqual(guess, ['application/unknown']);
assert.deepStrictEqual(guess, ['application/unknown']);
registerTextMime({ id: 'docker', filepattern: 'Docker*', mime: 'text/docker' });
guess = guessMimeTypes(URI.file('Docker-debug'));
assert.deepEqual(guess, ['text/docker', 'text/plain']);
assert.deepStrictEqual(guess, ['text/docker', 'text/plain']);
guess = guessMimeTypes(URI.file('docker-PROD'));
assert.deepEqual(guess, ['text/docker', 'text/plain']);
assert.deepStrictEqual(guess, ['text/docker', 'text/plain']);
registerTextMime({ id: 'niceregex', mime: 'text/nice-regex', firstline: /RegexesAreNice/ });
guess = guessMimeTypes(URI.file('Randomfile.noregistration'), 'RegexesAreNice');
assert.deepEqual(guess, ['text/nice-regex', 'text/plain']);
assert.deepStrictEqual(guess, ['text/nice-regex', 'text/plain']);
guess = guessMimeTypes(URI.file('Randomfile.noregistration'), 'RegexesAreNotNice');
assert.deepEqual(guess, ['application/unknown']);
assert.deepStrictEqual(guess, ['application/unknown']);
guess = guessMimeTypes(URI.file('Codefile'), 'RegexesAreNice');
assert.deepEqual(guess, ['text/code', 'text/plain']);
assert.deepStrictEqual(guess, ['text/code', 'text/plain']);
});
test('Mimes Priority', () => {
@@ -50,36 +50,36 @@ suite('Mime', () => {
registerTextMime({ id: 'foobar', mime: 'text/foobar', firstline: /foobar/ });
let guess = guessMimeTypes(URI.file('foo.monaco'));
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
guess = guessMimeTypes(URI.file('foo.monaco'), 'foobar');
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
registerTextMime({ id: 'docker', filename: 'dockerfile', mime: 'text/winner' });
registerTextMime({ id: 'docker', filepattern: 'dockerfile*', mime: 'text/looser' });
guess = guessMimeTypes(URI.file('dockerfile'));
assert.deepEqual(guess, ['text/winner', 'text/plain']);
assert.deepStrictEqual(guess, ['text/winner', 'text/plain']);
registerTextMime({ id: 'azure-looser', mime: 'text/azure-looser', firstline: /azure/ });
registerTextMime({ id: 'azure-winner', mime: 'text/azure-winner', firstline: /azure/ });
guess = guessMimeTypes(URI.file('azure'), 'azure');
assert.deepEqual(guess, ['text/azure-winner', 'text/plain']);
assert.deepStrictEqual(guess, ['text/azure-winner', 'text/plain']);
});
test('Specificity priority 1', () => {
registerTextMime({ id: 'monaco2', extension: '.monaco2', mime: 'text/monaco2' });
registerTextMime({ id: 'monaco2', filename: 'specific.monaco2', mime: 'text/specific-monaco2' });
assert.deepEqual(guessMimeTypes(URI.file('specific.monaco2')), ['text/specific-monaco2', 'text/plain']);
assert.deepEqual(guessMimeTypes(URI.file('foo.monaco2')), ['text/monaco2', 'text/plain']);
assert.deepStrictEqual(guessMimeTypes(URI.file('specific.monaco2')), ['text/specific-monaco2', 'text/plain']);
assert.deepStrictEqual(guessMimeTypes(URI.file('foo.monaco2')), ['text/monaco2', 'text/plain']);
});
test('Specificity priority 2', () => {
registerTextMime({ id: 'monaco3', filename: 'specific.monaco3', mime: 'text/specific-monaco3' });
registerTextMime({ id: 'monaco3', extension: '.monaco3', mime: 'text/monaco3' });
assert.deepEqual(guessMimeTypes(URI.file('specific.monaco3')), ['text/specific-monaco3', 'text/plain']);
assert.deepEqual(guessMimeTypes(URI.file('foo.monaco3')), ['text/monaco3', 'text/plain']);
assert.deepStrictEqual(guessMimeTypes(URI.file('specific.monaco3')), ['text/specific-monaco3', 'text/plain']);
assert.deepStrictEqual(guessMimeTypes(URI.file('foo.monaco3')), ['text/monaco3', 'text/plain']);
});
test('Mimes Priority - Longest Extension wins', () => {
@@ -88,13 +88,13 @@ suite('Mime', () => {
registerTextMime({ id: 'monaco', extension: '.monaco.xml.build', mime: 'text/monaco-xml-build' });
let guess = guessMimeTypes(URI.file('foo.monaco'));
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
guess = guessMimeTypes(URI.file('foo.monaco.xml'));
assert.deepEqual(guess, ['text/monaco-xml', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco-xml', 'text/plain']);
guess = guessMimeTypes(URI.file('foo.monaco.xml.build'));
assert.deepEqual(guess, ['text/monaco-xml-build', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco-xml-build', 'text/plain']);
});
test('Mimes Priority - User configured wins', () => {
@@ -102,7 +102,7 @@ suite('Mime', () => {
registerTextMime({ id: 'monaco', extension: '.monaco.xml', mime: 'text/monaco-xml' });
let guess = guessMimeTypes(URI.file('foo.monaco.xnl'));
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
});
test('Mimes Priority - Pattern matches on path if specified', () => {
@@ -110,7 +110,7 @@ suite('Mime', () => {
registerTextMime({ id: 'other', filepattern: '*ot.other.xml', mime: 'text/other' });
let guess = guessMimeTypes(URI.file('/some/path/dot.monaco.xml'));
assert.deepEqual(guess, ['text/monaco', 'text/plain']);
assert.deepStrictEqual(guess, ['text/monaco', 'text/plain']);
});
test('Mimes Priority - Last registered mime wins', () => {
@@ -118,12 +118,12 @@ suite('Mime', () => {
registerTextMime({ id: 'other', filepattern: '**/dot.monaco.xml', mime: 'text/other' });
let guess = guessMimeTypes(URI.file('/some/path/dot.monaco.xml'));
assert.deepEqual(guess, ['text/other', 'text/plain']);
assert.deepStrictEqual(guess, ['text/other', 'text/plain']);
});
test('Data URIs', () => {
registerTextMime({ id: 'data', extension: '.data', mime: 'text/data' });
assert.deepEqual(guessMimeTypes(URI.parse(`data:;label:something.data;description:data,`)), ['text/data', 'text/plain']);
assert.deepStrictEqual(guessMimeTypes(URI.parse(`data:;label:something.data;description:data,`)), ['text/data', 'text/plain']);
});
});

View File

@@ -7,10 +7,10 @@ import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { isEqual } from 'vs/base/common/resources';
import { isElectronSandboxed } from 'vs/base/common/platform';
import { isPreferringBrowserCodeLoad } from 'vs/base/common/platform';
suite('network', () => {
const enableTest = isElectronSandboxed;
const enableTest = isPreferringBrowserCodeLoad;
(!enableTest ? test.skip : test)('FileAccess: URI (native)', () => {

View File

@@ -101,7 +101,6 @@ suite('PagedModel', () => {
test('preemptive cancellation works', async function () {
const pager = new TestPager(() => {
assert(false);
return Promise.resolve([]);
});
const model = new PagedModel(pager);

View File

@@ -29,10 +29,11 @@
import * as assert from 'assert';
import * as path from 'vs/base/common/path';
import { isWindows } from 'vs/base/common/platform';
import { isWeb, isWindows } from 'vs/base/common/platform';
import * as process from 'vs/base/common/process';
suite('Paths (Node Implementation)', () => {
const __filename = 'path.test.js';
test('join', () => {
const failures = [] as string[];
const backslashRE = /\\/g;
@@ -175,9 +176,6 @@ suite('Paths (Node Implementation)', () => {
});
test('dirname', () => {
assert.strictEqual(path.dirname(path.normalize(__filename)).substr(-9),
isWindows ? 'test\\node' : 'test/node');
assert.strictEqual(path.posix.dirname('/a/b/'), '/a');
assert.strictEqual(path.posix.dirname('/a/b'), '/a');
assert.strictEqual(path.posix.dirname('/a'), '/');
@@ -362,7 +360,7 @@ suite('Paths (Node Implementation)', () => {
assert.equal(path.extname('far.boo/boo'), '');
});
test('resolve', () => {
(isWeb && isWindows ? test.skip : test)('resolve', () => { // TODO@sbatten fails on windows & browser only
const failures = [] as string[];
const slashRE = /\//g;
const backslashRE = /\\/g;

View File

@@ -15,7 +15,6 @@ suite('Processes', () => {
ELECTRON_NO_ASAR: 'x',
ELECTRON_NO_ATTACH_CONSOLE: 'x',
ELECTRON_RUN_AS_NODE: 'x',
GOOGLE_API_KEY: 'x',
VSCODE_CLI: 'x',
VSCODE_DEV: 'x',
VSCODE_IPC_HOOK: 'x',

View File

@@ -22,10 +22,10 @@ suite('Resources', () => {
];
let distinct = distinctParents(resources, r => r);
assert.equal(distinct.length, 3);
assert.equal(distinct[0].toString(), resources[0].toString());
assert.equal(distinct[1].toString(), resources[1].toString());
assert.equal(distinct[2].toString(), resources[2].toString());
assert.strictEqual(distinct.length, 3);
assert.strictEqual(distinct[0].toString(), resources[0].toString());
assert.strictEqual(distinct[1].toString(), resources[1].toString());
assert.strictEqual(distinct[2].toString(), resources[2].toString());
// Parent / Child
resources = [
@@ -37,144 +37,144 @@ suite('Resources', () => {
];
distinct = distinctParents(resources, r => r);
assert.equal(distinct.length, 3);
assert.equal(distinct[0].toString(), resources[0].toString());
assert.equal(distinct[1].toString(), resources[3].toString());
assert.equal(distinct[2].toString(), resources[4].toString());
assert.strictEqual(distinct.length, 3);
assert.strictEqual(distinct[0].toString(), resources[0].toString());
assert.strictEqual(distinct[1].toString(), resources[3].toString());
assert.strictEqual(distinct[2].toString(), resources[4].toString());
});
test('dirname', () => {
if (isWindows) {
assert.equal(dirname(URI.file('c:\\some\\file\\test.txt')).toString(), 'file:///c%3A/some/file');
assert.equal(dirname(URI.file('c:\\some\\file')).toString(), 'file:///c%3A/some');
assert.equal(dirname(URI.file('c:\\some\\file\\')).toString(), 'file:///c%3A/some');
assert.equal(dirname(URI.file('c:\\some')).toString(), 'file:///c%3A/');
assert.equal(dirname(URI.file('C:\\some')).toString(), 'file:///c%3A/');
assert.equal(dirname(URI.file('c:\\')).toString(), 'file:///c%3A/');
assert.strictEqual(dirname(URI.file('c:\\some\\file\\test.txt')).toString(), 'file:///c%3A/some/file');
assert.strictEqual(dirname(URI.file('c:\\some\\file')).toString(), 'file:///c%3A/some');
assert.strictEqual(dirname(URI.file('c:\\some\\file\\')).toString(), 'file:///c%3A/some');
assert.strictEqual(dirname(URI.file('c:\\some')).toString(), 'file:///c%3A/');
assert.strictEqual(dirname(URI.file('C:\\some')).toString(), 'file:///c%3A/');
assert.strictEqual(dirname(URI.file('c:\\')).toString(), 'file:///c%3A/');
} else {
assert.equal(dirname(URI.file('/some/file/test.txt')).toString(), 'file:///some/file');
assert.equal(dirname(URI.file('/some/file/')).toString(), 'file:///some');
assert.equal(dirname(URI.file('/some/file')).toString(), 'file:///some');
assert.strictEqual(dirname(URI.file('/some/file/test.txt')).toString(), 'file:///some/file');
assert.strictEqual(dirname(URI.file('/some/file/')).toString(), 'file:///some');
assert.strictEqual(dirname(URI.file('/some/file')).toString(), 'file:///some');
}
assert.equal(dirname(URI.parse('foo://a/some/file/test.txt')).toString(), 'foo://a/some/file');
assert.equal(dirname(URI.parse('foo://a/some/file/')).toString(), 'foo://a/some');
assert.equal(dirname(URI.parse('foo://a/some/file')).toString(), 'foo://a/some');
assert.equal(dirname(URI.parse('foo://a/some')).toString(), 'foo://a/');
assert.equal(dirname(URI.parse('foo://a/')).toString(), 'foo://a/');
assert.equal(dirname(URI.parse('foo://a')).toString(), 'foo://a');
assert.strictEqual(dirname(URI.parse('foo://a/some/file/test.txt')).toString(), 'foo://a/some/file');
assert.strictEqual(dirname(URI.parse('foo://a/some/file/')).toString(), 'foo://a/some');
assert.strictEqual(dirname(URI.parse('foo://a/some/file')).toString(), 'foo://a/some');
assert.strictEqual(dirname(URI.parse('foo://a/some')).toString(), 'foo://a/');
assert.strictEqual(dirname(URI.parse('foo://a/')).toString(), 'foo://a/');
assert.strictEqual(dirname(URI.parse('foo://a')).toString(), 'foo://a');
// does not explode (https://github.com/microsoft/vscode/issues/41987)
dirname(URI.from({ scheme: 'file', authority: '/users/someone/portal.h' }));
assert.equal(dirname(URI.parse('foo://a/b/c?q')).toString(), 'foo://a/b?q');
assert.strictEqual(dirname(URI.parse('foo://a/b/c?q')).toString(), 'foo://a/b?q');
});
test('basename', () => {
if (isWindows) {
assert.equal(basename(URI.file('c:\\some\\file\\test.txt')), 'test.txt');
assert.equal(basename(URI.file('c:\\some\\file')), 'file');
assert.equal(basename(URI.file('c:\\some\\file\\')), 'file');
assert.equal(basename(URI.file('C:\\some\\file\\')), 'file');
assert.strictEqual(basename(URI.file('c:\\some\\file\\test.txt')), 'test.txt');
assert.strictEqual(basename(URI.file('c:\\some\\file')), 'file');
assert.strictEqual(basename(URI.file('c:\\some\\file\\')), 'file');
assert.strictEqual(basename(URI.file('C:\\some\\file\\')), 'file');
} else {
assert.equal(basename(URI.file('/some/file/test.txt')), 'test.txt');
assert.equal(basename(URI.file('/some/file/')), 'file');
assert.equal(basename(URI.file('/some/file')), 'file');
assert.equal(basename(URI.file('/some')), 'some');
assert.strictEqual(basename(URI.file('/some/file/test.txt')), 'test.txt');
assert.strictEqual(basename(URI.file('/some/file/')), 'file');
assert.strictEqual(basename(URI.file('/some/file')), 'file');
assert.strictEqual(basename(URI.file('/some')), 'some');
}
assert.equal(basename(URI.parse('foo://a/some/file/test.txt')), 'test.txt');
assert.equal(basename(URI.parse('foo://a/some/file/')), 'file');
assert.equal(basename(URI.parse('foo://a/some/file')), 'file');
assert.equal(basename(URI.parse('foo://a/some')), 'some');
assert.equal(basename(URI.parse('foo://a/')), '');
assert.equal(basename(URI.parse('foo://a')), '');
assert.strictEqual(basename(URI.parse('foo://a/some/file/test.txt')), 'test.txt');
assert.strictEqual(basename(URI.parse('foo://a/some/file/')), 'file');
assert.strictEqual(basename(URI.parse('foo://a/some/file')), 'file');
assert.strictEqual(basename(URI.parse('foo://a/some')), 'some');
assert.strictEqual(basename(URI.parse('foo://a/')), '');
assert.strictEqual(basename(URI.parse('foo://a')), '');
});
test('joinPath', () => {
if (isWindows) {
assert.equal(joinPath(URI.file('c:\\foo\\bar'), '/file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.equal(joinPath(URI.file('c:\\foo\\bar\\'), 'file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.equal(joinPath(URI.file('c:\\foo\\bar\\'), '/file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.equal(joinPath(URI.file('c:\\'), '/file.js').toString(), 'file:///c%3A/file.js');
assert.equal(joinPath(URI.file('c:\\'), 'bar/file.js').toString(), 'file:///c%3A/bar/file.js');
assert.equal(joinPath(URI.file('c:\\foo'), './file.js').toString(), 'file:///c%3A/foo/file.js');
assert.equal(joinPath(URI.file('c:\\foo'), '/./file.js').toString(), 'file:///c%3A/foo/file.js');
assert.equal(joinPath(URI.file('C:\\foo'), '../file.js').toString(), 'file:///c%3A/file.js');
assert.equal(joinPath(URI.file('C:\\foo\\.'), '../file.js').toString(), 'file:///c%3A/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar'), '/file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar\\'), 'file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar\\'), '/file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\'), '/file.js').toString(), 'file:///c%3A/file.js');
assert.strictEqual(joinPath(URI.file('c:\\'), 'bar/file.js').toString(), 'file:///c%3A/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo'), './file.js').toString(), 'file:///c%3A/foo/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo'), '/./file.js').toString(), 'file:///c%3A/foo/file.js');
assert.strictEqual(joinPath(URI.file('C:\\foo'), '../file.js').toString(), 'file:///c%3A/file.js');
assert.strictEqual(joinPath(URI.file('C:\\foo\\.'), '../file.js').toString(), 'file:///c%3A/file.js');
} else {
assert.equal(joinPath(URI.file('/foo/bar'), '/file.js').toString(), 'file:///foo/bar/file.js');
assert.equal(joinPath(URI.file('/foo/bar'), 'file.js').toString(), 'file:///foo/bar/file.js');
assert.equal(joinPath(URI.file('/foo/bar/'), '/file.js').toString(), 'file:///foo/bar/file.js');
assert.equal(joinPath(URI.file('/'), '/file.js').toString(), 'file:///file.js');
assert.equal(joinPath(URI.file('/foo/bar'), './file.js').toString(), 'file:///foo/bar/file.js');
assert.equal(joinPath(URI.file('/foo/bar'), '/./file.js').toString(), 'file:///foo/bar/file.js');
assert.equal(joinPath(URI.file('/foo/bar'), '../file.js').toString(), 'file:///foo/file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar'), '/file.js').toString(), 'file:///foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar'), 'file.js').toString(), 'file:///foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar/'), '/file.js').toString(), 'file:///foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('/'), '/file.js').toString(), 'file:///file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar'), './file.js').toString(), 'file:///foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar'), '/./file.js').toString(), 'file:///foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar'), '../file.js').toString(), 'file:///foo/file.js');
}
assert.equal(joinPath(URI.parse('foo://a/foo/bar')).toString(), 'foo://a/foo/bar');
assert.equal(joinPath(URI.parse('foo://a/foo/bar'), '/file.js').toString(), 'foo://a/foo/bar/file.js');
assert.equal(joinPath(URI.parse('foo://a/foo/bar'), 'file.js').toString(), 'foo://a/foo/bar/file.js');
assert.equal(joinPath(URI.parse('foo://a/foo/bar/'), '/file.js').toString(), 'foo://a/foo/bar/file.js');
assert.equal(joinPath(URI.parse('foo://a/'), '/file.js').toString(), 'foo://a/file.js');
assert.equal(joinPath(URI.parse('foo://a/foo/bar/'), './file.js').toString(), 'foo://a/foo/bar/file.js');
assert.equal(joinPath(URI.parse('foo://a/foo/bar/'), '/./file.js').toString(), 'foo://a/foo/bar/file.js');
assert.equal(joinPath(URI.parse('foo://a/foo/bar/'), '../file.js').toString(), 'foo://a/foo/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar')).toString(), 'foo://a/foo/bar');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar'), '/file.js').toString(), 'foo://a/foo/bar/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar'), 'file.js').toString(), 'foo://a/foo/bar/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar/'), '/file.js').toString(), 'foo://a/foo/bar/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/'), '/file.js').toString(), 'foo://a/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar/'), './file.js').toString(), 'foo://a/foo/bar/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar/'), '/./file.js').toString(), 'foo://a/foo/bar/file.js');
assert.strictEqual(joinPath(URI.parse('foo://a/foo/bar/'), '../file.js').toString(), 'foo://a/foo/file.js');
assert.equal(
assert.strictEqual(
joinPath(URI.from({ scheme: 'myScheme', authority: 'authority', path: '/path', query: 'query', fragment: 'fragment' }), '/file.js').toString(),
'myScheme://authority/path/file.js?query#fragment');
});
test('normalizePath', () => {
if (isWindows) {
assert.equal(normalizePath(URI.file('c:\\foo\\.\\bar')).toString(), 'file:///c%3A/foo/bar');
assert.equal(normalizePath(URI.file('c:\\foo\\.')).toString(), 'file:///c%3A/foo');
assert.equal(normalizePath(URI.file('c:\\foo\\.\\')).toString(), 'file:///c%3A/foo/');
assert.equal(normalizePath(URI.file('c:\\foo\\..')).toString(), 'file:///c%3A/');
assert.equal(normalizePath(URI.file('c:\\foo\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.equal(normalizePath(URI.file('c:\\foo\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.equal(normalizePath(URI.file('c:\\foo\\foo\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.equal(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.equal(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\some\\..\\bar')).toString(), 'file:///c%3A/foo/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.\\bar')).toString(), 'file:///c%3A/foo/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.')).toString(), 'file:///c%3A/foo');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.\\')).toString(), 'file:///c%3A/foo/');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..')).toString(), 'file:///c%3A/');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\foo\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\some\\..\\bar')).toString(), 'file:///c%3A/foo/bar');
} else {
assert.equal(normalizePath(URI.file('/foo/./bar')).toString(), 'file:///foo/bar');
assert.equal(normalizePath(URI.file('/foo/.')).toString(), 'file:///foo');
assert.equal(normalizePath(URI.file('/foo/./')).toString(), 'file:///foo/');
assert.equal(normalizePath(URI.file('/foo/..')).toString(), 'file:///');
assert.equal(normalizePath(URI.file('/foo/../bar')).toString(), 'file:///bar');
assert.equal(normalizePath(URI.file('/foo/../../bar')).toString(), 'file:///bar');
assert.equal(normalizePath(URI.file('/foo/foo/../../bar')).toString(), 'file:///bar');
assert.equal(normalizePath(URI.file('/foo/foo/./../../bar')).toString(), 'file:///bar');
assert.equal(normalizePath(URI.file('/foo/foo/./../some/../bar')).toString(), 'file:///foo/bar');
assert.equal(normalizePath(URI.file('/f')).toString(), 'file:///f');
assert.strictEqual(normalizePath(URI.file('/foo/./bar')).toString(), 'file:///foo/bar');
assert.strictEqual(normalizePath(URI.file('/foo/.')).toString(), 'file:///foo');
assert.strictEqual(normalizePath(URI.file('/foo/./')).toString(), 'file:///foo/');
assert.strictEqual(normalizePath(URI.file('/foo/..')).toString(), 'file:///');
assert.strictEqual(normalizePath(URI.file('/foo/../bar')).toString(), 'file:///bar');
assert.strictEqual(normalizePath(URI.file('/foo/../../bar')).toString(), 'file:///bar');
assert.strictEqual(normalizePath(URI.file('/foo/foo/../../bar')).toString(), 'file:///bar');
assert.strictEqual(normalizePath(URI.file('/foo/foo/./../../bar')).toString(), 'file:///bar');
assert.strictEqual(normalizePath(URI.file('/foo/foo/./../some/../bar')).toString(), 'file:///foo/bar');
assert.strictEqual(normalizePath(URI.file('/f')).toString(), 'file:///f');
}
assert.equal(normalizePath(URI.parse('foo://a/foo/./bar')).toString(), 'foo://a/foo/bar');
assert.equal(normalizePath(URI.parse('foo://a/foo/.')).toString(), 'foo://a/foo');
assert.equal(normalizePath(URI.parse('foo://a/foo/./')).toString(), 'foo://a/foo/');
assert.equal(normalizePath(URI.parse('foo://a/foo/..')).toString(), 'foo://a/');
assert.equal(normalizePath(URI.parse('foo://a/foo/../bar')).toString(), 'foo://a/bar');
assert.equal(normalizePath(URI.parse('foo://a/foo/../../bar')).toString(), 'foo://a/bar');
assert.equal(normalizePath(URI.parse('foo://a/foo/foo/../../bar')).toString(), 'foo://a/bar');
assert.equal(normalizePath(URI.parse('foo://a/foo/foo/./../../bar')).toString(), 'foo://a/bar');
assert.equal(normalizePath(URI.parse('foo://a/foo/foo/./../some/../bar')).toString(), 'foo://a/foo/bar');
assert.equal(normalizePath(URI.parse('foo://a')).toString(), 'foo://a');
assert.equal(normalizePath(URI.parse('foo://a/')).toString(), 'foo://a/');
assert.equal(normalizePath(URI.parse('foo://a/foo/./bar?q=1')).toString(), URI.parse('foo://a/foo/bar?q%3D1').toString());
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/./bar')).toString(), 'foo://a/foo/bar');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/.')).toString(), 'foo://a/foo');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/./')).toString(), 'foo://a/foo/');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/..')).toString(), 'foo://a/');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/../bar')).toString(), 'foo://a/bar');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/../../bar')).toString(), 'foo://a/bar');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/foo/../../bar')).toString(), 'foo://a/bar');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/foo/./../../bar')).toString(), 'foo://a/bar');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/foo/./../some/../bar')).toString(), 'foo://a/foo/bar');
assert.strictEqual(normalizePath(URI.parse('foo://a')).toString(), 'foo://a');
assert.strictEqual(normalizePath(URI.parse('foo://a/')).toString(), 'foo://a/');
assert.strictEqual(normalizePath(URI.parse('foo://a/foo/./bar?q=1')).toString(), URI.parse('foo://a/foo/bar?q%3D1').toString());
});
test('isAbsolute', () => {
if (isWindows) {
assert.equal(isAbsolutePath(URI.file('c:\\foo\\')), true);
assert.equal(isAbsolutePath(URI.file('C:\\foo\\')), true);
assert.equal(isAbsolutePath(URI.file('bar')), true); // URI normalizes all file URIs to be absolute
assert.strictEqual(isAbsolutePath(URI.file('c:\\foo\\')), true);
assert.strictEqual(isAbsolutePath(URI.file('C:\\foo\\')), true);
assert.strictEqual(isAbsolutePath(URI.file('bar')), true); // URI normalizes all file URIs to be absolute
} else {
assert.equal(isAbsolutePath(URI.file('/foo/bar')), true);
assert.equal(isAbsolutePath(URI.file('bar')), true); // URI normalizes all file URIs to be absolute
assert.strictEqual(isAbsolutePath(URI.file('/foo/bar')), true);
assert.strictEqual(isAbsolutePath(URI.file('bar')), true); // URI normalizes all file URIs to be absolute
}
assert.equal(isAbsolutePath(URI.parse('foo:foo')), false);
assert.equal(isAbsolutePath(URI.parse('foo://a/foo/.')), true);
assert.strictEqual(isAbsolutePath(URI.parse('foo:foo')), false);
assert.strictEqual(isAbsolutePath(URI.parse('foo://a/foo/.')), true);
});
function assertTrailingSeparator(u1: URI, expected: boolean) {
assert.equal(hasTrailingPathSeparator(u1), expected, u1.toString());
assert.strictEqual(hasTrailingPathSeparator(u1), expected, u1.toString());
}
function assertRemoveTrailingSeparator(u1: URI, expected: URI) {
@@ -237,14 +237,14 @@ suite('Resources', () => {
function assertEqualURI(actual: URI, expected: URI, message?: string, ignoreCase?: boolean) {
let util = ignoreCase ? extUriIgnorePathCase : extUri;
if (!util.isEqual(expected, actual)) {
assert.equal(actual.toString(), expected.toString(), message);
assert.strictEqual(actual.toString(), expected.toString(), message);
}
}
function assertRelativePath(u1: URI, u2: URI, expectedPath: string | undefined, ignoreJoin?: boolean, ignoreCase?: boolean) {
let util = ignoreCase ? extUriIgnorePathCase : extUri;
assert.equal(util.relativePath(u1, u2), expectedPath, `from ${u1.toString()} to ${u2.toString()}`);
assert.strictEqual(util.relativePath(u1, u2), expectedPath, `from ${u1.toString()} to ${u2.toString()}`);
if (expectedPath !== undefined && !ignoreJoin) {
assertEqualURI(removeTrailingPathSeparator(joinPath(u1, expectedPath)), removeTrailingPathSeparator(u2), 'joinPath on relativePath should be equal', ignoreCase);
}
@@ -304,7 +304,7 @@ suite('Resources', () => {
if (!p.isAbsolute(path)) {
let expectedPath = isWindows ? toSlashes(path) : path;
expectedPath = expectedPath.startsWith('./') ? expectedPath.substr(2) : expectedPath;
assert.equal(relativePath(u1, actual), expectedPath, `relativePath (${u1.toString()}) on actual (${actual.toString()}) should be to path (${expectedPath})`);
assert.strictEqual(relativePath(u1, actual), expectedPath, `relativePath (${u1.toString()}) on actual (${actual.toString()}) should be to path (${expectedPath})`);
}
}
@@ -352,12 +352,12 @@ suite('Resources', () => {
let util = ignoreCase ? extUriIgnorePathCase : extUri;
assert.equal(util.isEqual(u1, u2), expected, `${u1.toString()}${expected ? '===' : '!=='}${u2.toString()}`);
assert.equal(util.compare(u1, u2) === 0, expected);
assert.equal(util.getComparisonKey(u1) === util.getComparisonKey(u2), expected, `comparison keys ${u1.toString()}, ${u2.toString()}`);
assert.equal(util.isEqualOrParent(u1, u2), expected, `isEqualOrParent ${u1.toString()}, ${u2.toString()}`);
assert.strictEqual(util.isEqual(u1, u2), expected, `${u1.toString()}${expected ? '===' : '!=='}${u2.toString()}`);
assert.strictEqual(util.compare(u1, u2) === 0, expected);
assert.strictEqual(util.getComparisonKey(u1) === util.getComparisonKey(u2), expected, `comparison keys ${u1.toString()}, ${u2.toString()}`);
assert.strictEqual(util.isEqualOrParent(u1, u2), expected, `isEqualOrParent ${u1.toString()}, ${u2.toString()}`);
if (!ignoreCase) {
assert.equal(u1.toString() === u2.toString(), expected);
assert.strictEqual(u1.toString() === u2.toString(), expected);
}
}
@@ -402,31 +402,31 @@ suite('Resources', () => {
let fileURI = isWindows ? URI.file('c:\\foo\\bar') : URI.file('/foo/bar');
let fileURI2 = isWindows ? URI.file('c:\\foo') : URI.file('/foo');
let fileURI2b = isWindows ? URI.file('C:\\Foo\\') : URI.file('/Foo/');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI, fileURI), true, '1');
assert.equal(extUri.isEqualOrParent(fileURI, fileURI), true, '2');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI, fileURI2), true, '3');
assert.equal(extUri.isEqualOrParent(fileURI, fileURI2), true, '4');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI, fileURI2b), true, '5');
assert.equal(extUri.isEqualOrParent(fileURI, fileURI2b), false, '6');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI, fileURI), true, '1');
assert.strictEqual(extUri.isEqualOrParent(fileURI, fileURI), true, '2');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI, fileURI2), true, '3');
assert.strictEqual(extUri.isEqualOrParent(fileURI, fileURI2), true, '4');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI, fileURI2b), true, '5');
assert.strictEqual(extUri.isEqualOrParent(fileURI, fileURI2b), false, '6');
assert.equal(extUri.isEqualOrParent(fileURI2, fileURI), false, '7');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI2b, fileURI2), true, '8');
assert.strictEqual(extUri.isEqualOrParent(fileURI2, fileURI), false, '7');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI2b, fileURI2), true, '8');
let fileURI3 = URI.parse('foo://server:453/foo/bar/goo');
let fileURI4 = URI.parse('foo://server:453/foo/');
let fileURI5 = URI.parse('foo://server:453/foo');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI3, fileURI3, true), true, '11');
assert.equal(extUri.isEqualOrParent(fileURI3, fileURI3), true, '12');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI3, fileURI4, true), true, '13');
assert.equal(extUri.isEqualOrParent(fileURI3, fileURI4), true, '14');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI3, fileURI, true), false, '15');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI5, fileURI5, true), true, '16');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI3, fileURI3, true), true, '11');
assert.strictEqual(extUri.isEqualOrParent(fileURI3, fileURI3), true, '12');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI3, fileURI4, true), true, '13');
assert.strictEqual(extUri.isEqualOrParent(fileURI3, fileURI4), true, '14');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI3, fileURI, true), false, '15');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI5, fileURI5, true), true, '16');
let fileURI6 = URI.parse('foo://server:453/foo?q=1');
let fileURI7 = URI.parse('foo://server:453/foo/bar?q=1');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI6, fileURI5), false, '17');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI6, fileURI6), true, '18');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI7, fileURI6), true, '19');
assert.equal(extUriIgnorePathCase.isEqualOrParent(fileURI7, fileURI5), false, '20');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI6, fileURI5), false, '17');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI6, fileURI6), true, '18');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI7, fileURI6), true, '19');
assert.strictEqual(extUriIgnorePathCase.isEqualOrParent(fileURI7, fileURI5), false, '20');
});
});

View File

@@ -57,7 +57,7 @@ suite('SmoothScrollingOperation', () => {
function assertSmoothScroll(from: number, to: number, expected: [number, number][]): void {
const actual = simulateSmoothScroll(from, to);
assert.deepEqual(actual, expected);
assert.deepStrictEqual(actual, expected);
}
test('scroll 25 lines (40 fit)', () => {

View File

@@ -12,45 +12,45 @@ import { binarySearch } from 'vs/base/common/arrays';
suite('SkipList', function () {
function assertValues<V>(list: SkipList<any, V>, expected: V[]) {
assert.equal(list.size, expected.length);
assert.deepEqual([...list.values()], expected);
assert.strictEqual(list.size, expected.length);
assert.deepStrictEqual([...list.values()], expected);
let valuesFromEntries = [...list.entries()].map(entry => entry[1]);
assert.deepEqual(valuesFromEntries, expected);
assert.deepStrictEqual(valuesFromEntries, expected);
let valuesFromIter = [...list].map(entry => entry[1]);
assert.deepEqual(valuesFromIter, expected);
assert.deepStrictEqual(valuesFromIter, expected);
let i = 0;
list.forEach((value, _key, map) => {
assert.ok(map === list);
assert.deepEqual(value, expected[i++]);
assert.deepStrictEqual(value, expected[i++]);
});
}
function assertKeys<K>(list: SkipList<K, any>, expected: K[]) {
assert.equal(list.size, expected.length);
assert.deepEqual([...list.keys()], expected);
assert.strictEqual(list.size, expected.length);
assert.deepStrictEqual([...list.keys()], expected);
let keysFromEntries = [...list.entries()].map(entry => entry[0]);
assert.deepEqual(keysFromEntries, expected);
assert.deepStrictEqual(keysFromEntries, expected);
let keysFromIter = [...list].map(entry => entry[0]);
assert.deepEqual(keysFromIter, expected);
assert.deepStrictEqual(keysFromIter, expected);
let i = 0;
list.forEach((_value, key, map) => {
assert.ok(map === list);
assert.deepEqual(key, expected[i++]);
assert.deepStrictEqual(key, expected[i++]);
});
}
test('set/get/delete', function () {
let list = new SkipList<number, number>((a, b) => a - b);
assert.equal(list.get(3), undefined);
assert.strictEqual(list.get(3), undefined);
list.set(3, 1);
assert.equal(list.get(3), 1);
assert.strictEqual(list.get(3), 1);
assertValues(list, [1]);
list.set(3, 3);
@@ -58,17 +58,17 @@ suite('SkipList', function () {
list.set(1, 1);
list.set(4, 4);
assert.equal(list.get(3), 3);
assert.equal(list.get(1), 1);
assert.equal(list.get(4), 4);
assert.strictEqual(list.get(3), 3);
assert.strictEqual(list.get(1), 1);
assert.strictEqual(list.get(4), 4);
assertValues(list, [1, 3, 4]);
assert.equal(list.delete(17), false);
assert.strictEqual(list.delete(17), false);
assert.equal(list.delete(1), true);
assert.equal(list.get(1), undefined);
assert.equal(list.get(3), 3);
assert.equal(list.get(4), 4);
assert.strictEqual(list.delete(1), true);
assert.strictEqual(list.get(1), undefined);
assert.strictEqual(list.get(3), 3);
assert.strictEqual(list.get(4), 4);
assertValues(list, [3, 4]);
});
@@ -87,7 +87,7 @@ suite('SkipList', function () {
assertKeys(list, [3, 6, 7, 9, 12, 19, 21, 25]);
list.set(17, true);
assert.deepEqual(list.size, 9);
assert.deepStrictEqual(list.size, 9);
assertKeys(list, [3, 6, 7, 9, 12, 17, 19, 21, 25]);
});
@@ -141,8 +141,7 @@ suite('SkipList', function () {
}
test('perf', function () {
this.skip();
test.skip('perf', function () {
// data
const max = 2 ** 16;

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { isReadableStream, newWriteableStream, Readable, consumeReadable, peekReadable, consumeStream, ReadableStream, toStream, toReadable, transform, peekStream, isReadableBufferedStream } from 'vs/base/common/stream';
import { isReadableStream, newWriteableStream, Readable, consumeReadable, peekReadable, consumeStream, ReadableStream, toStream, toReadable, transform, peekStream, isReadableBufferedStream, observe } from 'vs/base/common/stream';
import { timeout } from 'vs/base/common/async';
suite('Stream', () => {
@@ -43,37 +43,37 @@ suite('Stream', () => {
chunks.push(data);
});
assert.equal(chunks[0], 'Hello');
assert.strictEqual(chunks[0], 'Hello');
stream.write('World');
assert.equal(chunks[1], 'World');
assert.strictEqual(chunks[1], 'World');
assert.equal(error, false);
assert.equal(end, false);
assert.strictEqual(error, false);
assert.strictEqual(end, false);
stream.pause();
stream.write('1');
stream.write('2');
stream.write('3');
assert.equal(chunks.length, 2);
assert.strictEqual(chunks.length, 2);
stream.resume();
assert.equal(chunks.length, 3);
assert.equal(chunks[2], '1,2,3');
assert.strictEqual(chunks.length, 3);
assert.strictEqual(chunks[2], '1,2,3');
stream.error(new Error());
assert.equal(error, true);
assert.strictEqual(error, true);
stream.end('Final Bit');
assert.equal(chunks.length, 4);
assert.equal(chunks[3], 'Final Bit');
assert.strictEqual(chunks.length, 4);
assert.strictEqual(chunks[3], 'Final Bit');
stream.destroy();
stream.write('Unexpected');
assert.equal(chunks.length, 4);
assert.strictEqual(chunks.length, 4);
});
test('WriteableStream - removeListener', () => {
@@ -92,22 +92,24 @@ suite('Stream', () => {
stream.on('data', dataListener);
stream.write('Hello');
assert.equal(data, true);
assert.strictEqual(data, true);
data = false;
stream.removeListener('data', dataListener);
stream.write('World');
assert.equal(data, false);
assert.strictEqual(data, false);
stream.error(new Error());
assert.equal(error, true);
assert.strictEqual(error, true);
error = false;
stream.removeListener('error', errorListener);
// always leave at least one error listener to streams to avoid unexpected errors during test running
stream.on('error', () => { });
stream.error(new Error());
assert.equal(error, false);
assert.strictEqual(error, false);
});
test('WriteableStream - highWaterMark', async () => {
@@ -147,14 +149,14 @@ suite('Stream', () => {
assert.ok(data);
await timeout(0);
assert.equal(drained1, true);
assert.equal(drained2, true);
assert.strictEqual(drained1, true);
assert.strictEqual(drained2, true);
});
test('consumeReadable', () => {
const readable = arrayToReadable(['1', '2', '3', '4', '5']);
const consumed = consumeReadable(readable, strings => strings.join());
assert.equal(consumed, '1,2,3,4,5');
assert.strictEqual(consumed, '1,2,3,4,5');
});
test('peekReadable', () => {
@@ -166,17 +168,17 @@ suite('Stream', () => {
assert.fail('Unexpected result');
} else {
const consumed = consumeReadable(consumedOrReadable, strings => strings.join());
assert.equal(consumed, '1,2,3,4,5');
assert.strictEqual(consumed, '1,2,3,4,5');
}
}
let readable = arrayToReadable(['1', '2', '3', '4', '5']);
let consumedOrReadable = peekReadable(readable, strings => strings.join(), 5);
assert.equal(consumedOrReadable, '1,2,3,4,5');
assert.strictEqual(consumedOrReadable, '1,2,3,4,5');
readable = arrayToReadable(['1', '2', '3', '4', '5']);
consumedOrReadable = peekReadable(readable, strings => strings.join(), 6);
assert.equal(consumedOrReadable, '1,2,3,4,5');
assert.strictEqual(consumedOrReadable, '1,2,3,4,5');
});
test('peekReadable - error handling', async () => {
@@ -265,7 +267,7 @@ suite('Stream', () => {
test('consumeStream', async () => {
const stream = readableToStream(arrayToReadable(['1', '2', '3', '4', '5']));
const consumed = await consumeStream(stream, strings => strings.join());
assert.equal(consumed, '1,2,3,4,5');
assert.strictEqual(consumed, '1,2,3,4,5');
});
test('peekStream', async () => {
@@ -273,11 +275,11 @@ suite('Stream', () => {
const stream = readableToStream(arrayToReadable(['1', '2', '3', '4', '5']));
const result = await peekStream(stream, i);
assert.equal(stream, result.stream);
assert.strictEqual(stream, result.stream);
if (result.ended) {
assert.fail('Unexpected result, stream should not have ended yet');
} else {
assert.equal(result.buffer.length, i + 1, `maxChunks: ${i}`);
assert.strictEqual(result.buffer.length, i + 1, `maxChunks: ${i}`);
const additionalResult: string[] = [];
await consumeStream(stream, strings => {
@@ -286,33 +288,33 @@ suite('Stream', () => {
return strings.join();
});
assert.equal([...result.buffer, ...additionalResult].join(), '1,2,3,4,5');
assert.strictEqual([...result.buffer, ...additionalResult].join(), '1,2,3,4,5');
}
}
let stream = readableToStream(arrayToReadable(['1', '2', '3', '4', '5']));
let result = await peekStream(stream, 5);
assert.equal(stream, result.stream);
assert.equal(result.buffer.join(), '1,2,3,4,5');
assert.equal(result.ended, true);
assert.strictEqual(stream, result.stream);
assert.strictEqual(result.buffer.join(), '1,2,3,4,5');
assert.strictEqual(result.ended, true);
stream = readableToStream(arrayToReadable(['1', '2', '3', '4', '5']));
result = await peekStream(stream, 6);
assert.equal(stream, result.stream);
assert.equal(result.buffer.join(), '1,2,3,4,5');
assert.equal(result.ended, true);
assert.strictEqual(stream, result.stream);
assert.strictEqual(result.buffer.join(), '1,2,3,4,5');
assert.strictEqual(result.ended, true);
});
test('toStream', async () => {
const stream = toStream('1,2,3,4,5', strings => strings.join());
const consumed = await consumeStream(stream, strings => strings.join());
assert.equal(consumed, '1,2,3,4,5');
assert.strictEqual(consumed, '1,2,3,4,5');
});
test('toReadable', async () => {
const readable = toReadable('1,2,3,4,5');
const consumed = await consumeReadable(readable, strings => strings.join());
assert.equal(consumed, '1,2,3,4,5');
assert.strictEqual(consumed, '1,2,3,4,5');
});
test('transform', async () => {
@@ -330,6 +332,47 @@ suite('Stream', () => {
}, 0);
const consumed = await consumeStream(result, strings => strings.join());
assert.equal(consumed, '11,22,33,44,55');
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());
let listener1Called = false;
let listener2Called = false;
const listener1 = () => { stream.removeListener('end', listener1); listener1Called = true; };
const listener2 = () => { listener2Called = true; };
stream.on('end', listener1);
stream.on('end', listener2);
stream.on('data', () => { });
stream.end('');
assert.strictEqual(listener1Called, true);
assert.strictEqual(listener2Called, true);
});
});

View File

@@ -52,7 +52,7 @@ suite('Strings', () => {
let expected = strings.compare(a.toLowerCase(), b.toLowerCase());
expected = expected > 0 ? 1 : expected < 0 ? -1 : expected;
assert.equal(actual, expected, `${a} <> ${b}`);
assert.strictEqual(actual, expected, `${a} <> ${b}`);
if (recurse) {
assertCompareIgnoreCase(b, a, false);
@@ -89,7 +89,7 @@ suite('Strings', () => {
let expected = strings.compare(a.toLowerCase().substring(aStart, aEnd), b.toLowerCase().substring(bStart, bEnd));
expected = expected > 0 ? 1 : expected < 0 ? -1 : expected;
assert.equal(actual, expected, `${a} <> ${b}`);
assert.strictEqual(actual, expected, `${a} <> ${b}`);
if (recurse) {
assertCompareIgnoreCase(b, a, bStart, bEnd, aStart, aEnd, false);
@@ -188,36 +188,36 @@ suite('Strings', () => {
});
test('containsRTL', () => {
assert.equal(strings.containsRTL('a'), false);
assert.equal(strings.containsRTL(''), false);
assert.equal(strings.containsRTL(strings.UTF8_BOM_CHARACTER + 'a'), false);
assert.equal(strings.containsRTL('hello world!'), false);
assert.equal(strings.containsRTL('a📚📚b'), false);
assert.equal(strings.containsRTL('هناك حقيقة مثبتة منذ زمن طويل'), true);
assert.equal(strings.containsRTL('זוהי עובדה מבוססת שדעתו'), true);
assert.strictEqual(strings.containsRTL('a'), false);
assert.strictEqual(strings.containsRTL(''), false);
assert.strictEqual(strings.containsRTL(strings.UTF8_BOM_CHARACTER + 'a'), false);
assert.strictEqual(strings.containsRTL('hello world!'), false);
assert.strictEqual(strings.containsRTL('a📚📚b'), false);
assert.strictEqual(strings.containsRTL('هناك حقيقة مثبتة منذ زمن طويل'), true);
assert.strictEqual(strings.containsRTL('זוהי עובדה מבוססת שדעתו'), true);
});
test('containsEmoji', () => {
assert.equal(strings.containsEmoji('a'), false);
assert.equal(strings.containsEmoji(''), false);
assert.equal(strings.containsEmoji(strings.UTF8_BOM_CHARACTER + 'a'), false);
assert.equal(strings.containsEmoji('hello world!'), false);
assert.equal(strings.containsEmoji('هناك حقيقة مثبتة منذ زمن طويل'), false);
assert.equal(strings.containsEmoji('זוהי עובדה מבוססת שדעתו'), false);
assert.strictEqual(strings.containsEmoji('a'), false);
assert.strictEqual(strings.containsEmoji(''), false);
assert.strictEqual(strings.containsEmoji(strings.UTF8_BOM_CHARACTER + 'a'), false);
assert.strictEqual(strings.containsEmoji('hello world!'), false);
assert.strictEqual(strings.containsEmoji('هناك حقيقة مثبتة منذ زمن طويل'), false);
assert.strictEqual(strings.containsEmoji('זוהי עובדה מבוססת שדעתו'), false);
assert.equal(strings.containsEmoji('a📚📚b'), true);
assert.equal(strings.containsEmoji('1F600 # 😀 grinning face'), true);
assert.equal(strings.containsEmoji('1F47E # 👾 alien monster'), true);
assert.equal(strings.containsEmoji('1F467 1F3FD # 👧🏽 girl: medium skin tone'), true);
assert.equal(strings.containsEmoji('26EA # ⛪ church'), true);
assert.equal(strings.containsEmoji('231B # ⌛ hourglass'), true);
assert.equal(strings.containsEmoji('2702 # ✂ scissors'), true);
assert.equal(strings.containsEmoji('1F1F7 1F1F4 # 🇷🇴 Romania'), true);
assert.strictEqual(strings.containsEmoji('a📚📚b'), true);
assert.strictEqual(strings.containsEmoji('1F600 # 😀 grinning face'), true);
assert.strictEqual(strings.containsEmoji('1F47E # 👾 alien monster'), true);
assert.strictEqual(strings.containsEmoji('1F467 1F3FD # 👧🏽 girl: medium skin tone'), true);
assert.strictEqual(strings.containsEmoji('26EA # ⛪ church'), true);
assert.strictEqual(strings.containsEmoji('231B # ⌛ hourglass'), true);
assert.strictEqual(strings.containsEmoji('2702 # ✂ scissors'), true);
assert.strictEqual(strings.containsEmoji('1F1F7 1F1F4 # 🇷🇴 Romania'), true);
});
test('isBasicASCII', () => {
function assertIsBasicASCII(str: string, expected: boolean): void {
assert.equal(strings.isBasicASCII(str), expected, str + ` (${str.charCodeAt(0)})`);
assert.strictEqual(strings.isBasicASCII(str), expected, str + ` (${str.charCodeAt(0)})`);
}
assertIsBasicASCII('abcdefghijklmnopqrstuvwxyz', true);
assertIsBasicASCII('ABCDEFGHIJKLMNOPQRSTUVWXYZ', true);
@@ -245,16 +245,16 @@ suite('Strings', () => {
assert.throws(() => strings.createRegExp('', false));
// Escapes appropriately
assert.equal(strings.createRegExp('abc', false).source, 'abc');
assert.equal(strings.createRegExp('([^ ,.]*)', false).source, '\\(\\[\\^ ,\\.\\]\\*\\)');
assert.equal(strings.createRegExp('([^ ,.]*)', true).source, '([^ ,.]*)');
assert.strictEqual(strings.createRegExp('abc', false).source, 'abc');
assert.strictEqual(strings.createRegExp('([^ ,.]*)', false).source, '\\(\\[\\^ ,\\.\\]\\*\\)');
assert.strictEqual(strings.createRegExp('([^ ,.]*)', true).source, '([^ ,.]*)');
// Whole word
assert.equal(strings.createRegExp('abc', false, { wholeWord: true }).source, '\\babc\\b');
assert.equal(strings.createRegExp('abc', true, { wholeWord: true }).source, '\\babc\\b');
assert.equal(strings.createRegExp(' abc', true, { wholeWord: true }).source, ' abc\\b');
assert.equal(strings.createRegExp('abc ', true, { wholeWord: true }).source, '\\babc ');
assert.equal(strings.createRegExp(' abc ', true, { wholeWord: true }).source, ' abc ');
assert.strictEqual(strings.createRegExp('abc', false, { wholeWord: true }).source, '\\babc\\b');
assert.strictEqual(strings.createRegExp('abc', true, { wholeWord: true }).source, '\\babc\\b');
assert.strictEqual(strings.createRegExp(' abc', true, { wholeWord: true }).source, ' abc\\b');
assert.strictEqual(strings.createRegExp('abc ', true, { wholeWord: true }).source, '\\babc ');
assert.strictEqual(strings.createRegExp(' abc ', true, { wholeWord: true }).source, ' abc ');
const regExpWithoutFlags = strings.createRegExp('abc', true);
assert(!regExpWithoutFlags.global);
@@ -284,15 +284,15 @@ suite('Strings', () => {
});
test('getLeadingWhitespace', () => {
assert.equal(strings.getLeadingWhitespace(' foo'), ' ');
assert.equal(strings.getLeadingWhitespace(' foo', 2), '');
assert.equal(strings.getLeadingWhitespace(' foo', 1, 1), '');
assert.equal(strings.getLeadingWhitespace(' foo', 0, 1), ' ');
assert.equal(strings.getLeadingWhitespace(' '), ' ');
assert.equal(strings.getLeadingWhitespace(' ', 1), ' ');
assert.equal(strings.getLeadingWhitespace(' ', 0, 1), ' ');
assert.equal(strings.getLeadingWhitespace('\t\tfunction foo(){', 0, 1), '\t');
assert.equal(strings.getLeadingWhitespace('\t\tfunction foo(){', 0, 2), '\t\t');
assert.strictEqual(strings.getLeadingWhitespace(' foo'), ' ');
assert.strictEqual(strings.getLeadingWhitespace(' foo', 2), '');
assert.strictEqual(strings.getLeadingWhitespace(' foo', 1, 1), '');
assert.strictEqual(strings.getLeadingWhitespace(' foo', 0, 1), ' ');
assert.strictEqual(strings.getLeadingWhitespace(' '), ' ');
assert.strictEqual(strings.getLeadingWhitespace(' ', 1), ' ');
assert.strictEqual(strings.getLeadingWhitespace(' ', 0, 1), ' ');
assert.strictEqual(strings.getLeadingWhitespace('\t\tfunction foo(){', 0, 1), '\t');
assert.strictEqual(strings.getLeadingWhitespace('\t\tfunction foo(){', 0, 2), '\t\t');
});
test('fuzzyContains', () => {
@@ -316,11 +316,11 @@ suite('Strings', () => {
});
test('stripUTF8BOM', () => {
assert.equal(strings.stripUTF8BOM(strings.UTF8_BOM_CHARACTER), '');
assert.equal(strings.stripUTF8BOM(strings.UTF8_BOM_CHARACTER + 'foobar'), 'foobar');
assert.equal(strings.stripUTF8BOM('foobar' + strings.UTF8_BOM_CHARACTER), 'foobar' + strings.UTF8_BOM_CHARACTER);
assert.equal(strings.stripUTF8BOM('abc'), 'abc');
assert.equal(strings.stripUTF8BOM(''), '');
assert.strictEqual(strings.stripUTF8BOM(strings.UTF8_BOM_CHARACTER), '');
assert.strictEqual(strings.stripUTF8BOM(strings.UTF8_BOM_CHARACTER + 'foobar'), 'foobar');
assert.strictEqual(strings.stripUTF8BOM('foobar' + strings.UTF8_BOM_CHARACTER), 'foobar' + strings.UTF8_BOM_CHARACTER);
assert.strictEqual(strings.stripUTF8BOM('abc'), 'abc');
assert.strictEqual(strings.stripUTF8BOM(''), '');
});
test('containsUppercaseCharacter', () => {
@@ -340,7 +340,7 @@ suite('Strings', () => {
['FöÖ', true],
['\\Foo', true],
].forEach(([str, result]) => {
assert.equal(strings.containsUppercaseCharacter(<string>str), result, `Wrong result for ${str}`);
assert.strictEqual(strings.containsUppercaseCharacter(<string>str), result, `Wrong result for ${str}`);
});
});
@@ -352,7 +352,7 @@ suite('Strings', () => {
['Foo', true],
].forEach(([str, result]) => {
assert.equal(strings.containsUppercaseCharacter(<string>str, true), result, `Wrong result for ${str}`);
assert.strictEqual(strings.containsUppercaseCharacter(<string>str, true), result, `Wrong result for ${str}`);
});
});
@@ -364,20 +364,20 @@ suite('Strings', () => {
['123', '123'],
['.a', '.a'],
].forEach(([inStr, result]) => {
assert.equal(strings.uppercaseFirstLetter(inStr), result, `Wrong result for ${inStr}`);
assert.strictEqual(strings.uppercaseFirstLetter(inStr), result, `Wrong result for ${inStr}`);
});
});
test('getNLines', () => {
assert.equal(strings.getNLines('', 5), '');
assert.equal(strings.getNLines('foo', 5), 'foo');
assert.equal(strings.getNLines('foo\nbar', 5), 'foo\nbar');
assert.equal(strings.getNLines('foo\nbar', 2), 'foo\nbar');
assert.strictEqual(strings.getNLines('', 5), '');
assert.strictEqual(strings.getNLines('foo', 5), 'foo');
assert.strictEqual(strings.getNLines('foo\nbar', 5), 'foo\nbar');
assert.strictEqual(strings.getNLines('foo\nbar', 2), 'foo\nbar');
assert.equal(strings.getNLines('foo\nbar', 1), 'foo');
assert.equal(strings.getNLines('foo\nbar'), 'foo');
assert.equal(strings.getNLines('foo\nbar\nsomething', 2), 'foo\nbar');
assert.equal(strings.getNLines('foo', 0), '');
assert.strictEqual(strings.getNLines('foo\nbar', 1), 'foo');
assert.strictEqual(strings.getNLines('foo\nbar'), 'foo');
assert.strictEqual(strings.getNLines('foo\nbar\nsomething', 2), 'foo\nbar');
assert.strictEqual(strings.getNLines('foo', 0), '');
});
test('encodeUTF8', function () {
@@ -387,12 +387,12 @@ suite('Strings', () => {
for (let offset = 0; offset < actual.byteLength; offset++) {
actualArr[offset] = actual[offset];
}
assert.deepEqual(actualArr, expected);
assert.deepStrictEqual(actualArr, expected);
}
function assertDecodeUTF8(data: number[], expected: string): void {
const actual = strings.decodeUTF8(new Uint8Array(data));
assert.deepEqual(actual, expected);
assert.deepStrictEqual(actual, expected);
}
function assertEncodeDecodeUTF8(str: string, buff: number[]): void {
@@ -415,11 +415,11 @@ suite('Strings', () => {
});
test('getGraphemeBreakType', () => {
assert.equal(strings.getGraphemeBreakType(0xBC1), strings.GraphemeBreakType.SpacingMark);
assert.strictEqual(strings.getGraphemeBreakType(0xBC1), strings.GraphemeBreakType.SpacingMark);
});
test('truncate', () => {
assert.equal('hello world', strings.truncate('hello world', 100));
assert.equal('hello…', strings.truncate('hello world', 5));
assert.strictEqual('hello world', strings.truncate('hello world', 100));
assert.strictEqual('hello…', strings.truncate('hello world', 5));
});
});

View File

@@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable, IDisposableTracker, setDisposableTracker } from 'vs/base/common/lifecycle';
class DisposableTracker implements IDisposableTracker {
allDisposables: [IDisposable, string][] = [];
trackDisposable(x: IDisposable): void {
this.allDisposables.push([x, new Error().stack!]);
}
markTracked(x: IDisposable): void {
for (let idx = 0; idx < this.allDisposables.length; idx++) {
if (this.allDisposables[idx][0] === x) {
this.allDisposables.splice(idx, 1);
return;
}
}
}
}
let currentTracker: DisposableTracker | null = null;
export function beginTrackingDisposables(): void {
currentTracker = new DisposableTracker();
setDisposableTracker(currentTracker);
}
export function endTrackingDisposables(): void {
if (currentTracker) {
setDisposableTracker(null);
console.log(currentTracker!.allDisposables.map(e => `${e[0]}\n${e[1]}`).join('\n\n'));
currentTracker = null;
}
}
export function beginLoggingFS(withStacks: boolean = false): void {
if ((<any>self).beginLoggingFS) {
(<any>self).beginLoggingFS(withStacks);
}
}
export function endLoggingFS(): void {
if ((<any>self).endLoggingFS) {
(<any>self).endLoggingFS();
}
}

View File

@@ -57,7 +57,7 @@ suite('Types', () => {
assert(!types.isObject(/test/));
assert(!types.isObject(new RegExp('')));
assert(!types.isFunction(new Date()));
assert(!types.isObject(assert));
assert.strictEqual(types.isObject(assert), false);
assert(!types.isObject(function foo() { }));
assert(types.isObject({}));
@@ -75,7 +75,7 @@ suite('Types', () => {
assert(!types.isEmptyObject(/test/));
assert(!types.isEmptyObject(new RegExp('')));
assert(!types.isEmptyObject(new Date()));
assert(!types.isEmptyObject(assert));
assert.strictEqual(types.isEmptyObject(assert), false);
assert(!types.isEmptyObject(function foo() { /**/ }));
assert(!types.isEmptyObject({ foo: 'bar' }));
@@ -178,15 +178,15 @@ suite('Types', () => {
assert.throws(() => types.assertAllDefined(true, undefined));
assert.throws(() => types.assertAllDefined(undefined, false));
assert.equal(types.assertIsDefined(true), true);
assert.equal(types.assertIsDefined(false), false);
assert.equal(types.assertIsDefined('Hello'), 'Hello');
assert.equal(types.assertIsDefined(''), '');
assert.strictEqual(types.assertIsDefined(true), true);
assert.strictEqual(types.assertIsDefined(false), false);
assert.strictEqual(types.assertIsDefined('Hello'), 'Hello');
assert.strictEqual(types.assertIsDefined(''), '');
const res = types.assertAllDefined(1, true, 'Hello');
assert.equal(res[0], 1);
assert.equal(res[1], true);
assert.equal(res[2], 'Hello');
assert.strictEqual(res[0], 1);
assert.strictEqual(res[1], true);
assert.strictEqual(res[2], 'Hello');
});
test('validateConstraints', () => {

View File

@@ -9,82 +9,82 @@ import { isWindows } from 'vs/base/common/platform';
suite('URI', () => {
test('file#toString', () => {
assert.equal(URI.file('c:/win/path').toString(), 'file:///c%3A/win/path');
assert.equal(URI.file('C:/win/path').toString(), 'file:///c%3A/win/path');
assert.equal(URI.file('c:/win/path/').toString(), 'file:///c%3A/win/path/');
assert.equal(URI.file('/c:/win/path').toString(), 'file:///c%3A/win/path');
assert.strictEqual(URI.file('c:/win/path').toString(), 'file:///c%3A/win/path');
assert.strictEqual(URI.file('C:/win/path').toString(), 'file:///c%3A/win/path');
assert.strictEqual(URI.file('c:/win/path/').toString(), 'file:///c%3A/win/path/');
assert.strictEqual(URI.file('/c:/win/path').toString(), 'file:///c%3A/win/path');
});
test('URI.file (win-special)', () => {
if (isWindows) {
assert.equal(URI.file('c:\\win\\path').toString(), 'file:///c%3A/win/path');
assert.equal(URI.file('c:\\win/path').toString(), 'file:///c%3A/win/path');
assert.strictEqual(URI.file('c:\\win\\path').toString(), 'file:///c%3A/win/path');
assert.strictEqual(URI.file('c:\\win/path').toString(), 'file:///c%3A/win/path');
} else {
assert.equal(URI.file('c:\\win\\path').toString(), 'file:///c%3A%5Cwin%5Cpath');
assert.equal(URI.file('c:\\win/path').toString(), 'file:///c%3A%5Cwin/path');
assert.strictEqual(URI.file('c:\\win\\path').toString(), 'file:///c%3A%5Cwin%5Cpath');
assert.strictEqual(URI.file('c:\\win/path').toString(), 'file:///c%3A%5Cwin/path');
}
});
test('file#fsPath (win-special)', () => {
if (isWindows) {
assert.equal(URI.file('c:\\win\\path').fsPath, 'c:\\win\\path');
assert.equal(URI.file('c:\\win/path').fsPath, 'c:\\win\\path');
assert.strictEqual(URI.file('c:\\win\\path').fsPath, 'c:\\win\\path');
assert.strictEqual(URI.file('c:\\win/path').fsPath, 'c:\\win\\path');
assert.equal(URI.file('c:/win/path').fsPath, 'c:\\win\\path');
assert.equal(URI.file('c:/win/path/').fsPath, 'c:\\win\\path\\');
assert.equal(URI.file('C:/win/path').fsPath, 'c:\\win\\path');
assert.equal(URI.file('/c:/win/path').fsPath, 'c:\\win\\path');
assert.equal(URI.file('./c/win/path').fsPath, '\\.\\c\\win\\path');
assert.strictEqual(URI.file('c:/win/path').fsPath, 'c:\\win\\path');
assert.strictEqual(URI.file('c:/win/path/').fsPath, 'c:\\win\\path\\');
assert.strictEqual(URI.file('C:/win/path').fsPath, 'c:\\win\\path');
assert.strictEqual(URI.file('/c:/win/path').fsPath, 'c:\\win\\path');
assert.strictEqual(URI.file('./c/win/path').fsPath, '\\.\\c\\win\\path');
} else {
assert.equal(URI.file('c:/win/path').fsPath, 'c:/win/path');
assert.equal(URI.file('c:/win/path/').fsPath, 'c:/win/path/');
assert.equal(URI.file('C:/win/path').fsPath, 'c:/win/path');
assert.equal(URI.file('/c:/win/path').fsPath, 'c:/win/path');
assert.equal(URI.file('./c/win/path').fsPath, '/./c/win/path');
assert.strictEqual(URI.file('c:/win/path').fsPath, 'c:/win/path');
assert.strictEqual(URI.file('c:/win/path/').fsPath, 'c:/win/path/');
assert.strictEqual(URI.file('C:/win/path').fsPath, 'c:/win/path');
assert.strictEqual(URI.file('/c:/win/path').fsPath, 'c:/win/path');
assert.strictEqual(URI.file('./c/win/path').fsPath, '/./c/win/path');
}
});
test('URI#fsPath - no `fsPath` when no `path`', () => {
const value = URI.parse('file://%2Fhome%2Fticino%2Fdesktop%2Fcpluscplus%2Ftest.cpp');
assert.equal(value.authority, '/home/ticino/desktop/cpluscplus/test.cpp');
assert.equal(value.path, '/');
assert.strictEqual(value.authority, '/home/ticino/desktop/cpluscplus/test.cpp');
assert.strictEqual(value.path, '/');
if (isWindows) {
assert.equal(value.fsPath, '\\');
assert.strictEqual(value.fsPath, '\\');
} else {
assert.equal(value.fsPath, '/');
assert.strictEqual(value.fsPath, '/');
}
});
test('http#toString', () => {
assert.equal(URI.from({ scheme: 'http', authority: 'www.msft.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.equal(URI.from({ scheme: 'http', authority: 'www.msft.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.equal(URI.from({ scheme: 'http', authority: 'www.MSFT.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.equal(URI.from({ scheme: 'http', authority: '', path: 'my/path' }).toString(), 'http:/my/path');
assert.equal(URI.from({ scheme: 'http', authority: '', path: '/my/path' }).toString(), 'http:/my/path');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'www.msft.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'www.msft.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'www.MSFT.com', path: '/my/path' }).toString(), 'http://www.msft.com/my/path');
assert.strictEqual(URI.from({ scheme: 'http', authority: '', path: 'my/path' }).toString(), 'http:/my/path');
assert.strictEqual(URI.from({ scheme: 'http', authority: '', path: '/my/path' }).toString(), 'http:/my/path');
//http://a-test-site.com/#test=true
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(), 'http://a-test-site.com/?test%3Dtrue');
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(), 'http://a-test-site.com/#test%3Dtrue');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(), 'http://a-test-site.com/?test%3Dtrue');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(), 'http://a-test-site.com/#test%3Dtrue');
});
test('http#toString, encode=FALSE', () => {
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(true), 'http://a-test-site.com/?test=true');
assert.equal(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(true), 'http://a-test-site.com/#test=true');
assert.equal(URI.from({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(true), 'http:/api/files/test.me?t=1234');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: 'test=true' }).toString(true), 'http://a-test-site.com/?test=true');
assert.strictEqual(URI.from({ scheme: 'http', authority: 'a-test-site.com', path: '/', query: '', fragment: 'test=true' }).toString(true), 'http://a-test-site.com/#test=true');
assert.strictEqual(URI.from({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(true), 'http:/api/files/test.me?t=1234');
const value = URI.parse('file://shares/pröjects/c%23/#l12');
assert.equal(value.authority, 'shares');
assert.equal(value.path, '/pröjects/c#/');
assert.equal(value.fragment, 'l12');
assert.equal(value.toString(), 'file://shares/pr%C3%B6jects/c%23/#l12');
assert.equal(value.toString(true), 'file://shares/pröjects/c%23/#l12');
assert.strictEqual(value.authority, 'shares');
assert.strictEqual(value.path, '/pröjects/c#/');
assert.strictEqual(value.fragment, 'l12');
assert.strictEqual(value.toString(), 'file://shares/pr%C3%B6jects/c%23/#l12');
assert.strictEqual(value.toString(true), 'file://shares/pröjects/c%23/#l12');
const uri2 = URI.parse(value.toString(true));
const uri3 = URI.parse(value.toString());
assert.equal(uri2.authority, uri3.authority);
assert.equal(uri2.path, uri3.path);
assert.equal(uri2.query, uri3.query);
assert.equal(uri2.fragment, uri3.fragment);
assert.strictEqual(uri2.authority, uri3.authority);
assert.strictEqual(uri2.path, uri3.path);
assert.strictEqual(uri2.query, uri3.query);
assert.strictEqual(uri2.fragment, uri3.fragment);
});
test('with, identity', () => {
@@ -101,23 +101,23 @@ suite('URI', () => {
});
test('with, changes', () => {
assert.equal(URI.parse('before:some/file/path').with({ scheme: 'after' }).toString(), 'after:some/file/path');
assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'http', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'https', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'https:/api/files/test.me?t%3D1234');
assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'HTTP', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTP:/api/files/test.me?t%3D1234');
assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'HTTPS', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTPS:/api/files/test.me?t%3D1234');
assert.equal(URI.from({ scheme: 's' }).with({ scheme: 'boo', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'boo:/api/files/test.me?t%3D1234');
assert.strictEqual(URI.parse('before:some/file/path').with({ scheme: 'after' }).toString(), 'after:some/file/path');
assert.strictEqual(URI.from({ scheme: 's' }).with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.strictEqual(URI.from({ scheme: 's' }).with({ scheme: 'http', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.strictEqual(URI.from({ scheme: 's' }).with({ scheme: 'https', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'https:/api/files/test.me?t%3D1234');
assert.strictEqual(URI.from({ scheme: 's' }).with({ scheme: 'HTTP', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTP:/api/files/test.me?t%3D1234');
assert.strictEqual(URI.from({ scheme: 's' }).with({ scheme: 'HTTPS', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTPS:/api/files/test.me?t%3D1234');
assert.strictEqual(URI.from({ scheme: 's' }).with({ scheme: 'boo', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'boo:/api/files/test.me?t%3D1234');
});
test('with, remove components #8465', () => {
assert.equal(URI.parse('scheme://authority/path').with({ authority: '' }).toString(), 'scheme:/path');
assert.equal(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ authority: '' }).toString(), 'scheme:/path');
assert.equal(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ authority: null }).toString(), 'scheme:/path');
assert.equal(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ path: '' }).toString(), 'scheme://authority');
assert.equal(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ path: null }).toString(), 'scheme://authority');
assert.equal(URI.parse('scheme:/path').with({ authority: '' }).toString(), 'scheme:/path');
assert.equal(URI.parse('scheme:/path').with({ authority: null }).toString(), 'scheme:/path');
assert.strictEqual(URI.parse('scheme://authority/path').with({ authority: '' }).toString(), 'scheme:/path');
assert.strictEqual(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ authority: '' }).toString(), 'scheme:/path');
assert.strictEqual(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ authority: null }).toString(), 'scheme:/path');
assert.strictEqual(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ path: '' }).toString(), 'scheme://authority');
assert.strictEqual(URI.parse('scheme:/path').with({ authority: 'authority' }).with({ path: null }).toString(), 'scheme://authority');
assert.strictEqual(URI.parse('scheme:/path').with({ authority: '' }).toString(), 'scheme:/path');
assert.strictEqual(URI.parse('scheme:/path').with({ authority: null }).toString(), 'scheme:/path');
});
test('with, validation', () => {
@@ -130,104 +130,104 @@ suite('URI', () => {
test('parse', () => {
let value = URI.parse('http:/api/files/test.me?t=1234');
assert.equal(value.scheme, 'http');
assert.equal(value.authority, '');
assert.equal(value.path, '/api/files/test.me');
assert.equal(value.query, 't=1234');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'http');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/api/files/test.me');
assert.strictEqual(value.query, 't=1234');
assert.strictEqual(value.fragment, '');
value = URI.parse('http://api/files/test.me?t=1234');
assert.equal(value.scheme, 'http');
assert.equal(value.authority, 'api');
assert.equal(value.path, '/files/test.me');
assert.equal(value.query, 't=1234');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'http');
assert.strictEqual(value.authority, 'api');
assert.strictEqual(value.path, '/files/test.me');
assert.strictEqual(value.query, 't=1234');
assert.strictEqual(value.fragment, '');
value = URI.parse('file:///c:/test/me');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/c:/test/me');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.equal(value.fsPath, isWindows ? 'c:\\test\\me' : 'c:/test/me');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/c:/test/me');
assert.strictEqual(value.fragment, '');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fsPath, isWindows ? 'c:\\test\\me' : 'c:/test/me');
value = URI.parse('file://shares/files/c%23/p.cs');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, 'shares');
assert.equal(value.path, '/files/c#/p.cs');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.equal(value.fsPath, isWindows ? '\\\\shares\\files\\c#\\p.cs' : '//shares/files/c#/p.cs');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, 'shares');
assert.strictEqual(value.path, '/files/c#/p.cs');
assert.strictEqual(value.fragment, '');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fsPath, isWindows ? '\\\\shares\\files\\c#\\p.cs' : '//shares/files/c#/p.cs');
value = URI.parse('file:///c:/Source/Z%C3%BCrich%20or%20Zurich%20(%CB%88zj%CA%8A%C9%99r%C9%AAk,/Code/resources/app/plugins/c%23/plugin.json');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/c:/Source/Zürich or Zurich (ˈzjʊərɪk,/Code/resources/app/plugins/c#/plugin.json');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/c:/Source/Zürich or Zurich (ˈzjʊərɪk,/Code/resources/app/plugins/c#/plugin.json');
assert.strictEqual(value.fragment, '');
assert.strictEqual(value.query, '');
value = URI.parse('file:///c:/test %25/path');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/c:/test %/path');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/c:/test %/path');
assert.strictEqual(value.fragment, '');
assert.strictEqual(value.query, '');
value = URI.parse('inmemory:');
assert.equal(value.scheme, 'inmemory');
assert.equal(value.authority, '');
assert.equal(value.path, '');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'inmemory');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, '');
value = URI.parse('foo:api/files/test');
assert.equal(value.scheme, 'foo');
assert.equal(value.authority, '');
assert.equal(value.path, 'api/files/test');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'foo');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, 'api/files/test');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, '');
value = URI.parse('file:?q');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/');
assert.equal(value.query, 'q');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/');
assert.strictEqual(value.query, 'q');
assert.strictEqual(value.fragment, '');
value = URI.parse('file:#d');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/');
assert.equal(value.query, '');
assert.equal(value.fragment, 'd');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, 'd');
value = URI.parse('f3ile:#d');
assert.equal(value.scheme, 'f3ile');
assert.equal(value.authority, '');
assert.equal(value.path, '');
assert.equal(value.query, '');
assert.equal(value.fragment, 'd');
assert.strictEqual(value.scheme, 'f3ile');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, 'd');
value = URI.parse('foo+bar:path');
assert.equal(value.scheme, 'foo+bar');
assert.equal(value.authority, '');
assert.equal(value.path, 'path');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'foo+bar');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, 'path');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, '');
value = URI.parse('foo-bar:path');
assert.equal(value.scheme, 'foo-bar');
assert.equal(value.authority, '');
assert.equal(value.path, 'path');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'foo-bar');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, 'path');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, '');
value = URI.parse('foo.bar:path');
assert.equal(value.scheme, 'foo.bar');
assert.equal(value.authority, '');
assert.equal(value.path, 'path');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
assert.strictEqual(value.scheme, 'foo.bar');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, 'path');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, '');
});
test('parse, disallow //path when no authority', () => {
@@ -237,132 +237,132 @@ suite('URI', () => {
test('URI#file, win-speciale', () => {
if (isWindows) {
let value = URI.file('c:\\test\\drive');
assert.equal(value.path, '/c:/test/drive');
assert.equal(value.toString(), 'file:///c%3A/test/drive');
assert.strictEqual(value.path, '/c:/test/drive');
assert.strictEqual(value.toString(), 'file:///c%3A/test/drive');
value = URI.file('\\\\shäres\\path\\c#\\plugin.json');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, 'shäres');
assert.equal(value.path, '/path/c#/plugin.json');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.equal(value.toString(), 'file://sh%C3%A4res/path/c%23/plugin.json');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, 'shäres');
assert.strictEqual(value.path, '/path/c#/plugin.json');
assert.strictEqual(value.fragment, '');
assert.strictEqual(value.query, '');
assert.strictEqual(value.toString(), 'file://sh%C3%A4res/path/c%23/plugin.json');
value = URI.file('\\\\localhost\\c$\\GitDevelopment\\express');
assert.equal(value.scheme, 'file');
assert.equal(value.path, '/c$/GitDevelopment/express');
assert.equal(value.fsPath, '\\\\localhost\\c$\\GitDevelopment\\express');
assert.equal(value.query, '');
assert.equal(value.fragment, '');
assert.equal(value.toString(), 'file://localhost/c%24/GitDevelopment/express');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.path, '/c$/GitDevelopment/express');
assert.strictEqual(value.fsPath, '\\\\localhost\\c$\\GitDevelopment\\express');
assert.strictEqual(value.query, '');
assert.strictEqual(value.fragment, '');
assert.strictEqual(value.toString(), 'file://localhost/c%24/GitDevelopment/express');
value = URI.file('c:\\test with %\\path');
assert.equal(value.path, '/c:/test with %/path');
assert.equal(value.toString(), 'file:///c%3A/test%20with%20%25/path');
assert.strictEqual(value.path, '/c:/test with %/path');
assert.strictEqual(value.toString(), 'file:///c%3A/test%20with%20%25/path');
value = URI.file('c:\\test with %25\\path');
assert.equal(value.path, '/c:/test with %25/path');
assert.equal(value.toString(), 'file:///c%3A/test%20with%20%2525/path');
assert.strictEqual(value.path, '/c:/test with %25/path');
assert.strictEqual(value.toString(), 'file:///c%3A/test%20with%20%2525/path');
value = URI.file('c:\\test with %25\\c#code');
assert.equal(value.path, '/c:/test with %25/c#code');
assert.equal(value.toString(), 'file:///c%3A/test%20with%20%2525/c%23code');
assert.strictEqual(value.path, '/c:/test with %25/c#code');
assert.strictEqual(value.toString(), 'file:///c%3A/test%20with%20%2525/c%23code');
value = URI.file('\\\\shares');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, 'shares');
assert.equal(value.path, '/'); // slash is always there
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, 'shares');
assert.strictEqual(value.path, '/'); // slash is always there
value = URI.file('\\\\shares\\');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, 'shares');
assert.equal(value.path, '/');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, 'shares');
assert.strictEqual(value.path, '/');
}
});
test('VSCode URI module\'s driveLetterPath regex is incorrect, #32961', function () {
let uri = URI.parse('file:///_:/path');
assert.equal(uri.fsPath, isWindows ? '\\_:\\path' : '/_:/path');
assert.strictEqual(uri.fsPath, isWindows ? '\\_:\\path' : '/_:/path');
});
test('URI#file, no path-is-uri check', () => {
// we don't complain here
let value = URI.file('file://path/to/file');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/file://path/to/file');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/file://path/to/file');
});
test('URI#file, always slash', () => {
let value = URI.file('a.file');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/a.file');
assert.equal(value.toString(), 'file:///a.file');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/a.file');
assert.strictEqual(value.toString(), 'file:///a.file');
value = URI.parse(value.toString());
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/a.file');
assert.equal(value.toString(), 'file:///a.file');
assert.strictEqual(value.scheme, 'file');
assert.strictEqual(value.authority, '');
assert.strictEqual(value.path, '/a.file');
assert.strictEqual(value.toString(), 'file:///a.file');
});
test('URI.toString, only scheme and query', () => {
const value = URI.parse('stuff:?qüery');
assert.equal(value.toString(), 'stuff:?q%C3%BCery');
assert.strictEqual(value.toString(), 'stuff:?q%C3%BCery');
});
test('URI#toString, upper-case percent espaces', () => {
const value = URI.parse('file://sh%c3%a4res/path');
assert.equal(value.toString(), 'file://sh%C3%A4res/path');
assert.strictEqual(value.toString(), 'file://sh%C3%A4res/path');
});
test('URI#toString, lower-case windows drive letter', () => {
assert.equal(URI.parse('untitled:c:/Users/jrieken/Code/abc.txt').toString(), 'untitled:c%3A/Users/jrieken/Code/abc.txt');
assert.equal(URI.parse('untitled:C:/Users/jrieken/Code/abc.txt').toString(), 'untitled:c%3A/Users/jrieken/Code/abc.txt');
assert.strictEqual(URI.parse('untitled:c:/Users/jrieken/Code/abc.txt').toString(), 'untitled:c%3A/Users/jrieken/Code/abc.txt');
assert.strictEqual(URI.parse('untitled:C:/Users/jrieken/Code/abc.txt').toString(), 'untitled:c%3A/Users/jrieken/Code/abc.txt');
});
test('URI#toString, escape all the bits', () => {
const value = URI.file('/Users/jrieken/Code/_samples/18500/Mödel + Other Thîngß/model.js');
assert.equal(value.toString(), 'file:///Users/jrieken/Code/_samples/18500/M%C3%B6del%20%2B%20Other%20Th%C3%AEng%C3%9F/model.js');
assert.strictEqual(value.toString(), 'file:///Users/jrieken/Code/_samples/18500/M%C3%B6del%20%2B%20Other%20Th%C3%AEng%C3%9F/model.js');
});
test('URI#toString, don\'t encode port', () => {
let value = URI.parse('http://localhost:8080/far');
assert.equal(value.toString(), 'http://localhost:8080/far');
assert.strictEqual(value.toString(), 'http://localhost:8080/far');
value = URI.from({ scheme: 'http', authority: 'löcalhost:8080', path: '/far', query: undefined, fragment: undefined });
assert.equal(value.toString(), 'http://l%C3%B6calhost:8080/far');
assert.strictEqual(value.toString(), 'http://l%C3%B6calhost:8080/far');
});
test('URI#toString, user information in authority', () => {
let value = URI.parse('http://foo:bar@localhost/far');
assert.equal(value.toString(), 'http://foo:bar@localhost/far');
assert.strictEqual(value.toString(), 'http://foo:bar@localhost/far');
value = URI.parse('http://foo@localhost/far');
assert.equal(value.toString(), 'http://foo@localhost/far');
assert.strictEqual(value.toString(), 'http://foo@localhost/far');
value = URI.parse('http://foo:bAr@localhost:8080/far');
assert.equal(value.toString(), 'http://foo:bAr@localhost:8080/far');
assert.strictEqual(value.toString(), 'http://foo:bAr@localhost:8080/far');
value = URI.parse('http://foo@localhost:8080/far');
assert.equal(value.toString(), 'http://foo@localhost:8080/far');
assert.strictEqual(value.toString(), 'http://foo@localhost:8080/far');
value = URI.from({ scheme: 'http', authority: 'föö:bör@löcalhost:8080', path: '/far', query: undefined, fragment: undefined });
assert.equal(value.toString(), 'http://f%C3%B6%C3%B6:b%C3%B6r@l%C3%B6calhost:8080/far');
assert.strictEqual(value.toString(), 'http://f%C3%B6%C3%B6:b%C3%B6r@l%C3%B6calhost:8080/far');
});
test('correctFileUriToFilePath2', () => {
const test = (input: string, expected: string) => {
const value = URI.parse(input);
assert.equal(value.fsPath, expected, 'Result for ' + input);
assert.strictEqual(value.fsPath, expected, 'Result for ' + input);
const value2 = URI.file(value.fsPath);
assert.equal(value2.fsPath, expected, 'Result for ' + input);
assert.equal(value.toString(), value2.toString());
assert.strictEqual(value2.fsPath, expected, 'Result for ' + input);
assert.strictEqual(value.toString(), value2.toString());
};
test('file:///c:/alex.txt', isWindows ? 'c:\\alex.txt' : 'c:/alex.txt');
@@ -374,104 +374,132 @@ suite('URI', () => {
test('URI - http, query & toString', function () {
let uri = URI.parse('https://go.microsoft.com/fwlink/?LinkId=518008');
assert.equal(uri.query, 'LinkId=518008');
assert.equal(uri.toString(true), 'https://go.microsoft.com/fwlink/?LinkId=518008');
assert.equal(uri.toString(), 'https://go.microsoft.com/fwlink/?LinkId%3D518008');
assert.strictEqual(uri.query, 'LinkId=518008');
assert.strictEqual(uri.toString(true), 'https://go.microsoft.com/fwlink/?LinkId=518008');
assert.strictEqual(uri.toString(), 'https://go.microsoft.com/fwlink/?LinkId%3D518008');
let uri2 = URI.parse(uri.toString());
assert.equal(uri2.query, 'LinkId=518008');
assert.equal(uri2.query, uri.query);
assert.strictEqual(uri2.query, 'LinkId=518008');
assert.strictEqual(uri2.query, uri.query);
uri = URI.parse('https://go.microsoft.com/fwlink/?LinkId=518008&foö&ké¥=üü');
assert.equal(uri.query, 'LinkId=518008&foö&ké¥=üü');
assert.equal(uri.toString(true), 'https://go.microsoft.com/fwlink/?LinkId=518008&foö&ké¥=üü');
assert.equal(uri.toString(), 'https://go.microsoft.com/fwlink/?LinkId%3D518008%26fo%C3%B6%26k%C3%A9%C2%A5%3D%C3%BC%C3%BC');
assert.strictEqual(uri.query, 'LinkId=518008&foö&ké¥=üü');
assert.strictEqual(uri.toString(true), 'https://go.microsoft.com/fwlink/?LinkId=518008&foö&ké¥=üü');
assert.strictEqual(uri.toString(), 'https://go.microsoft.com/fwlink/?LinkId%3D518008%26fo%C3%B6%26k%C3%A9%C2%A5%3D%C3%BC%C3%BC');
uri2 = URI.parse(uri.toString());
assert.equal(uri2.query, 'LinkId=518008&foö&ké¥=üü');
assert.equal(uri2.query, uri.query);
assert.strictEqual(uri2.query, 'LinkId=518008&foö&ké¥=üü');
assert.strictEqual(uri2.query, uri.query);
// #24849
uri = URI.parse('https://twitter.com/search?src=typd&q=%23tag');
assert.equal(uri.toString(true), 'https://twitter.com/search?src=typd&q=%23tag');
assert.strictEqual(uri.toString(true), 'https://twitter.com/search?src=typd&q=%23tag');
});
test('class URI cannot represent relative file paths #34449', function () {
let path = '/foo/bar';
assert.equal(URI.file(path).path, path);
assert.strictEqual(URI.file(path).path, path);
path = 'foo/bar';
assert.equal(URI.file(path).path, '/foo/bar');
assert.strictEqual(URI.file(path).path, '/foo/bar');
path = './foo/bar';
assert.equal(URI.file(path).path, '/./foo/bar'); // missing normalization
assert.strictEqual(URI.file(path).path, '/./foo/bar'); // missing normalization
const fileUri1 = URI.parse(`file:foo/bar`);
assert.equal(fileUri1.path, '/foo/bar');
assert.equal(fileUri1.authority, '');
assert.strictEqual(fileUri1.path, '/foo/bar');
assert.strictEqual(fileUri1.authority, '');
const uri = fileUri1.toString();
assert.equal(uri, 'file:///foo/bar');
assert.strictEqual(uri, 'file:///foo/bar');
const fileUri2 = URI.parse(uri);
assert.equal(fileUri2.path, '/foo/bar');
assert.equal(fileUri2.authority, '');
assert.strictEqual(fileUri2.path, '/foo/bar');
assert.strictEqual(fileUri2.authority, '');
});
test('Ctrl click to follow hash query param url gets urlencoded #49628', function () {
let input = 'http://localhost:3000/#/foo?bar=baz';
let uri = URI.parse(input);
assert.equal(uri.toString(true), input);
assert.strictEqual(uri.toString(true), input);
input = 'http://localhost:3000/foo?bar=baz';
uri = URI.parse(input);
assert.equal(uri.toString(true), input);
assert.strictEqual(uri.toString(true), input);
});
test('Unable to open \'%A0.txt\': URI malformed #76506', function () {
let uri = URI.file('/foo/%A0.txt');
let uri2 = URI.parse(uri.toString());
assert.equal(uri.scheme, uri2.scheme);
assert.equal(uri.path, uri2.path);
assert.strictEqual(uri.scheme, uri2.scheme);
assert.strictEqual(uri.path, uri2.path);
uri = URI.file('/foo/%2e.txt');
uri2 = URI.parse(uri.toString());
assert.equal(uri.scheme, uri2.scheme);
assert.equal(uri.path, uri2.path);
assert.strictEqual(uri.scheme, uri2.scheme);
assert.strictEqual(uri.path, uri2.path);
});
test('Bug in URI.isUri() that fails `thing` type comparison #114971', function () {
const uri = URI.file('/foo/bazz.txt');
assert.strictEqual(URI.isUri(uri), true);
assert.strictEqual(URI.isUri(uri.toJSON()), false);
// fsPath -> getter
assert.strictEqual(URI.isUri({
scheme: 'file',
authority: '',
path: '/foo/bazz.txt',
get fsPath() { return '/foo/bazz.txt'; },
query: '',
fragment: '',
with() { return this; },
toString() { return ''; }
}), true);
// fsPath -> property
assert.strictEqual(URI.isUri({
scheme: 'file',
authority: '',
path: '/foo/bazz.txt',
fsPath: '/foo/bazz.txt',
query: '',
fragment: '',
with() { return this; },
toString() { return ''; }
}), true);
});
test('Unable to open \'%A0.txt\': URI malformed #76506', function () {
assert.equal(URI.parse('file://some/%.txt'), 'file://some/%25.txt');
assert.equal(URI.parse('file://some/%A0.txt'), 'file://some/%25A0.txt');
assert.strictEqual(URI.parse('file://some/%.txt').toString(), 'file://some/%25.txt');
assert.strictEqual(URI.parse('file://some/%A0.txt').toString(), 'file://some/%25A0.txt');
});
test('Links in markdown are broken if url contains encoded parameters #79474', function () {
this.skip();
test.skip('Links in markdown are broken if url contains encoded parameters #79474', function () {
let strIn = 'https://myhost.com/Redirect?url=http%3A%2F%2Fwww.bing.com%3Fsearch%3Dtom';
let uri1 = URI.parse(strIn);
let strOut = uri1.toString();
let uri2 = URI.parse(strOut);
assert.equal(uri1.scheme, uri2.scheme);
assert.equal(uri1.authority, uri2.authority);
assert.equal(uri1.path, uri2.path);
assert.equal(uri1.query, uri2.query);
assert.equal(uri1.fragment, uri2.fragment);
assert.equal(strIn, strOut); // fails here!!
assert.strictEqual(uri1.scheme, uri2.scheme);
assert.strictEqual(uri1.authority, uri2.authority);
assert.strictEqual(uri1.path, uri2.path);
assert.strictEqual(uri1.query, uri2.query);
assert.strictEqual(uri1.fragment, uri2.fragment);
assert.strictEqual(strIn, strOut); // fails here!!
});
test('Uri#parse can break path-component #45515', function () {
this.skip();
test.skip('Uri#parse can break path-component #45515', function () {
let strIn = 'https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437';
let uri1 = URI.parse(strIn);
let strOut = uri1.toString();
let uri2 = URI.parse(strOut);
assert.equal(uri1.scheme, uri2.scheme);
assert.equal(uri1.authority, uri2.authority);
assert.equal(uri1.path, uri2.path);
assert.equal(uri1.query, uri2.query);
assert.equal(uri1.fragment, uri2.fragment);
assert.equal(strIn, strOut); // fails here!!
assert.strictEqual(uri1.scheme, uri2.scheme);
assert.strictEqual(uri1.authority, uri2.authority);
assert.strictEqual(uri1.path, uri2.path);
assert.strictEqual(uri1.query, uri2.query);
assert.strictEqual(uri1.fragment, uri2.fragment);
assert.strictEqual(strIn, strOut); // fails here!!
});
test('URI - (de)serialize', function () {
@@ -492,13 +520,13 @@ suite('URI', () => {
let data = value.toJSON() as UriComponents;
let clone = URI.revive(data);
assert.equal(clone.scheme, value.scheme);
assert.equal(clone.authority, value.authority);
assert.equal(clone.path, value.path);
assert.equal(clone.query, value.query);
assert.equal(clone.fragment, value.fragment);
assert.equal(clone.fsPath, value.fsPath);
assert.equal(clone.toString(), value.toString());
assert.strictEqual(clone.scheme, value.scheme);
assert.strictEqual(clone.authority, value.authority);
assert.strictEqual(clone.path, value.path);
assert.strictEqual(clone.query, value.query);
assert.strictEqual(clone.fragment, value.fragment);
assert.strictEqual(clone.fsPath, value.fsPath);
assert.strictEqual(clone.toString(), value.toString());
}
// }
// console.profileEnd();
@@ -507,11 +535,11 @@ suite('URI', () => {
const baseUri = URI.parse(base);
const newUri = URI.joinPath(baseUri, fragment);
const actual = newUri.toString(true);
assert.equal(actual, expected);
assert.strictEqual(actual, expected);
if (checkWithUrl) {
const actualUrl = new URL(fragment, base).href;
assert.equal(actualUrl, expected, 'DIFFERENT from URL');
assert.strictEqual(actualUrl, expected, 'DIFFERENT from URL');
}
}
test('URI#joinPath', function () {

View File

@@ -5,47 +5,10 @@
import { join } from 'vs/base/common/path';
import { URI } from 'vs/base/common/uri';
import { canceled } from 'vs/base/common/errors';
import { isWindows } from 'vs/base/common/platform';
export type ValueCallback<T = any> = (value: T | Promise<T>) => void;
export class DeferredPromise<T> {
private completeCallback!: ValueCallback<T>;
private errorCallback!: (err: any) => void;
public p: Promise<any>;
constructor() {
this.p = new Promise<any>((c, e) => {
this.completeCallback = c;
this.errorCallback = e;
});
}
public complete(value: T) {
return new Promise<void>(resolve => {
this.completeCallback(value);
resolve();
});
}
public error(err: any) {
return new Promise<void>(resolve => {
this.errorCallback(err);
resolve();
});
}
public cancel() {
new Promise<void>(resolve => {
this.errorCallback(canceled());
resolve();
});
}
}
export function toResource(this: any, path: string) {
if (isWindows) {
return URI.file(join('C:\\', btoa(this.test.fullTitle()), path));
@@ -60,7 +23,7 @@ export function suiteRepeat(n: number, description: string, callback: (this: any
}
}
export function testRepeat(n: number, description: string, callback: (this: any, done: MochaDone) => any): void {
export function testRepeat(n: number, description: string, callback: (this: any) => any): void {
for (let i = 0; i < n; i++) {
test(`${description} (iteration ${i})`, callback);
}

View File

@@ -8,8 +8,8 @@ import * as uuid from 'vs/base/common/uuid';
suite('UUID', () => {
test('generation', () => {
const asHex = uuid.generateUuid();
assert.equal(asHex.length, 36);
assert.equal(asHex[14], '4');
assert.strictEqual(asHex.length, 36);
assert.strictEqual(asHex[14], '4');
assert.ok(asHex[19] === '8' || asHex[19] === '9' || asHex[19] === 'a' || asHex[19] === 'b');
});

View File

@@ -4,24 +4,29 @@
*--------------------------------------------------------------------------------------------*/
import { checksum } from 'vs/base/node/crypto';
import { generateUuid } from 'vs/base/common/uuid';
import { join } from 'vs/base/common/path';
import { tmpdir } from 'os';
import { mkdirp, rimraf, RimRafMode, writeFile } from 'vs/base/node/pfs';
import { mkdirp, rimraf, writeFile } from 'vs/base/node/pfs';
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
suite('Crypto', () => {
let testDir: string;
setup(function () {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'crypto');
return mkdirp(testDir);
});
teardown(function () {
return rimraf(testDir);
});
test('checksum', async () => {
const id = generateUuid();
const testDir = join(tmpdir(), 'vsctests', id);
const testFile = join(testDir, 'checksum.txt');
await mkdirp(testDir);
await writeFile(testFile, 'Hello World');
await checksum(testFile, '0a4d55a8d778e5022fab701977c5d840bbc486d0');
await rimraf(testDir, RimRafMode.MOVE);
});
});

View File

@@ -4,19 +4,19 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as decoder from 'vs/base/node/decoder';
import { LineDecoder } from 'vs/base/node/decoder';
suite('Decoder', () => {
test('decoding', () => {
const lineDecoder = new decoder.LineDecoder();
const lineDecoder = new LineDecoder();
let res = lineDecoder.write(Buffer.from('hello'));
assert.equal(res.length, 0);
assert.strictEqual(res.length, 0);
res = lineDecoder.write(Buffer.from('\nworld'));
assert.equal(res[0], 'hello');
assert.equal(res.length, 1);
assert.strictEqual(res[0], 'hello');
assert.strictEqual(res.length, 1);
assert.equal(lineDecoder.end(), 'world');
assert.strictEqual(lineDecoder.end(), 'world');
});
});
});

View File

@@ -4,70 +4,52 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as os from 'os';
import * as path from 'vs/base/common/path';
import * as uuid from 'vs/base/common/uuid';
import * as pfs from 'vs/base/node/pfs';
import { tmpdir } from 'os';
import { mkdirp, rimraf } from 'vs/base/node/pfs';
import { realcaseSync, realpath, realpathSync } from 'vs/base/node/extpath';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
suite('Extpath', () => {
flakySuite('Extpath', () => {
let testDir: string;
setup(() => {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'extpath');
return mkdirp(testDir, 493);
});
teardown(() => {
return rimraf(testDir);
});
test('realcase', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extpath', id);
await pfs.mkdirp(newDir, 493);
// assume case insensitive file system
if (process.platform === 'win32' || process.platform === 'darwin') {
const upper = newDir.toUpperCase();
const upper = testDir.toUpperCase();
const real = realcaseSync(upper);
if (real) { // can be null in case of permission errors
assert.notEqual(real, upper);
assert.equal(real.toUpperCase(), upper);
assert.equal(real, newDir);
assert.notStrictEqual(real, upper);
assert.strictEqual(real.toUpperCase(), upper);
assert.strictEqual(real, testDir);
}
}
// linux, unix, etc. -> assume case sensitive file system
else {
const real = realcaseSync(newDir);
assert.equal(real, newDir);
const real = realcaseSync(testDir);
assert.strictEqual(real, testDir);
}
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
});
test('realpath', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extpath', id);
await pfs.mkdirp(newDir, 493);
const realpathVal = await realpath(newDir);
const realpathVal = await realpath(testDir);
assert.ok(realpathVal);
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
});
test('realpathSync', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extpath', id);
await pfs.mkdirp(newDir, 493);
let realpath!: string;
try {
realpath = realpathSync(newDir);
} catch (error) {
assert.ok(!error);
}
assert.ok(realpath!);
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
test('realpathSync', () => {
const realpath = realpathSync(testDir);
assert.ok(realpath);
});
});

View File

@@ -2,22 +2,21 @@
* 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 { getMachineId } from 'vs/base/node/id';
import { getMac } from 'vs/base/node/macAddress';
import { flakySuite } from 'vs/base/test/node/testUtils';
suite('ID', () => {
flakySuite('ID', () => {
test('getMachineId', function () {
this.timeout(20000);
return getMachineId().then(id => {
assert.ok(id);
});
test('getMachineId', async function () {
const id = await getMachineId();
assert.ok(id);
});
test('getMac', () => {
return getMac().then(macAddress => {
assert.ok(/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(macAddress), `Expected a MAC address, got: ${macAddress}`);
});
test('getMac', async () => {
const macAddress = await getMac();
assert.ok(/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(macAddress), `Expected a MAC address, got: ${macAddress}`);
});
});
});

View File

@@ -2,36 +2,30 @@
* 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 platform from 'vs/base/common/platform';
import { isLinux } from 'vs/base/common/platform';
suite('Keytar', () => {
test('loads and is functional', function (done) {
if (platform.isLinux) {
// Skip test due to set up issue with Travis.
this.skip();
return;
}
(async () => {
const keytar = await import('keytar');
const name = `VSCode Test ${Math.floor(Math.random() * 1e9)}`;
(isLinux ? test.skip : test)('loads and is functional', async () => { // TODO@RMacfarlane test seems to fail on Linux (Error: Unknown or unsupported transport 'disabled' for address 'disabled:')
const keytar = await import('keytar');
const name = `VSCode Test ${Math.floor(Math.random() * 1e9)}`;
try {
await keytar.setPassword(name, 'foo', 'bar');
assert.strictEqual(await keytar.findPassword(name), 'bar');
assert.strictEqual((await keytar.findCredentials(name)).length, 1);
assert.strictEqual(await keytar.getPassword(name, 'foo'), 'bar');
await keytar.deletePassword(name, 'foo');
assert.strictEqual(await keytar.getPassword(name, 'foo'), null);
} catch (err) {
// try to clean up
try {
await keytar.setPassword(name, 'foo', 'bar');
assert.equal(await keytar.findPassword(name), 'bar');
assert.equal((await keytar.findCredentials(name)).length, 1);
assert.equal(await keytar.getPassword(name, 'foo'), 'bar');
await keytar.deletePassword(name, 'foo');
assert.equal(await keytar.getPassword(name, 'foo'), undefined);
} catch (err) {
// try to clean up
try {
await keytar.deletePassword(name, 'foo');
} finally {
// eslint-disable-next-line no-unsafe-finally
throw err;
}
} finally {
// eslint-disable-next-line no-unsafe-finally
throw err;
}
})().then(done, done);
}
});
});

View File

@@ -4,388 +4,306 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as os from 'os';
import * as path from 'vs/base/common/path';
import * as fs from 'fs';
import * as uuid from 'vs/base/common/uuid';
import * as pfs from 'vs/base/node/pfs';
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 { timeout } from 'vs/base/common/async';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { isWindows } from 'vs/base/common/platform';
import { canNormalize } from 'vs/base/common/normalization';
import { VSBuffer } from 'vs/base/common/buffer';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
suite('PFS', function () {
flakySuite('PFS', function () {
// Given issues such as https://github.com/microsoft/vscode/issues/84066
// we see random test failures when accessing the native file system. To
// diagnose further, we retry node.js file access tests up to 3 times to
// rule out any random disk issue.
this.retries(3);
let testDir: string;
setup(() => {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
return mkdirp(testDir, 493);
});
teardown(() => {
return rimraf(testDir);
});
test('writeFile', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'writefile.txt');
const testFile = join(testDir, 'writefile.txt');
await pfs.mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
assert.ok(!(await exists(testFile)));
await pfs.writeFile(testFile, 'Hello World', (null!));
assert.equal(fs.readFileSync(testFile), 'Hello World');
await writeFile(testFile, 'Hello World', (null!));
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
assert.strictEqual((await readFile(testFile)).toString(), 'Hello World');
});
test('writeFile - parallel write on different files works', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile1 = path.join(newDir, 'writefile1.txt');
const testFile2 = path.join(newDir, 'writefile2.txt');
const testFile3 = path.join(newDir, 'writefile3.txt');
const testFile4 = path.join(newDir, 'writefile4.txt');
const testFile5 = path.join(newDir, 'writefile5.txt');
await pfs.mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
const testFile1 = join(testDir, 'writefile1.txt');
const testFile2 = join(testDir, 'writefile2.txt');
const testFile3 = join(testDir, 'writefile3.txt');
const testFile4 = join(testDir, 'writefile4.txt');
const testFile5 = join(testDir, 'writefile5.txt');
await Promise.all([
pfs.writeFile(testFile1, 'Hello World 1', (null!)),
pfs.writeFile(testFile2, 'Hello World 2', (null!)),
pfs.writeFile(testFile3, 'Hello World 3', (null!)),
pfs.writeFile(testFile4, 'Hello World 4', (null!)),
pfs.writeFile(testFile5, 'Hello World 5', (null!))
writeFile(testFile1, 'Hello World 1', (null!)),
writeFile(testFile2, 'Hello World 2', (null!)),
writeFile(testFile3, 'Hello World 3', (null!)),
writeFile(testFile4, 'Hello World 4', (null!)),
writeFile(testFile5, 'Hello World 5', (null!))
]);
assert.equal(fs.readFileSync(testFile1), 'Hello World 1');
assert.equal(fs.readFileSync(testFile2), 'Hello World 2');
assert.equal(fs.readFileSync(testFile3), 'Hello World 3');
assert.equal(fs.readFileSync(testFile4), 'Hello World 4');
assert.equal(fs.readFileSync(testFile5), 'Hello World 5');
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
assert.strictEqual(fs.readFileSync(testFile1).toString(), 'Hello World 1');
assert.strictEqual(fs.readFileSync(testFile2).toString(), 'Hello World 2');
assert.strictEqual(fs.readFileSync(testFile3).toString(), 'Hello World 3');
assert.strictEqual(fs.readFileSync(testFile4).toString(), 'Hello World 4');
assert.strictEqual(fs.readFileSync(testFile5).toString(), 'Hello World 5');
});
test('writeFile - parallel write on same files works and is sequentalized', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'writefile.txt');
await pfs.mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
const testFile = join(testDir, 'writefile.txt');
await Promise.all([
pfs.writeFile(testFile, 'Hello World 1', undefined),
pfs.writeFile(testFile, 'Hello World 2', undefined),
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', undefined)),
pfs.writeFile(testFile, 'Hello World 4', undefined),
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', undefined))
writeFile(testFile, 'Hello World 1', undefined),
writeFile(testFile, 'Hello World 2', undefined),
timeout(10).then(() => writeFile(testFile, 'Hello World 3', undefined)),
writeFile(testFile, 'Hello World 4', undefined),
timeout(10).then(() => writeFile(testFile, 'Hello World 5', undefined))
]);
assert.equal(fs.readFileSync(testFile), 'Hello World 5');
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
assert.strictEqual(fs.readFileSync(testFile).toString(), 'Hello World 5');
});
test('rimraf - simple - unlink', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
await pfs.rimraf(newDir);
assert.ok(!fs.existsSync(newDir));
await rimraf(testDir);
assert.ok(!fs.existsSync(testDir));
});
test('rimraf - simple - move', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
await pfs.rimraf(newDir, pfs.RimRafMode.MOVE);
assert.ok(!fs.existsSync(newDir));
await rimraf(testDir, RimRafMode.MOVE);
assert.ok(!fs.existsSync(testDir));
});
test('rimraf - recursive folder structure - unlink', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(join(testDir, 'somefolder'));
fs.writeFileSync(join(testDir, 'somefolder', 'somefile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(path.join(newDir, 'somefolder'));
fs.writeFileSync(path.join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
await pfs.rimraf(newDir);
assert.ok(!fs.existsSync(newDir));
await rimraf(testDir);
assert.ok(!fs.existsSync(testDir));
});
test('rimraf - recursive folder structure - move', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(join(testDir, 'somefolder'));
fs.writeFileSync(join(testDir, 'somefolder', 'somefile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(path.join(newDir, 'somefolder'));
fs.writeFileSync(path.join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
await pfs.rimraf(newDir, pfs.RimRafMode.MOVE);
assert.ok(!fs.existsSync(newDir));
await rimraf(testDir, RimRafMode.MOVE);
assert.ok(!fs.existsSync(testDir));
});
test('rimraf - simple ends with dot - move', async () => {
const id = `${uuid.generateUuid()}.`;
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
await pfs.rimraf(newDir, pfs.RimRafMode.MOVE);
assert.ok(!fs.existsSync(newDir));
await rimraf(testDir, RimRafMode.MOVE);
assert.ok(!fs.existsSync(testDir));
});
test('rimraf - simple ends with dot slash/backslash - move', async () => {
const id = `${uuid.generateUuid()}.`;
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
await pfs.rimraf(`${newDir}${path.sep}`, pfs.RimRafMode.MOVE);
assert.ok(!fs.existsSync(newDir));
await rimraf(`${testDir}${sep}`, RimRafMode.MOVE);
assert.ok(!fs.existsSync(testDir));
});
test('rimrafSync - swallows file not found error', function () {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const nonExistingDir = join(testDir, 'not-existing');
rimrafSync(nonExistingDir);
pfs.rimrafSync(newDir);
assert.ok(!fs.existsSync(newDir));
assert.ok(!fs.existsSync(nonExistingDir));
});
test('rimrafSync - simple', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
rimrafSync(testDir);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
pfs.rimrafSync(newDir);
assert.ok(!fs.existsSync(newDir));
assert.ok(!fs.existsSync(testDir));
});
test('rimrafSync - recursive folder structure', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(join(testDir, 'somefolder'));
fs.writeFileSync(join(testDir, 'somefolder', 'somefile.txt'), 'Contents');
fs.mkdirSync(path.join(newDir, 'somefolder'));
fs.writeFileSync(path.join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
rimrafSync(testDir);
pfs.rimrafSync(newDir);
assert.ok(!fs.existsSync(newDir));
assert.ok(!fs.existsSync(testDir));
});
test('moveIgnoreError', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
await pfs.mkdirp(newDir, 493);
try {
await pfs.renameIgnoreError(path.join(newDir, 'foo'), path.join(newDir, 'bar'));
return pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
}
catch (error) {
assert.fail(error);
}
test('moveIgnoreError', () => {
return renameIgnoreError(join(testDir, 'foo'), join(testDir, 'bar'));
});
test('copy, move and delete', async () => {
const id = uuid.generateUuid();
const id2 = uuid.generateUuid();
const id = generateUuid();
const id2 = generateUuid();
const sourceDir = getPathFromAmdModule(require, './fixtures');
const parentDir = path.join(os.tmpdir(), 'vsctests', 'pfs');
const targetDir = path.join(parentDir, id);
const targetDir2 = path.join(parentDir, id2);
const parentDir = join(tmpdir(), 'vsctests', 'pfs');
const targetDir = join(parentDir, id);
const targetDir2 = join(parentDir, id2);
await pfs.copy(sourceDir, targetDir);
await copy(sourceDir, targetDir);
assert.ok(fs.existsSync(targetDir));
assert.ok(fs.existsSync(path.join(targetDir, 'index.html')));
assert.ok(fs.existsSync(path.join(targetDir, 'site.css')));
assert.ok(fs.existsSync(path.join(targetDir, 'examples')));
assert.ok(fs.statSync(path.join(targetDir, 'examples')).isDirectory());
assert.ok(fs.existsSync(path.join(targetDir, 'examples', 'small.jxs')));
assert.ok(fs.existsSync(join(targetDir, 'index.html')));
assert.ok(fs.existsSync(join(targetDir, 'site.css')));
assert.ok(fs.existsSync(join(targetDir, 'examples')));
assert.ok(fs.statSync(join(targetDir, 'examples')).isDirectory());
assert.ok(fs.existsSync(join(targetDir, 'examples', 'small.jxs')));
await pfs.move(targetDir, targetDir2);
await move(targetDir, targetDir2);
assert.ok(!fs.existsSync(targetDir));
assert.ok(fs.existsSync(targetDir2));
assert.ok(fs.existsSync(path.join(targetDir2, 'index.html')));
assert.ok(fs.existsSync(path.join(targetDir2, 'site.css')));
assert.ok(fs.existsSync(path.join(targetDir2, 'examples')));
assert.ok(fs.statSync(path.join(targetDir2, 'examples')).isDirectory());
assert.ok(fs.existsSync(path.join(targetDir2, 'examples', 'small.jxs')));
assert.ok(fs.existsSync(join(targetDir2, 'index.html')));
assert.ok(fs.existsSync(join(targetDir2, 'site.css')));
assert.ok(fs.existsSync(join(targetDir2, 'examples')));
assert.ok(fs.statSync(join(targetDir2, 'examples')).isDirectory());
assert.ok(fs.existsSync(join(targetDir2, 'examples', 'small.jxs')));
await pfs.move(path.join(targetDir2, 'index.html'), path.join(targetDir2, 'index_moved.html'));
await move(join(targetDir2, 'index.html'), join(targetDir2, 'index_moved.html'));
assert.ok(!fs.existsSync(path.join(targetDir2, 'index.html')));
assert.ok(fs.existsSync(path.join(targetDir2, 'index_moved.html')));
assert.ok(!fs.existsSync(join(targetDir2, 'index.html')));
assert.ok(fs.existsSync(join(targetDir2, 'index_moved.html')));
await pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
await rimraf(parentDir);
assert.ok(!fs.existsSync(parentDir));
});
test('mkdirp', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
test('copy skips over dangling symbolic links', async () => {
const id1 = generateUuid();
const symbolicLinkTarget = join(testDir, id1);
await pfs.mkdirp(newDir, 493);
const id2 = generateUuid();
const symbolicLink = join(testDir, id2);
const id3 = generateUuid();
const copyTarget = join(testDir, id3);
await mkdirp(symbolicLinkTarget, 493);
fs.symlinkSync(symbolicLinkTarget, symbolicLink, 'junction');
await rimraf(symbolicLinkTarget);
await copy(symbolicLink, copyTarget); // this should not throw
assert.ok(!fs.existsSync(copyTarget));
});
test('mkdirp', async () => {
const newDir = join(testDir, generateUuid());
await mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
return pfs.rimraf(parentDir, pfs.RimRafMode.MOVE);
});
test('readDirsInDir', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
fs.mkdirSync(join(testDir, 'somefolder1'));
fs.mkdirSync(join(testDir, 'somefolder2'));
fs.mkdirSync(join(testDir, 'somefolder3'));
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
await pfs.mkdirp(newDir, 493);
fs.mkdirSync(path.join(newDir, 'somefolder1'));
fs.mkdirSync(path.join(newDir, 'somefolder2'));
fs.mkdirSync(path.join(newDir, 'somefolder3'));
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
const result = await pfs.readDirsInDir(newDir);
assert.equal(result.length, 3);
const result = await readDirsInDir(testDir);
assert.strictEqual(result.length, 3);
assert.ok(result.indexOf('somefolder1') !== -1);
assert.ok(result.indexOf('somefolder2') !== -1);
assert.ok(result.indexOf('somefolder3') !== -1);
await pfs.rimraf(newDir);
});
test('stat link', async () => {
if (isWindows) {
return; // Symlinks are not the same on win, and we can not create them programitically without admin privileges
}
const id1 = generateUuid();
const directory = join(testDir, id1);
const id1 = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id1);
const directory = path.join(parentDir, 'pfs', id1);
const id2 = generateUuid();
const symbolicLink = join(testDir, id2);
const id2 = uuid.generateUuid();
const symbolicLink = path.join(parentDir, 'pfs', id2);
await mkdirp(directory, 493);
await pfs.mkdirp(directory, 493);
fs.symlinkSync(directory, symbolicLink, 'junction');
fs.symlinkSync(directory, symbolicLink);
let statAndIsLink = await pfs.statLink(directory);
let statAndIsLink = await statLink(directory);
assert.ok(!statAndIsLink?.symbolicLink);
statAndIsLink = await pfs.statLink(symbolicLink);
statAndIsLink = await statLink(symbolicLink);
assert.ok(statAndIsLink?.symbolicLink);
assert.ok(!statAndIsLink?.symbolicLink?.dangling);
pfs.rimrafSync(directory);
});
test('stat link (non existing target)', async () => {
if (isWindows) {
return; // Symlinks are not the same on win, and we can not create them programitically without admin privileges
}
const id1 = generateUuid();
const directory = join(testDir, id1);
const id1 = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id1);
const directory = path.join(parentDir, 'pfs', id1);
const id2 = generateUuid();
const symbolicLink = join(testDir, id2);
const id2 = uuid.generateUuid();
const symbolicLink = path.join(parentDir, 'pfs', id2);
await mkdirp(directory, 493);
await pfs.mkdirp(directory, 493);
fs.symlinkSync(directory, symbolicLink, 'junction');
fs.symlinkSync(directory, symbolicLink);
await rimraf(directory);
pfs.rimrafSync(directory);
const statAndIsLink = await pfs.statLink(symbolicLink);
const statAndIsLink = await statLink(symbolicLink);
assert.ok(statAndIsLink?.symbolicLink);
assert.ok(statAndIsLink?.symbolicLink?.dangling);
});
test('readdir', async () => {
if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id, 'öäü');
const id = generateUuid();
const newDir = join(testDir, 'pfs', id, 'öäü');
await pfs.mkdirp(newDir, 493);
await mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
const children = await pfs.readdir(path.join(parentDir, 'pfs', id));
assert.equal(children.some(n => n === 'öäü'), true); // Mac always converts to NFD, so
await pfs.rimraf(parentDir);
const children = await readdir(join(testDir, 'pfs', id));
assert.strictEqual(children.some(n => n === 'öäü'), true); // Mac always converts to NFD, so
}
});
test('readdirWithFileTypes', async () => {
if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const testDir = path.join(parentDir, 'pfs', id);
const newDir = join(testDir, 'öäü');
await mkdirp(newDir, 493);
const newDir = path.join(testDir, 'öäü');
await pfs.mkdirp(newDir, 493);
await pfs.writeFile(path.join(testDir, 'somefile.txt'), 'contents');
await writeFile(join(testDir, 'somefile.txt'), 'contents');
assert.ok(fs.existsSync(newDir));
const children = await pfs.readdirWithFileTypes(testDir);
const children = await readdirWithFileTypes(testDir);
assert.equal(children.some(n => n.name === 'öäü'), true); // Mac always converts to NFD, so
assert.equal(children.some(n => n.isDirectory()), true);
assert.strictEqual(children.some(n => n.name === 'öäü'), true); // Mac always converts to NFD, so
assert.strictEqual(children.some(n => n.isDirectory()), true);
assert.equal(children.some(n => n.name === 'somefile.txt'), true);
assert.equal(children.some(n => n.isFile()), true);
await pfs.rimraf(parentDir);
assert.strictEqual(children.some(n => n.name === 'somefile.txt'), true);
assert.strictEqual(children.some(n => n.isFile()), true);
}
});
@@ -416,65 +334,41 @@ suite('PFS', function () {
bigData: string | Buffer | Uint8Array,
bigDataValue: string
): Promise<void> {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'flushed.txt');
const testFile = join(testDir, 'flushed.txt');
await pfs.mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
assert.ok(fs.existsSync(testDir));
await pfs.writeFile(testFile, smallData);
assert.equal(fs.readFileSync(testFile), smallDataValue);
await writeFile(testFile, smallData);
assert.strictEqual(fs.readFileSync(testFile).toString(), smallDataValue);
await pfs.writeFile(testFile, bigData);
assert.equal(fs.readFileSync(testFile), bigDataValue);
await pfs.rimraf(parentDir);
await writeFile(testFile, bigData);
assert.strictEqual(fs.readFileSync(testFile).toString(), bigDataValue);
}
test('writeFile (string, error handling)', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'flushed.txt');
const testFile = join(testDir, 'flushed.txt');
await pfs.mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
fs.mkdirSync(testFile); // this will trigger an error because testFile is now a directory!
fs.mkdirSync(testFile); // this will trigger an error later because testFile is now a directory!
let expectedError: Error | undefined;
try {
await pfs.writeFile(testFile, 'Hello World');
await writeFile(testFile, 'Hello World');
} catch (error) {
expectedError = error;
}
assert.ok(expectedError);
await pfs.rimraf(parentDir);
});
test('writeFileSync', async () => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'flushed.txt');
const testFile = join(testDir, 'flushed.txt');
await pfs.mkdirp(newDir, 493);
assert.ok(fs.existsSync(newDir));
pfs.writeFileSync(testFile, 'Hello World');
assert.equal(fs.readFileSync(testFile), 'Hello World');
writeFileSync(testFile, 'Hello World');
assert.strictEqual(fs.readFileSync(testFile).toString(), 'Hello World');
const largeString = (new Array(100 * 1024)).join('Large String\n');
pfs.writeFileSync(testFile, largeString);
assert.equal(fs.readFileSync(testFile), largeString);
await pfs.rimraf(parentDir);
writeFileSync(testFile, largeString);
assert.strictEqual(fs.readFileSync(testFile).toString(), largeString);
});
});

View File

@@ -6,14 +6,10 @@
import * as assert from 'assert';
import * as net from 'net';
import * as ports from 'vs/base/node/ports';
import { flakySuite } from 'vs/base/test/node/testUtils';
suite('Ports', () => {
test('Finds a free port (no timeout)', function (done) {
this.timeout(1000 * 10); // higher timeout for this test
if (process.env['VSCODE_PID']) {
return done(); // this test fails when run from within VS Code
}
flakySuite('Ports', () => {
(process.env['VSCODE_PID'] ? test.skip /* this test fails when run from within VS Code */ : test)('Finds a free port (no timeout)', function (done) {
// get an initial freeport >= 7000
ports.findFreePort(7000, 100, 300000).then(initialPort => {

View File

@@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------------------------
* 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 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';
function checkPath(exePath: string) {
// Check to see if the path exists
let pathCheckResult = false;
try {
const stat = fs.statSync(exePath);
pathCheckResult = stat.isFile();
} catch {
// fs.exists throws on Windows with SymbolicLinks so we
// also use lstat to try and see if the file exists.
try {
pathCheckResult = fs.statSync(fs.readlinkSync(exePath)).isFile();
} catch {
}
}
assert.strictEqual(pathCheckResult, true);
}
if (platform.isWindows) {
suite('PowerShell finder', () => {
test('Can find first available PowerShell', async () => {
const pwshExe = await getFirstAvailablePowerShellInstallation();
const exePath = pwshExe?.exePath;
assert.notStrictEqual(exePath, null);
assert.notStrictEqual(pwshExe?.displayName, null);
checkPath(exePath!);
});
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);
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);
}
});
});
}

View File

@@ -13,9 +13,9 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
function fork(id: string): cp.ChildProcess {
const opts: any = {
env: objects.mixin(objects.deepClone(process.env), {
AMD_ENTRYPOINT: id,
PIPE_LOGGING: 'true',
VERBOSE_LOGGING: true
VSCODE_AMD_ENTRYPOINT: id,
VSCODE_PIPE_LOGGING: 'true',
VSCODE_VERBOSE_LOGGING: true
})
};
@@ -59,11 +59,7 @@ suite('Processes', () => {
});
});
test('buffered sending - lots of data (potential deadlock on win32)', function (done: () => void) {
if (!platform.isWindows || process.env['VSCODE_PID']) {
return done(); // test is only relevant for Windows and seems to crash randomly on some Linux builds
}
(!platform.isWindows || process.env['VSCODE_PID'] ? test.skip : test)('buffered sending - lots of data (potential deadlock on win32)', function (done: () => void) { // test is only relevant for Windows and seems to crash randomly on some Linux builds
const child = fork('vs/base/test/node/processes/fixtures/fork_large');
const sender = processes.createQueuedSender(child);

View File

@@ -3,9 +3,25 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { Suite } from 'mocha';
import { join } from 'vs/base/common/path';
import { generateUuid } from 'vs/base/common/uuid';
export function getRandomTestPath(tmpdir: string, ...segments: string[]): string {
return join(tmpdir, ...segments, generateUuid());
}
export function flakySuite(title: string, fn: (this: Suite) => void): Suite {
return suite(title, function () {
// Flaky suites need retries and timeout to complete
// e.g. because they access the file system which can
// be unreliable depending on the environment.
this.retries(3);
this.timeout(1000 * 20);
// Invoke suite ensuring that `this` is
// properly wired in.
fn.call(this);
});
}

View File

@@ -5,24 +5,33 @@
import * as assert from 'assert';
import * as path from 'vs/base/common/path';
import * as os from 'os';
import { tmpdir } from 'os';
import { extract } from 'vs/base/node/zip';
import { generateUuid } from 'vs/base/common/uuid';
import { rimraf, exists } from 'vs/base/node/pfs';
import { rimraf, exists, mkdirp } from 'vs/base/node/pfs';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { createCancelablePromise } from 'vs/base/common/async';
const fixtures = getPathFromAmdModule(require, './fixtures');
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
suite('Zip', () => {
test('extract should handle directories', () => {
const fixture = path.join(fixtures, 'extract.zip');
const target = path.join(os.tmpdir(), generateUuid());
let testDir: string;
return createCancelablePromise(token => extract(fixture, target, {}, token)
.then(() => exists(path.join(target, 'extension')))
.then(exists => assert(exists))
.then(() => rimraf(target)));
setup(() => {
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'zip');
return mkdirp(testDir);
});
teardown(() => {
return rimraf(testDir);
});
test('extract should handle directories', async () => {
const fixtures = getPathFromAmdModule(require, './fixtures');
const fixture = path.join(fixtures, 'extract.zip');
await createCancelablePromise(token => extract(fixture, testDir, {}, token));
const doesExist = await exists(path.join(testDir, 'extension'));
assert(doesExist);
});
});