-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
149 lines (146 loc) · 3.33 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import assert from 'node:assert/strict'
import test from 'node:test'
import rehypeStringify from 'rehype-stringify'
import remarkBreaks from 'remark-breaks'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
test('remarkBreaks', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('remark-breaks')).sort(), [
'default'
])
})
})
test('fixtures', async function (t) {
const fixtures = [
{
in: 'This is a\nparagraph.',
out: '<p>This is a<br>\nparagraph.</p>',
name: 'no space'
},
{
in: 'This is a \nparagraph.',
out: '<p>This is a<br>\nparagraph.</p>',
name: 'one space'
},
{
in: 'This is a \nparagraph.',
out: '<p>This is a<br>\nparagraph.</p>',
name: 'two spaces'
},
{
in: 'This is a \nparagraph.',
out: '<p>This is a<br>\nparagraph.</p>',
name: 'three spaces'
},
{
in: 'This is a\rparagraph.',
out: '<p>This is a<br>\nparagraph.</p>',
name: 'carriage return'
},
{
in: 'This is a\r\nparagraph.',
out: '<p>This is a<br>\nparagraph.</p>',
name: 'carriage return + line feed'
},
{
in: 'After *phrasing*\nmore.',
out: '<p>After <em>phrasing</em><br>\nmore.</p>',
name: 'after phrasing'
},
{
in: 'Before\n*phrasing*.',
out: '<p>Before<br>\n<em>phrasing</em>.</p>',
name: 'before phrasing'
},
{
in: 'Mul\nti\nple.',
out: '<p>Mul<br>\nti<br>\nple.</p>',
name: 'multiple'
},
{
in: 'None.',
out: '<p>None.</p>',
name: 'none'
},
{
in: [
'no space',
'asd',
'',
'one space ',
'asd',
'',
'one tab ',
'asd',
'',
'in an ![image',
'alt](#)',
'',
'in a [link',
'alt](#)',
'',
'in an *emphasis',
'emphasis*.',
'',
'in a **strong',
'strong**.',
'',
'setext',
'heading',
'===',
'',
'> block',
'> quote.',
'',
'* list',
' item.'
].join('\n'),
out: [
'<p>no space<br>',
'asd</p>',
'<p>one space<br>',
'asd</p>',
'<p>one tab<br>',
'asd</p>',
'<p>in an <img src="#" alt="image',
'alt"></p>',
'<p>in a <a href="#">link<br>',
'alt</a></p>',
'<p>in an <em>emphasis<br>',
'emphasis</em>.</p>',
'<p>in a <strong>strong<br>',
'strong</strong>.</p>',
'<h1>setext<br>',
'heading</h1>',
'<blockquote>',
'<p>block<br>',
'quote.</p>',
'</blockquote>',
'<ul>',
'<li>list<br>',
'item.</li>',
'</ul>'
].join('\n'),
name: 'document'
}
]
let index = -1
while (++index < fixtures.length) {
const fixture = fixtures[index]
await t.test(fixture.name, async function () {
assert.equal(
String(
await unified()
.use(remarkParse)
.use(remarkBreaks)
.use(remarkRehype)
.use(rehypeStringify)
.process(fixture.in)
),
fixture.out
)
})
}
})