Path: blob/main/src/vs/base/test/common/linkedText.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { parseLinkedText } from '../../common/linkedText.js';7import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';89suite('LinkedText', () => {10ensureNoDisposablesAreLeakedInTestSuite();1112test('parses correctly', () => {13assert.deepStrictEqual(parseLinkedText('').nodes, []);14assert.deepStrictEqual(parseLinkedText('hello').nodes, ['hello']);15assert.deepStrictEqual(parseLinkedText('hello there').nodes, ['hello there']);16assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href).').nodes, [17'Some message with ',18{ label: 'link text', href: 'http://link.href' },19'.'20]);21assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href "and a title").').nodes, [22'Some message with ',23{ label: 'link text', href: 'http://link.href', title: 'and a title' },24'.'25]);26assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href \'and a title\').').nodes, [27'Some message with ',28{ label: 'link text', href: 'http://link.href', title: 'and a title' },29'.'30]);31assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href "and a \'title\'").').nodes, [32'Some message with ',33{ label: 'link text', href: 'http://link.href', title: 'and a \'title\'' },34'.'35]);36assert.deepStrictEqual(parseLinkedText('Some message with [link text](http://link.href \'and a "title"\').').nodes, [37'Some message with ',38{ label: 'link text', href: 'http://link.href', title: 'and a "title"' },39'.'40]);41assert.deepStrictEqual(parseLinkedText('Some message with [link text](random stuff).').nodes, [42'Some message with [link text](random stuff).'43]);44assert.deepStrictEqual(parseLinkedText('Some message with [https link](https://link.href).').nodes, [45'Some message with ',46{ label: 'https link', href: 'https://link.href' },47'.'48]);49assert.deepStrictEqual(parseLinkedText('Some message with [https link](https:).').nodes, [50'Some message with [https link](https:).'51]);52assert.deepStrictEqual(parseLinkedText('Some message with [a command](command:foobar).').nodes, [53'Some message with ',54{ label: 'a command', href: 'command:foobar' },55'.'56]);57assert.deepStrictEqual(parseLinkedText('Some message with [a command](command:).').nodes, [58'Some message with [a command](command:).'59]);60assert.deepStrictEqual(parseLinkedText('link [one](command:foo "nice") and link [two](http://foo)...').nodes, [61'link ',62{ label: 'one', href: 'command:foo', title: 'nice' },63' and link ',64{ label: 'two', href: 'http://foo' },65'...'66]);67assert.deepStrictEqual(parseLinkedText('link\n[one](command:foo "nice")\nand link [two](http://foo)...').nodes, [68'link\n',69{ label: 'one', href: 'command:foo', title: 'nice' },70'\nand link ',71{ label: 'two', href: 'http://foo' },72'...'73]);74});7576test('Should match non-greedily', () => {77assert.deepStrictEqual(parseLinkedText('a [link text 1](http://link.href "title1") b [link text 2](http://link.href "title2") c').nodes, [78'a ',79{ label: 'link text 1', href: 'http://link.href', title: 'title1' },80' b ',81{ label: 'link text 2', href: 'http://link.href', title: 'title2' },82' c',83]);84});85});868788