mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -31,9 +31,23 @@ let withBuilder = function (builder, offdom) {
|
||||
};
|
||||
|
||||
suite('Builder', () => {
|
||||
let fixture: HTMLElement;
|
||||
let fixtureId = 'builder-fixture';
|
||||
|
||||
test('Dimension.substract()', function () {
|
||||
assert.equal(1, 1);
|
||||
setup(() => {
|
||||
fixture = document.createElement('div');
|
||||
fixture.id = fixtureId;
|
||||
document.body.appendChild(fixture);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
document.body.removeChild(fixture);
|
||||
});
|
||||
|
||||
test('Dimension.substract()', function () {
|
||||
// let d1 = new Dimension(200, 100);
|
||||
// let d2 = new Box(10, 20, 30, 40);
|
||||
|
||||
// assert.deepEqual(d1.substract(d2), new Dimension(140, 60));
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,15 @@ const $ = dom.$;
|
||||
|
||||
suite('dom', () => {
|
||||
test('hasClass', () => {
|
||||
assert(true);
|
||||
|
||||
// let element = document.createElement('div');
|
||||
// element.className = 'foobar boo far';
|
||||
|
||||
// assert(dom.hasClass(element, 'foobar'));
|
||||
// assert(dom.hasClass(element, 'boo'));
|
||||
// assert(dom.hasClass(element, 'far'));
|
||||
// assert(!dom.hasClass(element, 'bar'));
|
||||
// assert(!dom.hasClass(element, 'foo'));
|
||||
// assert(!dom.hasClass(element, ''));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import { renderMarkdown, renderText, renderFormattedText } from 'vs/base/browser
|
||||
|
||||
suite('HtmlContent', () => {
|
||||
test('render simple element', () => {
|
||||
var result: HTMLElement = <any>renderText('testing');
|
||||
var result: HTMLElement = renderText('testing');
|
||||
|
||||
assert.strictEqual(result.nodeType, document.ELEMENT_NODE);
|
||||
assert.strictEqual(result.textContent, 'testing');
|
||||
@@ -18,7 +18,7 @@ suite('HtmlContent', () => {
|
||||
});
|
||||
|
||||
test('render element with class', () => {
|
||||
var result: HTMLElement = <any>renderText('testing', {
|
||||
var result: HTMLElement = renderText('testing', {
|
||||
className: 'testClass'
|
||||
});
|
||||
assert.strictEqual(result.nodeType, document.ELEMENT_NODE);
|
||||
@@ -26,32 +26,32 @@ suite('HtmlContent', () => {
|
||||
});
|
||||
|
||||
test('simple formatting', () => {
|
||||
var result: HTMLElement = <any>renderFormattedText('**bold**');
|
||||
var result: HTMLElement = renderFormattedText('**bold**');
|
||||
assert.strictEqual(result.children.length, 1);
|
||||
assert.strictEqual(result.firstChild.textContent, 'bold');
|
||||
assert.strictEqual((<HTMLElement>result.firstChild).tagName, 'B');
|
||||
assert.strictEqual(result.innerHTML, '<b>bold</b>');
|
||||
|
||||
result = <any>renderFormattedText('__italics__');
|
||||
result = renderFormattedText('__italics__');
|
||||
assert.strictEqual(result.innerHTML, '<i>italics</i>');
|
||||
|
||||
result = <any>renderFormattedText('this string has **bold** and __italics__');
|
||||
result = renderFormattedText('this string has **bold** and __italics__');
|
||||
assert.strictEqual(result.innerHTML, 'this string has <b>bold</b> and <i>italics</i>');
|
||||
});
|
||||
|
||||
test('no formatting', () => {
|
||||
var result: HTMLElement = <any>renderFormattedText('this is just a string');
|
||||
var result: HTMLElement = renderFormattedText('this is just a string');
|
||||
assert.strictEqual(result.innerHTML, 'this is just a string');
|
||||
});
|
||||
|
||||
test('preserve newlines', () => {
|
||||
var result: HTMLElement = <any>renderFormattedText('line one\nline two');
|
||||
var result: HTMLElement = renderFormattedText('line one\nline two');
|
||||
assert.strictEqual(result.innerHTML, 'line one<br>line two');
|
||||
});
|
||||
|
||||
test('action', () => {
|
||||
var callbackCalled = false;
|
||||
var result: HTMLElement = <any>renderFormattedText('[[action]]', {
|
||||
var result: HTMLElement = renderFormattedText('[[action]]', {
|
||||
actionCallback(content) {
|
||||
assert.strictEqual(content, '0');
|
||||
callbackCalled = true;
|
||||
@@ -67,7 +67,7 @@ suite('HtmlContent', () => {
|
||||
|
||||
test('fancy action', () => {
|
||||
var callbackCalled = false;
|
||||
var result: HTMLElement = <any>renderFormattedText('__**[[action]]**__', {
|
||||
var result: HTMLElement = renderFormattedText('__**[[action]]**__', {
|
||||
actionCallback(content) {
|
||||
assert.strictEqual(content, '0');
|
||||
callbackCalled = true;
|
||||
@@ -82,13 +82,13 @@ suite('HtmlContent', () => {
|
||||
});
|
||||
|
||||
test('escaped formatting', () => {
|
||||
var result: HTMLElement = <any>renderFormattedText('\\*\\*bold\\*\\*');
|
||||
var result: HTMLElement = renderFormattedText('\\*\\*bold\\*\\*');
|
||||
assert.strictEqual(result.children.length, 0);
|
||||
assert.strictEqual(result.innerHTML, '**bold**');
|
||||
});
|
||||
test('image rendering conforms to default', () => {
|
||||
const markdown = { value: `` };
|
||||
const result: HTMLElement = <any>renderMarkdown(markdown);
|
||||
const result: HTMLElement = renderMarkdown(markdown);
|
||||
const renderer = new marked.Renderer();
|
||||
const imageFromMarked = marked(markdown.value, {
|
||||
sanitize: true,
|
||||
@@ -98,7 +98,7 @@ suite('HtmlContent', () => {
|
||||
});
|
||||
test('image rendering conforms to default without title', () => {
|
||||
const markdown = { value: `` };
|
||||
const result: HTMLElement = <any>renderMarkdown(markdown);
|
||||
const result: HTMLElement = renderMarkdown(markdown);
|
||||
const renderer = new marked.Renderer();
|
||||
const imageFromMarked = marked(markdown.value, {
|
||||
sanitize: true,
|
||||
@@ -107,15 +107,15 @@ suite('HtmlContent', () => {
|
||||
assert.strictEqual(result.innerHTML, imageFromMarked);
|
||||
});
|
||||
test('image width from title params', () => {
|
||||
var result: HTMLElement = <any>renderMarkdown({ value: `` });
|
||||
var result: HTMLElement = renderMarkdown({ value: `` });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="someimageurl" alt="image" title="caption" width="100"></p>`);
|
||||
});
|
||||
test('image height from title params', () => {
|
||||
var result: HTMLElement = <any>renderMarkdown({ value: `` });
|
||||
var result: HTMLElement = renderMarkdown({ value: `` });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="someimageurl" alt="image" title="caption" height="100"></p>`);
|
||||
});
|
||||
test('image width and height from title params', () => {
|
||||
var result: HTMLElement = <any>renderMarkdown({ value: `` });
|
||||
var result: HTMLElement = renderMarkdown({ value: `` });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="someimageurl" alt="image" title="caption" width="100" height="200"></p>`);
|
||||
});
|
||||
});
|
||||
|
||||
81
src/vs/base/test/browser/ui/splitview/splitview.test.ts
Normal file
81
src/vs/base/test/browser/ui/splitview/splitview.test.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { SplitView, IView, Orientation } from 'vs/base/browser/ui/splitview/splitview';
|
||||
import { Sash } from 'vs/base/browser/ui/sash/sash';
|
||||
|
||||
class TestView implements IView {
|
||||
|
||||
private _onDidChange = new Emitter<number | undefined>();
|
||||
readonly onDidChange = this._onDidChange.event;
|
||||
|
||||
get minimumSize(): number { return this._minimumSize; }
|
||||
set minimumSize(size: number) { this._minimumSize = size; this._onDidChange.fire(); }
|
||||
|
||||
get maximumSize(): number { return this._maximumSize; }
|
||||
set maximumSize(size: number) { this._maximumSize = size; this._onDidChange.fire(); }
|
||||
|
||||
private _onDidRender = new Emitter<{ container: HTMLElement; orientation: Orientation }>();
|
||||
readonly onDidRender = this._onDidRender.event;
|
||||
|
||||
private _size = 0;
|
||||
get size(): number { return this._size; }
|
||||
private _onDidLayout = new Emitter<{ size: number; orientation: Orientation }>();
|
||||
readonly onDidLayout = this._onDidLayout.event;
|
||||
|
||||
private _onDidFocus = new Emitter<void>();
|
||||
readonly onDidFocus = this._onDidFocus.event;
|
||||
|
||||
constructor(
|
||||
private _minimumSize: number,
|
||||
private _maximumSize: number
|
||||
) {
|
||||
assert(_minimumSize <= _maximumSize, 'splitview view minimum size must be <= maximum size');
|
||||
}
|
||||
|
||||
render(container: HTMLElement, orientation: Orientation): void {
|
||||
this._onDidRender.fire({ container, orientation });
|
||||
}
|
||||
|
||||
layout(size: number, orientation: Orientation): void {
|
||||
this._size = size;
|
||||
this._onDidLayout.fire({ size, orientation });
|
||||
}
|
||||
|
||||
focus(): void {
|
||||
this._onDidFocus.fire();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._onDidChange.dispose();
|
||||
this._onDidRender.dispose();
|
||||
this._onDidLayout.dispose();
|
||||
this._onDidFocus.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function getSashes(splitview: SplitView): Sash[] {
|
||||
return (splitview as any).sashItems.map(i => i.sash) as Sash[];
|
||||
}
|
||||
|
||||
suite('Splitview', () => {
|
||||
let container: HTMLElement;
|
||||
|
||||
setup(() => {
|
||||
container = document.createElement('div');
|
||||
container.style.position = 'absolute';
|
||||
container.style.width = `${200}px`;
|
||||
container.style.height = `${200}px`;
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
container = null;
|
||||
});
|
||||
|
||||
test('empty splitview has empty DOM', () => {
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import arrays = require('vs/base/common/arrays');
|
||||
|
||||
suite('Arrays', () => {
|
||||
@@ -94,7 +95,51 @@ suite('Arrays', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('delta', function () {
|
||||
test('sortedDiff', function () {
|
||||
function compare(a: number, b: number): number {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
let d = arrays.sortedDiff([1, 2, 4], [], compare);
|
||||
assert.deepEqual(d, [
|
||||
{ start: 0, deleteCount: 3, inserted: [] }
|
||||
]);
|
||||
|
||||
d = arrays.sortedDiff([], [1, 2, 4], compare);
|
||||
assert.deepEqual(d, [
|
||||
{ start: 0, deleteCount: 0, inserted: [1, 2, 4] }
|
||||
]);
|
||||
|
||||
d = arrays.sortedDiff([1, 2, 4], [1, 2, 4], compare);
|
||||
assert.deepEqual(d, []);
|
||||
|
||||
d = arrays.sortedDiff([1, 2, 4], [2, 3, 4, 5], compare);
|
||||
assert.deepEqual(d, [
|
||||
{ start: 0, deleteCount: 1, inserted: [] },
|
||||
{ start: 2, deleteCount: 0, inserted: [3] },
|
||||
{ start: 3, deleteCount: 0, inserted: [5] },
|
||||
]);
|
||||
|
||||
d = arrays.sortedDiff([2, 3, 4, 5], [1, 2, 4], compare);
|
||||
assert.deepEqual(d, [
|
||||
{ start: 0, deleteCount: 0, inserted: [1] },
|
||||
{ start: 1, deleteCount: 1, inserted: [] },
|
||||
{ start: 3, deleteCount: 1, inserted: [] },
|
||||
]);
|
||||
|
||||
d = arrays.sortedDiff([1, 3, 5, 7], [5, 9, 11], compare);
|
||||
assert.deepEqual(d, [
|
||||
{ start: 0, deleteCount: 2, inserted: [] },
|
||||
{ start: 3, deleteCount: 1, inserted: [9, 11] }
|
||||
]);
|
||||
|
||||
d = arrays.sortedDiff([1, 3, 7], [5, 9, 11], compare);
|
||||
assert.deepEqual(d, [
|
||||
{ start: 0, deleteCount: 3, inserted: [5, 9, 11] }
|
||||
]);
|
||||
});
|
||||
|
||||
test('delta sorted arrays', function () {
|
||||
function compare(a: number, b: number): number {
|
||||
return a - b;
|
||||
}
|
||||
@@ -171,5 +216,58 @@ suite('Arrays', () => {
|
||||
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]);
|
||||
});
|
||||
|
||||
test('topAsync', function (done) {
|
||||
const cmp = (a, b) => {
|
||||
assert.strictEqual(typeof a, 'number', 'typeof a');
|
||||
assert.strictEqual(typeof b, 'number', 'typeof b');
|
||||
return a - b;
|
||||
};
|
||||
|
||||
testTopAsync(cmp, 1)
|
||||
.then(() => {
|
||||
return testTopAsync(cmp, 2);
|
||||
})
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
function testTopAsync(cmp: any, m: number) {
|
||||
return TPromise.as(null).then(() => {
|
||||
return arrays.topAsync([], cmp, 1, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, []);
|
||||
});
|
||||
}).then(() => {
|
||||
return arrays.topAsync([1], cmp, 0, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, []);
|
||||
});
|
||||
}).then(() => {
|
||||
return arrays.topAsync([1, 2], cmp, 1, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, [1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return arrays.topAsync([2, 1], cmp, 1, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, [1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return arrays.topAsync([1, 3, 2], cmp, 2, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, [1, 2]);
|
||||
});
|
||||
}).then(() => {
|
||||
return arrays.topAsync([3, 2, 1], cmp, 3, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, [1, 2, 3]);
|
||||
});
|
||||
}).then(() => {
|
||||
return arrays.topAsync([4, 6, 2, 7, 8, 3, 5, 1], cmp, 3, m)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, [1, 2, 3]);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import * as assert from 'assert';
|
||||
import { Promise, TPromise } from 'vs/base/common/winjs.base';
|
||||
import Async = require('vs/base/common/async');
|
||||
import URI from 'vs/base/common/uri';
|
||||
|
||||
suite('Async', () => {
|
||||
test('Throttler - non async', function (done) {
|
||||
@@ -452,8 +453,15 @@ suite('Async', () => {
|
||||
let asyncPromise = false;
|
||||
let f2 = () => TPromise.timeout(10).then(() => asyncPromise = true);
|
||||
|
||||
assert.equal(queue.size, 0);
|
||||
|
||||
queue.queue(f1);
|
||||
queue.queue(f2).then(() => {
|
||||
assert.equal(queue.size, 0); // sync promise is already done
|
||||
|
||||
const p = queue.queue(f2);
|
||||
assert.equal(queue.size, 1);
|
||||
return p.then(() => {
|
||||
assert.equal(queue.size, 1);
|
||||
assert.ok(syncPromise);
|
||||
assert.ok(asyncPromise);
|
||||
|
||||
@@ -569,4 +577,22 @@ suite('Async', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('ResourceQueue - simple', function () {
|
||||
let queue = new Async.ResourceQueue();
|
||||
|
||||
const r1Queue = queue.queueFor(URI.file('/some/path'));
|
||||
const r2Queue = queue.queueFor(URI.file('/some/other/path'));
|
||||
|
||||
assert.ok(r1Queue);
|
||||
assert.ok(r2Queue);
|
||||
assert.equal(r1Queue, queue.queueFor(URI.file('/some/path'))); // same queue returned
|
||||
|
||||
let syncPromiseFactory = () => TPromise.as(true);
|
||||
|
||||
r1Queue.queue(syncPromiseFactory);
|
||||
|
||||
const r1Queue2 = queue.queueFor(URI.file('/some/path'));
|
||||
assert.notEqual(r1Queue, r1Queue2); // previous one got disposed after finishing
|
||||
});
|
||||
});
|
||||
|
||||
@@ -179,6 +179,29 @@ suite('Event', function () {
|
||||
}
|
||||
});
|
||||
|
||||
test('reusing event function and context', function () {
|
||||
let counter = 0;
|
||||
function listener() {
|
||||
counter += 1;
|
||||
}
|
||||
const context = {};
|
||||
|
||||
let emitter = new Emitter();
|
||||
let reg1 = emitter.event(listener, context);
|
||||
let reg2 = emitter.event(listener, context);
|
||||
|
||||
emitter.fire();
|
||||
assert.equal(counter, 2);
|
||||
|
||||
reg1.dispose();
|
||||
emitter.fire();
|
||||
assert.equal(counter, 3);
|
||||
|
||||
reg2.dispose();
|
||||
emitter.fire();
|
||||
assert.equal(counter, 3);
|
||||
});
|
||||
|
||||
test('Debounce Event', function (done: () => void) {
|
||||
let doc = new Samples.Document3();
|
||||
|
||||
@@ -660,4 +683,4 @@ suite('Event utils', () => {
|
||||
assert.deepEqual(result, [1, 2, 3, 4, 5]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
// import * as assert from 'assert';
|
||||
import * as filters from 'vs/base/common/filters';
|
||||
import { data } from './filters.perf.data';
|
||||
|
||||
|
||||
@@ -161,6 +161,18 @@ suite('Filters', () => {
|
||||
{ start: 9, end: 10 },
|
||||
{ start: 18, end: 19 }
|
||||
]);
|
||||
filterOk(matchesSubString, 'abc', 'abcabc', [
|
||||
{ start: 0, end: 3 },
|
||||
]);
|
||||
filterOk(matchesSubString, 'abc', 'aaabbbccc', [
|
||||
{ start: 0, end: 1 },
|
||||
{ start: 3, end: 4 },
|
||||
{ start: 6, end: 7 },
|
||||
]);
|
||||
});
|
||||
|
||||
test('matchesSubString performance (#35346)', function () {
|
||||
filterNotOk(matchesSubString, 'aaaaaaaaaaaaaaaaaaaax', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
|
||||
});
|
||||
|
||||
test('WordFilter', function () {
|
||||
|
||||
121
src/vs/base/test/common/linkedList.test.ts
Normal file
121
src/vs/base/test/common/linkedList.test.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { LinkedList } from 'vs/base/common/linkedList';
|
||||
|
||||
suite('LinkedList', function () {
|
||||
|
||||
function assertElements<E>(list: LinkedList<E>, ...elements: E[]) {
|
||||
// first: assert toArray
|
||||
assert.deepEqual(list.toArray(), elements);
|
||||
|
||||
// second: assert iterator
|
||||
for (let iter = list.iterator(), element = iter.next(); !element.done; element = iter.next()) {
|
||||
assert.equal(elements.shift(), element.value);
|
||||
}
|
||||
assert.equal(elements.length, 0);
|
||||
}
|
||||
|
||||
test('Push/Iter', function () {
|
||||
const list = new LinkedList<number>();
|
||||
list.push(0);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
assertElements(list, 0, 1, 2);
|
||||
});
|
||||
|
||||
test('Push/Remove', function () {
|
||||
let list = new LinkedList<number>();
|
||||
let disp = list.push(0);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
disp();
|
||||
assertElements(list, 1, 2);
|
||||
|
||||
list = new LinkedList<number>();
|
||||
list.push(0);
|
||||
disp = list.push(1);
|
||||
list.push(2);
|
||||
disp();
|
||||
assertElements(list, 0, 2);
|
||||
|
||||
list = new LinkedList<number>();
|
||||
list.push(0);
|
||||
list.push(1);
|
||||
disp = list.push(2);
|
||||
disp();
|
||||
assertElements(list, 0, 1);
|
||||
});
|
||||
|
||||
test('Push/toArray', function () {
|
||||
let list = new LinkedList<string>();
|
||||
list.push('foo');
|
||||
list.push('bar');
|
||||
list.push('far');
|
||||
list.push('boo');
|
||||
|
||||
assert.deepEqual(
|
||||
list.toArray(),
|
||||
[
|
||||
'foo',
|
||||
'bar',
|
||||
'far',
|
||||
'boo',
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
test('unshift/Iter', function () {
|
||||
const list = new LinkedList<number>();
|
||||
list.unshift(0);
|
||||
list.unshift(1);
|
||||
list.unshift(2);
|
||||
assertElements(list, 2, 1, 0);
|
||||
});
|
||||
|
||||
test('unshift/Remove', function () {
|
||||
let list = new LinkedList<number>();
|
||||
let disp = list.unshift(0);
|
||||
list.unshift(1);
|
||||
list.unshift(2);
|
||||
disp();
|
||||
assertElements(list, 2, 1);
|
||||
|
||||
list = new LinkedList<number>();
|
||||
list.unshift(0);
|
||||
disp = list.unshift(1);
|
||||
list.unshift(2);
|
||||
disp();
|
||||
assertElements(list, 2, 0);
|
||||
|
||||
list = new LinkedList<number>();
|
||||
list.unshift(0);
|
||||
list.unshift(1);
|
||||
disp = list.unshift(2);
|
||||
disp();
|
||||
assertElements(list, 1, 0);
|
||||
});
|
||||
|
||||
test('unshift/toArray', function () {
|
||||
let list = new LinkedList<string>();
|
||||
list.unshift('foo');
|
||||
list.unshift('bar');
|
||||
list.unshift('far');
|
||||
list.unshift('boo');
|
||||
|
||||
assert.deepEqual(
|
||||
list.toArray(),
|
||||
[
|
||||
'boo',
|
||||
'far',
|
||||
'bar',
|
||||
'foo',
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
import { BoundedMap, TrieMap, ResourceMap } from 'vs/base/common/map';
|
||||
import { BoundedMap, ResourceMap, TernarySearchTree, PathIterator, StringIterator } from 'vs/base/common/map';
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
|
||||
@@ -311,53 +311,203 @@ suite('Map', () => {
|
||||
assert.ok(!map.has('4'));
|
||||
});
|
||||
|
||||
test('PathIterator', function () {
|
||||
const iter = new PathIterator();
|
||||
iter.reset('file:///usr/bin/file.txt');
|
||||
|
||||
test('TrieMap - basics', function () {
|
||||
assert.equal(iter.value(), 'file:');
|
||||
assert.equal(iter.hasNext(), true);
|
||||
assert.equal(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);
|
||||
|
||||
const map = new TrieMap<number>();
|
||||
iter.next();
|
||||
assert.equal(iter.value(), 'usr');
|
||||
assert.equal(iter.hasNext(), true);
|
||||
|
||||
map.insert('/user/foo/bar', 1);
|
||||
map.insert('/user/foo', 2);
|
||||
map.insert('/user/foo/flip/flop', 3);
|
||||
iter.next();
|
||||
assert.equal(iter.value(), 'bin');
|
||||
assert.equal(iter.hasNext(), true);
|
||||
|
||||
assert.equal(map.findSubstr('/user/bar'), undefined);
|
||||
assert.equal(map.findSubstr('/user/foo'), 2);
|
||||
assert.equal(map.findSubstr('\\user\\foo'), 2);
|
||||
assert.equal(map.findSubstr('/user/foo/ba'), 2);
|
||||
assert.equal(map.findSubstr('/user/foo/far/boo'), 2);
|
||||
assert.equal(map.findSubstr('/user/foo/bar'), 1);
|
||||
assert.equal(map.findSubstr('/user/foo/bar/far/boo'), 1);
|
||||
iter.next();
|
||||
assert.equal(iter.value(), 'file.txt');
|
||||
assert.equal(iter.hasNext(), false);
|
||||
|
||||
iter.next();
|
||||
assert.equal(iter.value(), '');
|
||||
assert.equal(iter.hasNext(), false);
|
||||
iter.next();
|
||||
assert.equal(iter.value(), '');
|
||||
assert.equal(iter.hasNext(), false);
|
||||
|
||||
//
|
||||
iter.reset('/foo/bar/');
|
||||
assert.equal(iter.value(), 'foo');
|
||||
assert.equal(iter.hasNext(), true);
|
||||
|
||||
iter.next();
|
||||
assert.equal(iter.value(), 'bar');
|
||||
assert.equal(iter.hasNext(), false);
|
||||
});
|
||||
|
||||
test('TrieMap - lookup', function () {
|
||||
function assertTernarySearchTree<E>(trie: TernarySearchTree<E>, ...elements: [string, E][]) {
|
||||
const map = new Map<string, E>();
|
||||
for (const [key, value] of elements) {
|
||||
map.set(key, value);
|
||||
}
|
||||
map.forEach((value, key) => {
|
||||
assert.equal(trie.get(key), value);
|
||||
});
|
||||
trie.forEach((element, key) => {
|
||||
assert.equal(element, map.get(key));
|
||||
map.delete(key);
|
||||
});
|
||||
assert.equal(map.size, 0);
|
||||
}
|
||||
|
||||
const map = new TrieMap<number>();
|
||||
map.insert('/user/foo/bar', 1);
|
||||
map.insert('/user/foo', 2);
|
||||
map.insert('/user/foo/flip/flop', 3);
|
||||
test('TernarySearchTree - set', function () {
|
||||
|
||||
assert.equal(map.lookUp('/foo'), undefined);
|
||||
assert.equal(map.lookUp('/user'), undefined);
|
||||
assert.equal(map.lookUp('/user/foo'), 2);
|
||||
assert.equal(map.lookUp('/user/foo/bar'), 1);
|
||||
assert.equal(map.lookUp('/user/foo/bar/boo'), undefined);
|
||||
let trie = TernarySearchTree.forStrings<number>();
|
||||
trie.set('foobar', 1);
|
||||
trie.set('foobaz', 2);
|
||||
|
||||
assertTernarySearchTree(trie, ['foobar', 1], ['foobaz', 2]); // longer
|
||||
|
||||
trie = TernarySearchTree.forStrings<number>();
|
||||
trie.set('foobar', 1);
|
||||
trie.set('fooba', 2);
|
||||
assertTernarySearchTree(trie, ['foobar', 1], ['fooba', 2]); // shorter
|
||||
|
||||
trie = TernarySearchTree.forStrings<number>();
|
||||
trie.set('foo', 1);
|
||||
trie.set('foo', 2);
|
||||
assertTernarySearchTree(trie, ['foo', 2]);
|
||||
|
||||
trie = TernarySearchTree.forStrings<number>();
|
||||
trie.set('foo', 1);
|
||||
trie.set('foobar', 2);
|
||||
trie.set('bar', 3);
|
||||
trie.set('foob', 4);
|
||||
trie.set('bazz', 5);
|
||||
|
||||
assertTernarySearchTree(trie,
|
||||
['foo', 1],
|
||||
['foobar', 2],
|
||||
['bar', 3],
|
||||
['foob', 4],
|
||||
['bazz', 5]
|
||||
);
|
||||
});
|
||||
|
||||
test('TrieMap - superstr', function () {
|
||||
test('TernarySearchTree - findLongestMatch', function () {
|
||||
|
||||
const map = new TrieMap<number>();
|
||||
map.insert('/user/foo/bar', 1);
|
||||
map.insert('/user/foo', 2);
|
||||
map.insert('/user/foo/flip/flop', 3);
|
||||
let trie = TernarySearchTree.forStrings<number>();
|
||||
trie.set('foo', 1);
|
||||
trie.set('foobar', 2);
|
||||
trie.set('foobaz', 3);
|
||||
|
||||
const supMap = map.findSuperstr('/user');
|
||||
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.equal(supMap.lookUp('foo'), 2);
|
||||
assert.equal(supMap.lookUp('foo/bar'), 1);
|
||||
assert.equal(supMap.lookUp('foo/flip/flop'), 3);
|
||||
assert.equal(supMap.lookUp('foo/flip/flop/bar'), undefined);
|
||||
assert.equal(supMap.lookUp('user'), undefined);
|
||||
test('TernarySearchTree - basics', function () {
|
||||
let trie = new TernarySearchTree<number>(new StringIterator());
|
||||
|
||||
trie.set('foo', 1);
|
||||
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.equal(trie.findSubstr('fo'), undefined);
|
||||
assert.equal(trie.findSubstr('foo'), 1);
|
||||
assert.equal(trie.findSubstr('foooo'), 1);
|
||||
|
||||
|
||||
trie.delete('foobar');
|
||||
trie.delete('bar');
|
||||
assert.equal(trie.get('foobar'), undefined);
|
||||
assert.equal(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);
|
||||
});
|
||||
|
||||
test('TernarySearchTree (PathSegments) - basics', function () {
|
||||
let trie = new TernarySearchTree<number>(new PathIterator());
|
||||
|
||||
trie.set('/user/foo/bar', 1);
|
||||
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.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);
|
||||
});
|
||||
|
||||
test('TernarySearchTree (PathSegments) - lookup', function () {
|
||||
|
||||
const map = new TernarySearchTree<number>(new PathIterator());
|
||||
map.set('/user/foo/bar', 1);
|
||||
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);
|
||||
});
|
||||
|
||||
test('TernarySearchTree (PathSegments) - superstr', function () {
|
||||
|
||||
const map = new TernarySearchTree<number>(new PathIterator());
|
||||
map.set('/user/foo/bar', 1);
|
||||
map.set('/user/foo', 2);
|
||||
map.set('/user/foo/flip/flop', 3);
|
||||
map.set('/usr/foo', 4);
|
||||
|
||||
const elements = map.findSuperstr('/user');
|
||||
|
||||
assertTernarySearchTree(elements, ['foo/bar', 1], ['foo', 2], ['foo/flip/flop', 3]);
|
||||
// assert.equal(elements.length, 3);
|
||||
assert.equal(elements.get('foo/bar'), 1);
|
||||
assert.equal(elements.get('foo'), 2);
|
||||
assert.equal(elements.get('foo/flip/flop'), 3);
|
||||
|
||||
assertTernarySearchTree(map.findSuperstr('/usr'), ['foo', 4]);
|
||||
assert.equal(map.findSuperstr('/usr/foo'), undefined);
|
||||
assert.equal(map.get('/usr/foo'), 4);
|
||||
|
||||
assert.equal(map.findSuperstr('/not'), undefined);
|
||||
assert.equal(map.findSuperstr('/us'), undefined);
|
||||
assert.equal(map.findSuperstr('/usrr'), undefined);
|
||||
assert.equal(map.findSuperstr('/userr'), undefined);
|
||||
});
|
||||
|
||||
test('ResourceMap - basics', function () {
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import scorer = require('vs/base/common/scorer');
|
||||
|
||||
suite('Scorer', () => {
|
||||
|
||||
test('score', function () {
|
||||
const target = 'HelLo-World';
|
||||
|
||||
const scores = [];
|
||||
scores.push(scorer.score(target, 'HelLo-World')); // direct case match
|
||||
scores.push(scorer.score(target, 'hello-world')); // direct mix-case match
|
||||
scores.push(scorer.score(target, 'HW')); // direct case prefix (multiple)
|
||||
scores.push(scorer.score(target, 'H')); // direct case prefix
|
||||
scores.push(scorer.score(target, 'hw')); // direct mix-case prefix (multiple)
|
||||
scores.push(scorer.score(target, 'h')); // direct mix-case prefix
|
||||
scores.push(scorer.score(target, 'W')); // direct case word prefix
|
||||
scores.push(scorer.score(target, 'w')); // direct mix-case word prefix
|
||||
scores.push(scorer.score(target, 'Ld')); // in-string case match (multiple)
|
||||
scores.push(scorer.score(target, 'L')); // in-string case match
|
||||
scores.push(scorer.score(target, 'ld')); // in-string mix-case match
|
||||
scores.push(scorer.score(target, 'l')); // in-string mix-case match
|
||||
scores.push(scorer.score(target, '4')); // no match
|
||||
|
||||
// Assert scoring order
|
||||
let sortedScores = scores.sort((a, b) => b - a);
|
||||
assert.deepEqual(scores, sortedScores);
|
||||
});
|
||||
|
||||
test('cache', function () {
|
||||
const cache = Object.create(null);
|
||||
|
||||
scorer.score('target', 'query', cache);
|
||||
scorer.score('target', 't', cache);
|
||||
|
||||
assert.equal(Object.getOwnPropertyNames(cache).length, 2);
|
||||
});
|
||||
|
||||
test('matches', function () {
|
||||
assert.ok(scorer.matches('hello world', 'h'));
|
||||
assert.ok(!scorer.matches('hello world', 'q'));
|
||||
assert.ok(scorer.matches('hello world', 'hw'));
|
||||
assert.ok(scorer.matches('hello world', 'horl'));
|
||||
assert.ok(scorer.matches('hello world', 'd'));
|
||||
assert.ok(!scorer.matches('hello world', 'wh'));
|
||||
assert.ok(!scorer.matches('d', 'dd'));
|
||||
});
|
||||
});
|
||||
@@ -312,6 +312,22 @@ suite('Strings', () => {
|
||||
assert(regExpWithFlags.multiline);
|
||||
});
|
||||
|
||||
test('regExpContainsBackreference', () => {
|
||||
assert(strings.regExpContainsBackreference('foo \\5 bar'));
|
||||
assert(strings.regExpContainsBackreference('\\2'));
|
||||
assert(strings.regExpContainsBackreference('(\\d)(\\n)(\\1)'));
|
||||
assert(strings.regExpContainsBackreference('(A).*?\\1'));
|
||||
assert(strings.regExpContainsBackreference('\\\\\\1'));
|
||||
assert(strings.regExpContainsBackreference('foo \\\\\\1'));
|
||||
|
||||
assert(!strings.regExpContainsBackreference(''));
|
||||
assert(!strings.regExpContainsBackreference('\\\\1'));
|
||||
assert(!strings.regExpContainsBackreference('foo \\\\1'));
|
||||
assert(!strings.regExpContainsBackreference('(A).*?\\\\1'));
|
||||
assert(!strings.regExpContainsBackreference('foo \\d1 bar'));
|
||||
assert(!strings.regExpContainsBackreference('123'));
|
||||
});
|
||||
|
||||
test('getLeadingWhitespace', () => {
|
||||
assert.equal(strings.getLeadingWhitespace(' foo'), ' ');
|
||||
assert.equal(strings.getLeadingWhitespace(' foo', 2), '');
|
||||
@@ -322,6 +338,33 @@ suite('Strings', () => {
|
||||
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');
|
||||
});
|
||||
|
||||
test('fuzzyContains', function () {
|
||||
assert.ok(!strings.fuzzyContains(void 0, null));
|
||||
assert.ok(strings.fuzzyContains('hello world', 'h'));
|
||||
assert.ok(!strings.fuzzyContains('hello world', 'q'));
|
||||
assert.ok(strings.fuzzyContains('hello world', 'hw'));
|
||||
assert.ok(strings.fuzzyContains('hello world', 'horl'));
|
||||
assert.ok(strings.fuzzyContains('hello world', 'd'));
|
||||
assert.ok(!strings.fuzzyContains('hello world', 'wh'));
|
||||
assert.ok(!strings.fuzzyContains('d', 'dd'));
|
||||
});
|
||||
|
||||
test('startsWithUTF8BOM', () => {
|
||||
assert(strings.startsWithUTF8BOM(strings.UTF8_BOM_CHARACTER));
|
||||
assert(strings.startsWithUTF8BOM(strings.UTF8_BOM_CHARACTER + 'a'));
|
||||
assert(strings.startsWithUTF8BOM(strings.UTF8_BOM_CHARACTER + 'aaaaaaaaaa'));
|
||||
assert(!strings.startsWithUTF8BOM(' ' + strings.UTF8_BOM_CHARACTER));
|
||||
assert(!strings.startsWithUTF8BOM('foo'));
|
||||
assert(!strings.startsWithUTF8BOM(''));
|
||||
});
|
||||
|
||||
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(''), '');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -368,6 +368,23 @@ suite('URI', () => {
|
||||
assert.equal(value.toString(), 'http://l%C3%B6calhost:8080/far');
|
||||
});
|
||||
|
||||
test('URI#toString, user information in authority', () => {
|
||||
var value = URI.parse('http://foo:bar@localhost/far');
|
||||
assert.equal(value.toString(), 'http://foo:bar@localhost/far');
|
||||
|
||||
value = URI.parse('http://foo@localhost/far');
|
||||
assert.equal(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');
|
||||
|
||||
value = URI.parse('http://foo@localhost:8080/far');
|
||||
assert.equal(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');
|
||||
});
|
||||
|
||||
test('correctFileUriToFilePath2', () => {
|
||||
|
||||
var test = (input: string, expected: string) => {
|
||||
|
||||
152
src/vs/base/test/common/winjs.polyfill.promise.test.ts
Normal file
152
src/vs/base/test/common/winjs.polyfill.promise.test.ts
Normal file
@@ -0,0 +1,152 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { PolyfillPromise } from 'vs/base/common/winjs.polyfill.promise';
|
||||
import { Promise as WinJSPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
suite('Polyfill Promise', function () {
|
||||
|
||||
test('sync-resolve, NativePromise', function () {
|
||||
// native promise behaviour
|
||||
const actual: string[] = [];
|
||||
const promise = new Promise(resolve => {
|
||||
actual.push('inCtor');
|
||||
resolve(null);
|
||||
}).then(() => actual.push('inThen'));
|
||||
actual.push('afterCtor');
|
||||
return promise.then(() => {
|
||||
assert.deepEqual(actual, ['inCtor', 'afterCtor', 'inThen']);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync-resolve, WinJSPromise', function () {
|
||||
|
||||
// winjs promise behaviour
|
||||
const actual: string[] = [];
|
||||
const promise = new WinJSPromise(resolve => {
|
||||
actual.push('inCtor');
|
||||
resolve(null);
|
||||
}).then(() => actual.push('inThen'));
|
||||
actual.push('afterCtor');
|
||||
return promise.then(() => {
|
||||
assert.deepEqual(actual, ['inCtor', 'inThen', 'afterCtor']);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync-resolve, PolyfillPromise', function () {
|
||||
|
||||
// winjs promise behaviour
|
||||
const actual: string[] = [];
|
||||
const promise = new PolyfillPromise(resolve => {
|
||||
actual.push('inCtor');
|
||||
resolve(null);
|
||||
}).then(() => actual.push('inThen'));
|
||||
actual.push('afterCtor');
|
||||
return promise.then(() => {
|
||||
assert.deepEqual(actual, ['inCtor', 'afterCtor', 'inThen']);
|
||||
});
|
||||
});
|
||||
|
||||
test('PolyfillPromise, executor has two params', function () {
|
||||
return new PolyfillPromise(function () {
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.equal(typeof arguments[0], 'function');
|
||||
assert.equal(typeof arguments[1], 'function');
|
||||
|
||||
arguments[0]();
|
||||
});
|
||||
});
|
||||
|
||||
// run the same tests for the native and polyfill promise
|
||||
(<any[]>[Promise, PolyfillPromise]).forEach(PromiseCtor => {
|
||||
|
||||
test(PromiseCtor.name + ', resolved value', function () {
|
||||
return new PromiseCtor(resolve => resolve(1)).then(value => assert.equal(value, 1));
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', rejected value', function () {
|
||||
return new PromiseCtor((_, reject) => reject(1)).then(null, value => assert.equal(value, 1));
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', catch', function () {
|
||||
return new PromiseCtor((_, reject) => reject(1)).catch(value => assert.equal(value, 1));
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-resolve', function () {
|
||||
return PromiseCtor.resolve(42).then(value => assert.equal(value, 42));
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-reject', function () {
|
||||
return PromiseCtor.reject(42).then(null, value => assert.equal(value, 42));
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-all, 1', function () {
|
||||
return PromiseCtor.all([
|
||||
PromiseCtor.resolve(1),
|
||||
PromiseCtor.resolve(2)
|
||||
]).then(values => {
|
||||
assert.deepEqual(values, [1, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-all, 2', function () {
|
||||
return PromiseCtor.all([
|
||||
PromiseCtor.resolve(1),
|
||||
3,
|
||||
PromiseCtor.resolve(2)
|
||||
]).then(values => {
|
||||
assert.deepEqual(values, [1, 3, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-all, 3', function () {
|
||||
return PromiseCtor.all([
|
||||
PromiseCtor.resolve(1),
|
||||
PromiseCtor.reject(13),
|
||||
PromiseCtor.reject(12),
|
||||
]).catch(values => {
|
||||
assert.deepEqual(values, 13);
|
||||
});
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-race, 1', function () {
|
||||
return PromiseCtor.race([
|
||||
PromiseCtor.resolve(1),
|
||||
PromiseCtor.resolve(2),
|
||||
]).then(value => {
|
||||
assert.deepEqual(value, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-race, 2', function () {
|
||||
return PromiseCtor.race([
|
||||
PromiseCtor.reject(-1),
|
||||
PromiseCtor.resolve(2),
|
||||
]).catch(value => {
|
||||
assert.deepEqual(value, -1);
|
||||
});
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', static-race, 3', function () {
|
||||
return PromiseCtor.race([
|
||||
PromiseCtor.resolve(1),
|
||||
PromiseCtor.reject(2),
|
||||
]).then(value => {
|
||||
assert.deepEqual(value, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test(PromiseCtor.name + ', throw in ctor', function () {
|
||||
return new PromiseCtor(() => {
|
||||
throw new Error('sooo bad');
|
||||
}).catch(err => {
|
||||
assert.equal(err.message, 'sooo bad');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
51
src/vs/base/test/node/console.test.ts
Normal file
51
src/vs/base/test/node/console.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { getFirstFrame } from 'vs/base/node/console';
|
||||
import { normalize } from 'path';
|
||||
|
||||
suite('Console', () => {
|
||||
|
||||
test('getFirstFrame', function () {
|
||||
let stack = 'at vscode.commands.registerCommand (/Users/someone/Desktop/test-ts/out/src/extension.js:18:17)';
|
||||
let frame = getFirstFrame(stack);
|
||||
|
||||
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
|
||||
assert.equal(frame.line, 18);
|
||||
assert.equal(frame.column, 17);
|
||||
|
||||
stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17';
|
||||
frame = getFirstFrame(stack);
|
||||
|
||||
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
|
||||
assert.equal(frame.line, 18);
|
||||
assert.equal(frame.column, 17);
|
||||
|
||||
stack = 'at c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17';
|
||||
frame = getFirstFrame(stack);
|
||||
|
||||
assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
|
||||
assert.equal(frame.line, 18);
|
||||
assert.equal(frame.column, 17);
|
||||
|
||||
stack = 'at e.$executeContributedCommand(c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17)';
|
||||
frame = getFirstFrame(stack);
|
||||
|
||||
assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
|
||||
assert.equal(frame.line, 18);
|
||||
assert.equal(frame.column, 17);
|
||||
|
||||
stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17\nat /Users/someone/Desktop/test-ts/out/src/other.js:28:27\nat /Users/someone/Desktop/test-ts/out/src/more.js:38:37';
|
||||
frame = getFirstFrame(stack);
|
||||
|
||||
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
|
||||
assert.equal(frame.line, 18);
|
||||
assert.equal(frame.column, 17);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,8 @@ import strings = require('vs/base/common/strings');
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import { onError } from 'vs/base/test/common/utils';
|
||||
|
||||
const ignore = () => { };
|
||||
|
||||
suite('Extfs', () => {
|
||||
|
||||
test('mkdirp', function (done: () => void) {
|
||||
@@ -30,7 +32,7 @@ suite('Extfs', () => {
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
}); // 493 = 0755
|
||||
});
|
||||
|
||||
@@ -160,7 +162,7 @@ suite('Extfs', () => {
|
||||
extfs.readdir(path.join(parentDir, 'extfs', id), (error, children) => {
|
||||
assert.equal(children.some(n => n === 'öäü'), true); // Mac always converts to NFD, so
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
});
|
||||
}); // 493 = 0755
|
||||
} else {
|
||||
@@ -197,7 +199,7 @@ suite('Extfs', () => {
|
||||
|
||||
assert.equal(fs.readFileSync(testFile), largeString);
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -228,7 +230,7 @@ suite('Extfs', () => {
|
||||
assert.equal(real, newDir);
|
||||
}
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -243,7 +245,7 @@ suite('Extfs', () => {
|
||||
assert.ok(realpath);
|
||||
assert.ok(!error);
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -262,7 +264,7 @@ suite('Extfs', () => {
|
||||
}
|
||||
assert.ok(realpath);
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@
|
||||
import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import glob = require('vs/base/common/glob');
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
suite('Glob', () => {
|
||||
|
||||
@@ -884,4 +885,56 @@ suite('Glob', () => {
|
||||
// Later expressions take precedence
|
||||
assert.deepEqual(glob.mergeExpressions({ 'a': true, 'b': false, 'c': true }, { 'a': false, 'b': true }), { 'a': false, 'b': true, 'c': true });
|
||||
});
|
||||
|
||||
test('relative pattern - glob star', function () {
|
||||
if (isWindows) {
|
||||
let p = { base: 'C:\\DNXConsoleApp\\foo', pattern: '**/*.cs' };
|
||||
assert(glob.match(p, 'C:\\DNXConsoleApp\\foo\\Program.cs'));
|
||||
assert(glob.match(p, 'C:\\DNXConsoleApp\\foo\\bar\\Program.cs'));
|
||||
assert(!glob.match(p, 'C:\\DNXConsoleApp\\foo\\Program.ts'));
|
||||
assert(!glob.match(p, 'C:\\DNXConsoleApp\\Program.cs'));
|
||||
assert(!glob.match(p, 'C:\\other\\DNXConsoleApp\\foo\\Program.ts'));
|
||||
} else {
|
||||
let p: glob.IRelativePattern = { base: '/DNXConsoleApp/foo', pattern: '**/*.cs' };
|
||||
assert(glob.match(p, '/DNXConsoleApp/foo/Program.cs'));
|
||||
assert(glob.match(p, '/DNXConsoleApp/foo/bar/Program.cs'));
|
||||
assert(!glob.match(p, '/DNXConsoleApp/foo/Program.ts'));
|
||||
assert(!glob.match(p, '/DNXConsoleApp/Program.cs'));
|
||||
assert(!glob.match(p, '/other/DNXConsoleApp/foo/Program.ts'));
|
||||
}
|
||||
});
|
||||
|
||||
test('relative pattern - single star', function () {
|
||||
if (isWindows) {
|
||||
let p = { base: 'C:\\DNXConsoleApp\\foo', pattern: '*.cs' };
|
||||
assert(glob.match(p, 'C:\\DNXConsoleApp\\foo\\Program.cs'));
|
||||
assert(!glob.match(p, 'C:\\DNXConsoleApp\\foo\\bar\\Program.cs'));
|
||||
assert(!glob.match(p, 'C:\\DNXConsoleApp\\foo\\Program.ts'));
|
||||
assert(!glob.match(p, 'C:\\DNXConsoleApp\\Program.cs'));
|
||||
assert(!glob.match(p, 'C:\\other\\DNXConsoleApp\\foo\\Program.ts'));
|
||||
} else {
|
||||
let p: glob.IRelativePattern = { base: '/DNXConsoleApp/foo', pattern: '*.cs' };
|
||||
assert(glob.match(p, '/DNXConsoleApp/foo/Program.cs'));
|
||||
assert(!glob.match(p, '/DNXConsoleApp/foo/bar/Program.cs'));
|
||||
assert(!glob.match(p, '/DNXConsoleApp/foo/Program.ts'));
|
||||
assert(!glob.match(p, '/DNXConsoleApp/Program.cs'));
|
||||
assert(!glob.match(p, '/other/DNXConsoleApp/foo/Program.ts'));
|
||||
}
|
||||
});
|
||||
|
||||
test('relative pattern - single star with path', function () {
|
||||
if (isWindows) {
|
||||
let p = { base: 'C:\\DNXConsoleApp\\foo', pattern: 'something/*.cs' };
|
||||
assert(glob.match(p, 'C:\\DNXConsoleApp\\foo\\something\\Program.cs'));
|
||||
assert(!glob.match(p, 'C:\\DNXConsoleApp\\foo\\Program.cs'));
|
||||
} else {
|
||||
let p: glob.IRelativePattern = { base: '/DNXConsoleApp/foo', pattern: 'something/*.cs' };
|
||||
assert(glob.match(p, '/DNXConsoleApp/foo/something/Program.cs'));
|
||||
assert(!glob.match(p, '/DNXConsoleApp/foo/Program.cs'));
|
||||
}
|
||||
});
|
||||
|
||||
test('pattern with "base" does not explode - #36081', function () {
|
||||
assert.ok(glob.match({ 'base': true }, 'base'));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user