|
1 | 1 | import assert from 'node:assert/strict'
|
2 | 2 | import test from 'node:test'
|
3 |
| -import {u} from 'unist-builder' |
4 | 3 | import {h} from 'hastscript'
|
| 4 | +import {u} from 'unist-builder' |
5 | 5 | import {fromText} from './index.js'
|
6 |
| -import * as mod from './index.js' |
7 |
| - |
8 |
| -test('fromText', () => { |
9 |
| - assert.deepEqual( |
10 |
| - Object.keys(mod).sort(), |
11 |
| - ['fromText'], |
12 |
| - 'should expose the public api' |
13 |
| - ) |
14 | 6 |
|
15 |
| - assert.deepEqual( |
16 |
| - // @ts-expect-error runtime. |
17 |
| - fromText(u('text'), 'foo'), |
18 |
| - u('text', 'foo'), |
19 |
| - 'should set text nodes' |
| 7 | +test('fromText', async function (t) { |
| 8 | + await t.test('should expose the public api', async function () { |
| 9 | + assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ |
| 10 | + 'fromText' |
| 11 | + ]) |
| 12 | + }) |
| 13 | + |
| 14 | + await t.test('should set text nodes', async function () { |
| 15 | + assert.deepEqual( |
| 16 | + // @ts-expect-error runtime. |
| 17 | + fromText(u('text'), 'foo'), |
| 18 | + u('text', 'foo') |
| 19 | + ) |
| 20 | + }) |
| 21 | + |
| 22 | + await t.test('should reset text nodes (1)', async function () { |
| 23 | + assert.deepEqual( |
| 24 | + // @ts-expect-error runtime. |
| 25 | + fromText(u('text')), |
| 26 | + u('text', '') |
| 27 | + ) |
| 28 | + }) |
| 29 | + |
| 30 | + await t.test('should reset text nodes (2)', async function () { |
| 31 | + assert.deepEqual(fromText(u('text', 'foo')), u('text', '')) |
| 32 | + }) |
| 33 | + |
| 34 | + await t.test('should set parent nodes', async function () { |
| 35 | + assert.deepEqual(fromText(h('p'), 'foo'), h('p', 'foo')) |
| 36 | + }) |
| 37 | + |
| 38 | + await t.test( |
| 39 | + 'should set parent nodes with <br>s if ␊ is used', |
| 40 | + async function () { |
| 41 | + assert.deepEqual( |
| 42 | + fromText(h('p', 'foo'), 'foo\nbar\nbaz'), |
| 43 | + h('p', ['foo', h('br'), 'bar', h('br'), 'baz']) |
| 44 | + ) |
| 45 | + } |
20 | 46 | )
|
21 | 47 |
|
22 |
| - assert.deepEqual( |
23 |
| - // @ts-expect-error runtime. |
24 |
| - fromText(u('text')), |
25 |
| - u('text', ''), |
26 |
| - 'should reset text nodes (1)' |
| 48 | + await t.test( |
| 49 | + 'should set parent nodes with <br>s if ␍ is used', |
| 50 | + async function () { |
| 51 | + assert.deepEqual( |
| 52 | + fromText(h('p', 'foo'), 'foo\rbar\rbaz'), |
| 53 | + h('p', ['foo', h('br'), 'bar', h('br'), 'baz']) |
| 54 | + ) |
| 55 | + } |
27 | 56 | )
|
28 | 57 |
|
29 |
| - assert.deepEqual( |
30 |
| - fromText(u('text', 'foo')), |
31 |
| - u('text', ''), |
32 |
| - 'should reset text nodes (2)' |
| 58 | + await t.test( |
| 59 | + 'should set parent nodes with <br>s if ␍␊ is used', |
| 60 | + async function () { |
| 61 | + assert.deepEqual( |
| 62 | + fromText(h('p', 'foo'), 'foo\r\nbar\r\nbaz'), |
| 63 | + h('p', ['foo', h('br'), 'bar', h('br'), 'baz']) |
| 64 | + ) |
| 65 | + } |
33 | 66 | )
|
34 | 67 |
|
35 |
| - assert.deepEqual( |
36 |
| - fromText(h('p'), 'foo'), |
37 |
| - h('p', 'foo'), |
38 |
| - 'should set parent nodes' |
| 68 | + await t.test( |
| 69 | + 'should set parent nodes with <br>s if a final ␊ is used', |
| 70 | + async function () { |
| 71 | + assert.deepEqual( |
| 72 | + fromText(h('p', 'foo'), 'foo\n'), |
| 73 | + h('p', ['foo', h('br')]) |
| 74 | + ) |
| 75 | + } |
39 | 76 | )
|
40 | 77 |
|
41 |
| - assert.deepEqual( |
42 |
| - fromText(h('p', 'foo'), 'foo\nbar\nbaz'), |
43 |
| - h('p', ['foo', h('br'), 'bar', h('br'), 'baz']), |
44 |
| - 'should set parent nodes with <br>s if ␊ is used' |
| 78 | + await t.test( |
| 79 | + 'should set parent nodes with <br>s if a final ␍␊ is used', |
| 80 | + async function () { |
| 81 | + assert.deepEqual( |
| 82 | + fromText(h('p', 'foo'), 'foo\r'), |
| 83 | + h('p', ['foo', h('br')]) |
| 84 | + ) |
| 85 | + } |
45 | 86 | )
|
46 | 87 |
|
47 |
| - assert.deepEqual( |
48 |
| - fromText(h('p', 'foo'), 'foo\rbar\rbaz'), |
49 |
| - h('p', ['foo', h('br'), 'bar', h('br'), 'baz']), |
50 |
| - 'should set parent nodes with <br>s if ␍ is used' |
| 88 | + await t.test( |
| 89 | + 'should set parent nodes with <br>s if a final ␍␊ is used', |
| 90 | + async function () { |
| 91 | + assert.deepEqual( |
| 92 | + fromText(h('p', 'foo'), 'foo\r\n'), |
| 93 | + h('p', ['foo', h('br')]) |
| 94 | + ) |
| 95 | + } |
51 | 96 | )
|
52 | 97 |
|
53 |
| - assert.deepEqual( |
54 |
| - fromText(h('p', 'foo'), 'foo\r\nbar\r\nbaz'), |
55 |
| - h('p', ['foo', h('br'), 'bar', h('br'), 'baz']), |
56 |
| - 'should set parent nodes with <br>s if ␍␊ is used' |
| 98 | + await t.test( |
| 99 | + 'should set parent nodes with <br>s if an initial ␊ is used', |
| 100 | + async function () { |
| 101 | + assert.deepEqual( |
| 102 | + fromText(h('p', 'foo'), '\nfoo'), |
| 103 | + h('p', [h('br'), 'foo']) |
| 104 | + ) |
| 105 | + } |
57 | 106 | )
|
58 | 107 |
|
59 |
| - assert.deepEqual( |
60 |
| - fromText(h('p', 'foo'), 'foo\n'), |
61 |
| - h('p', ['foo', h('br')]), |
62 |
| - 'should set parent nodes with <br>s if a final ␊ is used' |
| 108 | + await t.test( |
| 109 | + 'should set parent nodes with <br>s if an initial ␍␊ is used', |
| 110 | + async function () { |
| 111 | + assert.deepEqual( |
| 112 | + fromText(h('p', 'foo'), '\rfoo'), |
| 113 | + h('p', [h('br'), 'foo']) |
| 114 | + ) |
| 115 | + } |
63 | 116 | )
|
64 | 117 |
|
65 |
| - assert.deepEqual( |
66 |
| - fromText(h('p', 'foo'), 'foo\r'), |
67 |
| - h('p', ['foo', h('br')]), |
68 |
| - 'should set parent nodes with <br>s if a final ␍␊ is used' |
| 118 | + await t.test( |
| 119 | + 'should set parent nodes with <br>s if an initial ␍␊ is used', |
| 120 | + async function () { |
| 121 | + assert.deepEqual( |
| 122 | + fromText(h('p', 'foo'), '\r\nfoo'), |
| 123 | + h('p', [h('br'), 'foo']) |
| 124 | + ) |
| 125 | + } |
69 | 126 | )
|
70 | 127 |
|
71 |
| - assert.deepEqual( |
72 |
| - fromText(h('p', 'foo'), 'foo\r\n'), |
73 |
| - h('p', ['foo', h('br')]), |
74 |
| - 'should set parent nodes with <br>s if a final ␍␊ is used' |
75 |
| - ) |
76 |
| - |
77 |
| - assert.deepEqual( |
78 |
| - fromText(h('p', 'foo'), '\nfoo'), |
79 |
| - h('p', [h('br'), 'foo']), |
80 |
| - 'should set parent nodes with <br>s if an initial ␊ is used' |
81 |
| - ) |
| 128 | + await t.test('should reset parent nodes (1)', async function () { |
| 129 | + assert.deepEqual(fromText(h('p')), h('p')) |
| 130 | + }) |
82 | 131 |
|
83 |
| - assert.deepEqual( |
84 |
| - fromText(h('p', 'foo'), '\rfoo'), |
85 |
| - h('p', [h('br'), 'foo']), |
86 |
| - 'should set parent nodes with <br>s if an initial ␍␊ is used' |
87 |
| - ) |
88 |
| - |
89 |
| - assert.deepEqual( |
90 |
| - fromText(h('p', 'foo'), '\r\nfoo'), |
91 |
| - h('p', [h('br'), 'foo']), |
92 |
| - 'should set parent nodes with <br>s if an initial ␍␊ is used' |
93 |
| - ) |
94 |
| - |
95 |
| - assert.deepEqual(fromText(h('p')), h('p'), 'should reset parent nodes (1)') |
96 |
| - |
97 |
| - assert.deepEqual( |
98 |
| - fromText(h('p', 'foo')), |
99 |
| - h('p'), |
100 |
| - 'should reset parent nodes (2)' |
101 |
| - ) |
| 132 | + await t.test('should reset parent nodes (2)', async function () { |
| 133 | + assert.deepEqual(fromText(h('p', 'foo')), h('p')) |
| 134 | + }) |
102 | 135 | })
|
0 commit comments