|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | + |
| 7 | +import * as assert from 'assert'; |
| 8 | +import { MarkdownString } from 'vs/workbench/api/node/extHostTypeConverters'; |
| 9 | +import { isEmptyObject } from 'vs/base/common/types'; |
| 10 | +import { size } from 'vs/base/common/collections'; |
| 11 | + |
| 12 | +suite('ExtHostTypeConverter', function () { |
| 13 | + |
| 14 | + test('MarkdownConvert - uris', function () { |
| 15 | + |
| 16 | + let data = MarkdownString.from('Hello'); |
| 17 | + assert.equal(isEmptyObject(data.uris), true); |
| 18 | + assert.equal(data.value, 'Hello'); |
| 19 | + |
| 20 | + data = MarkdownString.from('Hello [link](foo)'); |
| 21 | + assert.equal(data.value, 'Hello [link](foo)'); |
| 22 | + assert.equal(isEmptyObject(data.uris), true); // no scheme, no uri |
| 23 | + |
| 24 | + data = MarkdownString.from('Hello [link](www.noscheme.bad)'); |
| 25 | + assert.equal(data.value, 'Hello [link](www.noscheme.bad)'); |
| 26 | + assert.equal(isEmptyObject(data.uris), true); // no scheme, no uri |
| 27 | + |
| 28 | + data = MarkdownString.from('Hello [link](foo:path)'); |
| 29 | + assert.equal(data.value, 'Hello [link](foo:path)'); |
| 30 | + assert.equal(size(data.uris), 1); |
| 31 | + assert.ok(!!data.uris['foo:path']); |
| 32 | + |
| 33 | + data = MarkdownString.from('hello@foo.bar'); |
| 34 | + assert.equal(data.value, 'hello@foo.bar'); |
| 35 | + assert.equal(size(data.uris), 1); |
| 36 | + assert.ok(!!data.uris['mailto:hello@foo.bar']); |
| 37 | + |
| 38 | + data = MarkdownString.from('*hello* [click](command:me)'); |
| 39 | + assert.equal(data.value, '*hello* [click](command:me)'); |
| 40 | + assert.equal(size(data.uris), 1); |
| 41 | + assert.ok(!!data.uris['command:me']); |
| 42 | + |
| 43 | + data = MarkdownString.from('*hello* [click](file:///somepath/here). [click](file:///somepath/here)'); |
| 44 | + assert.equal(data.value, '*hello* [click](file:///somepath/here). [click](file:///somepath/here)'); |
| 45 | + assert.equal(size(data.uris), 1); |
| 46 | + assert.ok(!!data.uris['file:///somepath/here']); |
| 47 | + |
| 48 | + data = MarkdownString.from('*hello* [click](file:///somepath/here). [click](file:///somepath/here)'); |
| 49 | + assert.equal(data.value, '*hello* [click](file:///somepath/here). [click](file:///somepath/here)'); |
| 50 | + assert.equal(size(data.uris), 1); |
| 51 | + assert.ok(!!data.uris['file:///somepath/here']); |
| 52 | + |
| 53 | + data = MarkdownString.from('*hello* [click](file:///somepath/here). [click](file:///somepath/here2)'); |
| 54 | + assert.equal(data.value, '*hello* [click](file:///somepath/here). [click](file:///somepath/here2)'); |
| 55 | + assert.equal(size(data.uris), 2); |
| 56 | + assert.ok(!!data.uris['file:///somepath/here']); |
| 57 | + assert.ok(!!data.uris['file:///somepath/here2']); |
| 58 | + }); |
| 59 | +}); |
0 commit comments