mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode 1fbacccbc900bb59ba8a8f26a4128d48a1c97842
This commit is contained in:
58
src/vs/base/test/browser/linkedText.test.ts
Normal file
58
src/vs/base/test/browser/linkedText.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { parseLinkedText } from 'vs/base/browser/linkedText';
|
||||
|
||||
suite('LinkedText', () => {
|
||||
test('parses correctly', () => {
|
||||
assert.deepEqual(parseLinkedText(''), []);
|
||||
assert.deepEqual(parseLinkedText('hello'), ['hello']);
|
||||
assert.deepEqual(parseLinkedText('hello there'), ['hello there']);
|
||||
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href).'), [
|
||||
'Some message with ',
|
||||
{ label: 'link text', href: 'http://link.href' },
|
||||
'.'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href "and a title").'), [
|
||||
'Some message with ',
|
||||
{ label: 'link text', href: 'http://link.href', title: 'and a title' },
|
||||
'.'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('Some message with [link text](random stuff).'), [
|
||||
'Some message with [link text](random stuff).'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('Some message with [https link](https://link.href).'), [
|
||||
'Some message with ',
|
||||
{ label: 'https link', href: 'https://link.href' },
|
||||
'.'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('Some message with [https link](https:).'), [
|
||||
'Some message with [https link](https:).'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('Some message with [a command](command:foobar).'), [
|
||||
'Some message with ',
|
||||
{ label: 'a command', href: 'command:foobar' },
|
||||
'.'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('Some message with [a command](command:).'), [
|
||||
'Some message with [a command](command:).'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('link [one](command:foo "nice") and link [two](http://foo)...'), [
|
||||
'link ',
|
||||
{ label: 'one', href: 'command:foo', title: 'nice' },
|
||||
' and link ',
|
||||
{ label: 'two', href: 'http://foo' },
|
||||
'...'
|
||||
]);
|
||||
assert.deepEqual(parseLinkedText('link\n[one](command:foo "nice")\nand link [two](http://foo)...'), [
|
||||
'link\n',
|
||||
{ label: 'one', href: 'command:foo', title: 'nice' },
|
||||
'\nand link ',
|
||||
{ label: 'two', href: 'http://foo' },
|
||||
'...'
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -108,6 +108,7 @@ suite('Resources', () => {
|
||||
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.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');
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 * 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 { ConfigWatcher } from 'vs/base/node/config';
|
||||
import { testFile } from 'vs/base/test/node/utils';
|
||||
|
||||
suite('Config', () => {
|
||||
|
||||
test('defaults', () => {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'config', id);
|
||||
const testFile = path.join(newDir, 'config.json');
|
||||
|
||||
let watcher = new ConfigWatcher<{}>(testFile);
|
||||
|
||||
let config = watcher.getConfig();
|
||||
assert.ok(config);
|
||||
assert.equal(Object.keys(config), 0);
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
let watcher2 = new ConfigWatcher<any[]>(testFile, { defaultConfig: ['foo'], onError: console.error });
|
||||
|
||||
let config2 = watcher2.getConfig();
|
||||
assert.ok(Array.isArray(config2));
|
||||
assert.equal(config2.length, 1);
|
||||
|
||||
watcher.dispose();
|
||||
});
|
||||
|
||||
test('getConfig / getValue', function () {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
|
||||
let config = watcher.getConfig();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
assert.ok(!watcher.hasParseErrors);
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
test('getConfig / getValue - broken JSON', function () {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n "foo": "bar ... ');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
|
||||
let config = watcher.getConfig();
|
||||
assert.ok(config);
|
||||
assert.ok(!config.foo);
|
||||
|
||||
assert.ok(watcher.hasParseErrors);
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
// test('watching', function (done) {
|
||||
// this.timeout(10000); // watching is timing intense
|
||||
|
||||
// testFile('config', 'config.json').then(res => {
|
||||
// fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
// let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
// watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
// fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "changed" }');
|
||||
|
||||
// watcher.onDidUpdateConfiguration(event => {
|
||||
// assert.ok(event);
|
||||
// assert.equal(event.config.foo, 'changed');
|
||||
// assert.equal(watcher.getValue('foo'), 'changed');
|
||||
|
||||
// watcher.dispose();
|
||||
|
||||
// res.cleanUp().then(done, done);
|
||||
// });
|
||||
// }, done);
|
||||
// });
|
||||
|
||||
// test('watching also works when file created later', function (done) {
|
||||
// this.timeout(10000); // watching is timing intense
|
||||
|
||||
// testFile('config', 'config.json').then(res => {
|
||||
// let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
// watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
// fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "changed" }');
|
||||
|
||||
// watcher.onDidUpdateConfiguration(event => {
|
||||
// assert.ok(event);
|
||||
// assert.equal(event.config.foo, 'changed');
|
||||
// assert.equal(watcher.getValue('foo'), 'changed');
|
||||
|
||||
// watcher.dispose();
|
||||
|
||||
// res.cleanUp().then(done, done);
|
||||
// });
|
||||
// }, done);
|
||||
// });
|
||||
|
||||
// test('watching detects the config file getting deleted', function (done) {
|
||||
// this.timeout(10000); // watching is timing intense
|
||||
|
||||
// testFile('config', 'config.json').then(res => {
|
||||
// fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
// let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
// watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
// watcher.onDidUpdateConfiguration(event => {
|
||||
// assert.ok(event);
|
||||
|
||||
// watcher.dispose();
|
||||
|
||||
// res.cleanUp().then(done, done);
|
||||
// });
|
||||
|
||||
// fs.unlinkSync(res.testFile);
|
||||
// }, done);
|
||||
// });
|
||||
|
||||
test('reload', function (done) {
|
||||
testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile, { changeBufferDelay: 100, onError: console.error, defaultConfig: { foo: 'bar' } });
|
||||
watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "changed" }');
|
||||
|
||||
// still old values because change is not bubbling yet
|
||||
assert.equal(watcher.getConfig().foo, 'bar');
|
||||
|
||||
// force a load from disk
|
||||
watcher.reload(config => {
|
||||
assert.equal(config.foo, 'changed');
|
||||
assert.equal(watcher.getConfig().foo, 'changed');
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
res.cleanUp().then(done, done);
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user