extHostTypeConverter.test.ts 4.0 KB
Newer Older
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/


import * as assert from 'assert';
J
Johannes Rieken 已提交
8
import { MarkdownString, LogLevel } from 'vs/workbench/api/common/extHostTypeConverters';
9
import { isEmptyObject } from 'vs/base/common/types';
J
Johannes Rieken 已提交
10
import { size, forEach } from 'vs/base/common/collections';
J
Johannes Rieken 已提交
11
import * as types from 'vs/workbench/api/common/extHostTypes';
12
import { LogLevel as _MainLogLevel } from 'vs/platform/log/common/log';
J
Johannes Rieken 已提交
13
import { URI } from 'vs/base/common/uri';
14 15 16 17 18 19 20 21 22 23 24

suite('ExtHostTypeConverter', function () {

	test('MarkdownConvert - uris', function () {

		let data = MarkdownString.from('Hello');
		assert.equal(isEmptyObject(data.uris), true);
		assert.equal(data.value, 'Hello');

		data = MarkdownString.from('Hello [link](foo)');
		assert.equal(data.value, 'Hello [link](foo)');
25 26
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['foo']);
27 28 29

		data = MarkdownString.from('Hello [link](www.noscheme.bad)');
		assert.equal(data.value, 'Hello [link](www.noscheme.bad)');
30 31
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['www.noscheme.bad']);
32 33 34

		data = MarkdownString.from('Hello [link](foo:path)');
		assert.equal(data.value, 'Hello [link](foo:path)');
35 36
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['foo:path']);
37 38 39

		data = MarkdownString.from('hello@foo.bar');
		assert.equal(data.value, 'hello@foo.bar');
40 41
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['mailto:hello@foo.bar']);
42 43 44

		data = MarkdownString.from('*hello* [click](command:me)');
		assert.equal(data.value, '*hello* [click](command:me)');
45 46
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['command:me']);
47 48 49

		data = MarkdownString.from('*hello* [click](file:///somepath/here). [click](file:///somepath/here)');
		assert.equal(data.value, '*hello* [click](file:///somepath/here). [click](file:///somepath/here)');
50 51
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['file:///somepath/here']);
52 53 54

		data = MarkdownString.from('*hello* [click](file:///somepath/here). [click](file:///somepath/here)');
		assert.equal(data.value, '*hello* [click](file:///somepath/here). [click](file:///somepath/here)');
55 56
		assert.equal(size(data.uris!), 1);
		assert.ok(!!data.uris!['file:///somepath/here']);
57 58 59

		data = MarkdownString.from('*hello* [click](file:///somepath/here). [click](file:///somepath/here2)');
		assert.equal(data.value, '*hello* [click](file:///somepath/here). [click](file:///somepath/here2)');
60 61 62
		assert.equal(size(data.uris!), 2);
		assert.ok(!!data.uris!['file:///somepath/here']);
		assert.ok(!!data.uris!['file:///somepath/here2']);
63
	});
64

J
Johannes Rieken 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78
	test('NPM script explorer running a script from the hover does not work #65561', function () {

		let data = MarkdownString.from('*hello* [click](command:npm.runScriptFromHover?%7B%22documentUri%22%3A%7B%22%24mid%22%3A1%2C%22external%22%3A%22file%3A%2F%2F%2Fc%253A%2Ffoo%2Fbaz.ex%22%2C%22path%22%3A%22%2Fc%3A%2Ffoo%2Fbaz.ex%22%2C%22scheme%22%3A%22file%22%7D%2C%22script%22%3A%22dev%22%7D)');
		// assert that both uri get extracted but that the latter is only decoded once...
		assert.equal(size(data.uris!), 2);
		forEach(data.uris!, entry => {
			if (entry.value.scheme === 'file') {
				assert.ok(URI.revive(entry.value).toString().indexOf('file:///c%3A') === 0);
			} else {
				assert.equal(entry.value.scheme, 'command');
			}
		});
	});

79 80 81 82 83 84 85 86 87
	test('LogLevel', () => {
		assert.equal(LogLevel.from(types.LogLevel.Error), _MainLogLevel.Error);
		assert.equal(LogLevel.from(types.LogLevel.Info), _MainLogLevel.Info);
		assert.equal(LogLevel.from(types.LogLevel.Off), _MainLogLevel.Off);

		assert.equal(LogLevel.to(_MainLogLevel.Error), types.LogLevel.Error);
		assert.equal(LogLevel.to(_MainLogLevel.Info), types.LogLevel.Info);
		assert.equal(LogLevel.to(_MainLogLevel.Off), types.LogLevel.Off);
	});
88
});