Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/common/linkedText.test.ts
3296 views
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
import assert from 'assert';
7
import { parseLinkedText } from '../../common/linkedText.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
9
10
suite('LinkedText', () => {
11
ensureNoDisposablesAreLeakedInTestSuite();
12
13
test('parses correctly', () => {
14
assert.deepStrictEqual(parseLinkedText('').nodes, []);
15
assert.deepStrictEqual(parseLinkedText('hello').nodes, ['hello']);
16
assert.deepStrictEqual(parseLinkedText('hello there').nodes, ['hello there']);
17
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href).').nodes, [
18
'Some message with ',
19
{ label: 'link text', href: 'http://link.href' },
20
'.'
21
]);
22
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href "and a title").').nodes, [
23
'Some message with ',
24
{ label: 'link text', href: 'http://link.href', title: 'and a title' },
25
'.'
26
]);
27
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href \'and a title\').').nodes, [
28
'Some message with ',
29
{ label: 'link text', href: 'http://link.href', title: 'and a title' },
30
'.'
31
]);
32
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href "and a \'title\'").').nodes, [
33
'Some message with ',
34
{ label: 'link text', href: 'http://link.href', title: 'and a \'title\'' },
35
'.'
36
]);
37
assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href \'and a "title"\').').nodes, [
38
'Some message with ',
39
{ label: 'link text', href: 'http://link.href', title: 'and a "title"' },
40
'.'
41
]);
42
assert.deepStrictEqual(parseLinkedText('Some message with [link text](random stuff).').nodes, [
43
'Some message with [link text](random stuff).'
44
]);
45
assert.deepStrictEqual(parseLinkedText('Some message with [https link](https://link.href).').nodes, [
46
'Some message with ',
47
{ label: 'https link', href: 'https://link.href' },
48
'.'
49
]);
50
assert.deepStrictEqual(parseLinkedText('Some message with [https link](https:).').nodes, [
51
'Some message with [https link](https:).'
52
]);
53
assert.deepStrictEqual(parseLinkedText('Some message with [a command](command:foobar).').nodes, [
54
'Some message with ',
55
{ label: 'a command', href: 'command:foobar' },
56
'.'
57
]);
58
assert.deepStrictEqual(parseLinkedText('Some message with [a command](command:).').nodes, [
59
'Some message with [a command](command:).'
60
]);
61
assert.deepStrictEqual(parseLinkedText('link [one](command:foo "nice") and link [two](http://foo)...').nodes, [
62
'link ',
63
{ label: 'one', href: 'command:foo', title: 'nice' },
64
' and link ',
65
{ label: 'two', href: 'http://foo' },
66
'...'
67
]);
68
assert.deepStrictEqual(parseLinkedText('link\n[one](command:foo "nice")\nand link [two](http://foo)...').nodes, [
69
'link\n',
70
{ label: 'one', href: 'command:foo', title: 'nice' },
71
'\nand link ',
72
{ label: 'two', href: 'http://foo' },
73
'...'
74
]);
75
});
76
77
test('Should match non-greedily', () => {
78
assert.deepStrictEqual(parseLinkedText('a [link text 1](http://link.href "title1") b [link text 2](http://link.href "title2") c').nodes, [
79
'a ',
80
{ label: 'link text 1', href: 'http://link.href', title: 'title1' },
81
' b ',
82
{ label: 'link text 2', href: 'http://link.href', title: 'title2' },
83
' c',
84
]);
85
});
86
});
87
88