|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 | 3 | var test = require('tape')
|
| 4 | +var vfile = require('vfile') |
4 | 5 | var remark = require('remark')
|
5 | 6 | var source = require('.')
|
6 | 7 |
|
7 | 8 | test('unist-util-source', function (t) {
|
8 |
| - t.plan(10) |
| 9 | + var file = vfile('> + **[Hello](./example)**\n> world.') |
| 10 | + var node = remark().parse(file) |
9 | 11 |
|
10 |
| - remark() |
11 |
| - .use(function () { |
12 |
| - return transformer |
13 |
| - function transformer(tree, file) { |
14 |
| - var node = tree |
| 12 | + t.equal(source(node, file), '> + **[Hello](./example)**\n> world.', 'root') |
15 | 13 |
|
16 |
| - t.equal(source(node, file), '> + **[Hello](./example)**\n> world.') |
| 14 | + node = node.children[0] |
| 15 | + t.equal( |
| 16 | + source(node, file), |
| 17 | + '> + **[Hello](./example)**\n> world.', |
| 18 | + 'block quote' |
| 19 | + ) |
17 | 20 |
|
18 |
| - // Blockquote. |
19 |
| - node = tree.children[0] |
20 |
| - t.equal(source(node, file), '> + **[Hello](./example)**\n> world.') |
| 21 | + node = node.children[0] |
| 22 | + t.equal(source(node, file), '+ **[Hello](./example)**\n> world.', 'list') |
21 | 23 |
|
22 |
| - // List. |
23 |
| - node = node.children[0] |
24 |
| - t.equal(source(node, file), '+ **[Hello](./example)**\nworld.') |
| 24 | + node = node.children[0] |
| 25 | + t.equal(source(node, file), '+ **[Hello](./example)**\n> world.', 'list item') |
25 | 26 |
|
26 |
| - // List-item. |
27 |
| - node = node.children[0] |
28 |
| - t.equal(source(node, file), '+ **[Hello](./example)**\nworld.') |
| 27 | + node = node.children[0] |
| 28 | + t.equal(source(node, file), '**[Hello](./example)**\n> world.', 'paragraph') |
29 | 29 |
|
30 |
| - // Paragraph. |
31 |
| - node = node.children[0] |
32 |
| - t.equal(source(node, file), '**[Hello](./example)**\nworld.') |
| 30 | + node = node.children[0] |
| 31 | + t.equal(source(node, file), '**[Hello](./example)**', 'strong') |
33 | 32 |
|
34 |
| - // Strong. |
35 |
| - node = node.children[0] |
36 |
| - t.equal(source(node, file), '**[Hello](./example)**') |
| 33 | + node = node.children[0] |
| 34 | + t.equal(source(node, file), '[Hello](./example)', 'link') |
37 | 35 |
|
38 |
| - // Link. |
39 |
| - node = node.children[0] |
40 |
| - t.equal(source(node, file), '[Hello](./example)') |
| 36 | + node = node.children[0] |
| 37 | + t.equal(source(node, file), 'Hello', 'text') |
41 | 38 |
|
42 |
| - // Text. |
43 |
| - node = node.children[0] |
44 |
| - t.equal(source(node, file), 'Hello') |
| 39 | + t.equal(source({type: node.type, value: node.value}, file), null, 'generated') |
45 | 40 |
|
46 |
| - // Generated. |
47 |
| - t.equal(source({type: node.type, value: node.value}, file), null) |
| 41 | + t.equal(source(null, file), null, 'missing') |
48 | 42 |
|
49 |
| - // Missing. |
50 |
| - t.equal(source(null, file), null) |
51 |
| - } |
52 |
| - }) |
53 |
| - .processSync(['> + **[Hello](./example)**', '> world.'].join('\n')) |
| 43 | + file = vfile('a\r\nb') |
| 44 | + node = remark().parse(file).children[0] |
| 45 | + |
| 46 | + t.equal(source(node, file), 'a\r\nb', 'cr + lf') |
| 47 | + |
| 48 | + file = vfile('a\rb') |
| 49 | + node = remark().parse(file).children[0] |
| 50 | + |
| 51 | + t.equal(source(node, file), 'a\rb', 'cr') |
| 52 | + |
| 53 | + file = vfile('a\n') |
| 54 | + node = remark().parse(file) |
| 55 | + |
| 56 | + t.equal(source(node, file), 'a\n', 'eof eol') |
| 57 | + |
| 58 | + file = vfile('a\n\rb') |
| 59 | + node = remark().parse(file) |
| 60 | + |
| 61 | + t.equal(source(node, file), 'a\n\rb', 'blank lines') |
| 62 | + |
| 63 | + t.end() |
54 | 64 | })
|
0 commit comments