|
| 1 | +/** |
| 2 | + * @typedef {import('mdast').Root} Root |
| 3 | + * @typedef {import('mdast').Text} Text |
| 4 | + * @typedef {Root['children'][number]|Root} Node |
| 5 | + */ |
| 6 | + |
| 7 | +import assert from 'node:assert' |
1 | 8 | import test from 'tape'
|
2 | 9 | import remark from 'remark'
|
3 | 10 | import {VFile} from 'vfile'
|
4 | 11 | import {source} from './index.js'
|
5 | 12 |
|
6 | 13 | test('unist-util-source', function (t) {
|
7 | 14 | var file = new VFile('> + **[Hello](./example)**\n> world.')
|
| 15 | + /** @type {Node} */ |
| 16 | + // @ts-expect-error: hush. |
8 | 17 | var node = remark().parse(file)
|
9 | 18 |
|
10 | 19 | t.equal(source(node, file), '> + **[Hello](./example)**\n> world.', 'root')
|
11 | 20 |
|
| 21 | + assert(node.type === 'root') |
12 | 22 | node = node.children[0]
|
| 23 | + assert(node.type === 'blockquote') |
13 | 24 | t.equal(
|
14 | 25 | source(node, file),
|
15 | 26 | '> + **[Hello](./example)**\n> world.',
|
16 | 27 | 'block quote'
|
17 | 28 | )
|
18 | 29 |
|
19 | 30 | node = node.children[0]
|
| 31 | + assert(node.type === 'list') |
20 | 32 | t.equal(source(node, file), '+ **[Hello](./example)**\n> world.', 'list')
|
21 | 33 |
|
22 | 34 | node = node.children[0]
|
| 35 | + assert(node.type === 'listItem') |
23 | 36 | t.equal(source(node, file), '+ **[Hello](./example)**\n> world.', 'list item')
|
24 | 37 |
|
25 | 38 | node = node.children[0]
|
| 39 | + assert(node.type === 'paragraph') |
26 | 40 | t.equal(source(node, file), '**[Hello](./example)**\n> world.', 'paragraph')
|
27 | 41 |
|
28 | 42 | node = node.children[0]
|
| 43 | + assert(node.type === 'strong') |
29 | 44 | t.equal(source(node, file), '**[Hello](./example)**', 'strong')
|
30 | 45 |
|
31 | 46 | node = node.children[0]
|
| 47 | + assert(node.type === 'link') |
32 | 48 | t.equal(source(node, file), '[Hello](./example)', 'link')
|
33 | 49 |
|
34 | 50 | node = node.children[0]
|
| 51 | + assert(node.type === 'text') |
35 | 52 | t.equal(source(node, file), 'Hello', 'text')
|
36 | 53 |
|
37 |
| - t.equal(source({type: node.type, value: node.value}, file), null, 'generated') |
| 54 | + t.equal( |
| 55 | + source(/** @type {Text} */ ({type: node.type, value: node.value}), file), |
| 56 | + null, |
| 57 | + 'generated' |
| 58 | + ) |
38 | 59 |
|
39 | 60 | t.equal(source(null, file), null, 'missing')
|
40 | 61 |
|
41 | 62 | file = new VFile('a\r\nb')
|
42 |
| - node = remark().parse(file).children[0] |
| 63 | + // @ts-expect-error: hush. |
| 64 | + node = remark().parse(file) |
| 65 | + assert(node.type === 'root') |
| 66 | + node = node.children[0] |
| 67 | + assert(node.type === 'paragraph') |
43 | 68 |
|
44 | 69 | t.equal(source(node, file), 'a\r\nb', 'cr + lf')
|
45 | 70 |
|
46 | 71 | file = new VFile('a\rb')
|
47 |
| - node = remark().parse(file).children[0] |
| 72 | + // @ts-expect-error: hush. |
| 73 | + node = remark().parse(file) |
| 74 | + assert(node.type === 'root') |
| 75 | + node = node.children[0] |
| 76 | + assert(node.type === 'paragraph') |
48 | 77 |
|
49 | 78 | t.equal(source(node, file), 'a\rb', 'cr')
|
50 | 79 |
|
51 | 80 | file = new VFile('a\n')
|
| 81 | + // @ts-expect-error: hush. |
52 | 82 | node = remark().parse(file)
|
53 | 83 |
|
54 | 84 | t.equal(source(node, file), 'a\n', 'eof eol')
|
55 | 85 |
|
56 | 86 | file = new VFile('a\n\rb')
|
| 87 | + // @ts-expect-error: hush. |
57 | 88 | node = remark().parse(file)
|
58 | 89 |
|
59 | 90 | t.equal(source(node, file), 'a\n\rb', 'blank lines')
|
|
0 commit comments