|
| 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 * as assert from 'assert'; |
| 7 | +import { parseLinkedText } from 'vs/base/browser/linkedText'; |
| 8 | + |
| 9 | +suite('LinkedText', () => { |
| 10 | + test('parses correctly', () => { |
| 11 | + assert.deepEqual(parseLinkedText(''), []); |
| 12 | + assert.deepEqual(parseLinkedText('hello'), ['hello']); |
| 13 | + assert.deepEqual(parseLinkedText('hello there'), ['hello there']); |
| 14 | + assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href).'), [ |
| 15 | + 'Some message with ', |
| 16 | + { label: 'link text', href: 'http://link.href' }, |
| 17 | + '.' |
| 18 | + ]); |
| 19 | + assert.deepEqual(parseLinkedText('Some message with [link text](http://link.href "and a title").'), [ |
| 20 | + 'Some message with ', |
| 21 | + { label: 'link text', href: 'http://link.href', title: 'and a title' }, |
| 22 | + '.' |
| 23 | + ]); |
| 24 | + assert.deepEqual(parseLinkedText('Some message with [link text](random stuff).'), [ |
| 25 | + 'Some message with [link text](random stuff).' |
| 26 | + ]); |
| 27 | + assert.deepEqual(parseLinkedText('Some message with [https link](https://link.href).'), [ |
| 28 | + 'Some message with ', |
| 29 | + { label: 'https link', href: 'https://link.href' }, |
| 30 | + '.' |
| 31 | + ]); |
| 32 | + assert.deepEqual(parseLinkedText('Some message with [https link](https:).'), [ |
| 33 | + 'Some message with [https link](https:).' |
| 34 | + ]); |
| 35 | + assert.deepEqual(parseLinkedText('Some message with [a command](command:foobar).'), [ |
| 36 | + 'Some message with ', |
| 37 | + { label: 'a command', href: 'command:foobar' }, |
| 38 | + '.' |
| 39 | + ]); |
| 40 | + assert.deepEqual(parseLinkedText('Some message with [a command](command:).'), [ |
| 41 | + 'Some message with [a command](command:).' |
| 42 | + ]); |
| 43 | + assert.deepEqual(parseLinkedText('link [one](command:foo "nice") and link [two](http://foo)...'), [ |
| 44 | + 'link ', |
| 45 | + { label: 'one', href: 'command:foo', title: 'nice' }, |
| 46 | + ' and link ', |
| 47 | + { label: 'two', href: 'http://foo' }, |
| 48 | + '...' |
| 49 | + ]); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +/* |
| 54 | +[I'm an inline-style link](https://www.google.com) |
| 55 | +
|
| 56 | +[I'm an inline-style link with title](https://www.google.com "Google's Homepage") |
| 57 | +
|
| 58 | +[I'm a reference-style link][Arbitrary case-insensitive reference text] |
| 59 | +
|
| 60 | +[I'm a relative reference to a repository file](../blob/master/LICENSE) |
| 61 | +
|
| 62 | +[You can use numbers for reference-style link definitions][1] |
| 63 | +*/ |
0 commit comments