-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
188 lines (181 loc) · 4.65 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import assert from 'node:assert/strict'
import test from 'node:test'
import {remark} from 'remark'
import remarkReferenceLinks from 'remark-reference-links'
test('remarkReferenceLinks', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(
Object.keys(await import('remark-reference-links')).sort(),
['default']
)
})
await t.test('should work', async function () {
assert.equal(
String(
await remark()
.use(remarkReferenceLinks)
.process(
[
'[foo](http://example.com "Example Domain"), [foo](http://example.com "Example Domain"), [bar](http://example.com "Example Domain").',
'![foo](http://example.com "Example Domain"), ![foo](http://example.com "Example Domain"), ![bar](http://example.com "Example Domain").'
].join('\n')
)
),
[
'[foo][1], [foo][1], [bar][1].',
'![foo][1], ![foo][1], ![bar][1].',
'',
'[1]: http://example.com "Example Domain"',
''
].join('\n')
)
})
await t.test(
'should number reference links in the order they’re seen',
async function () {
assert.equal(
String(
await remark()
.use(remarkReferenceLinks)
.process(
'[foo](http://example.com/1 "Example Domain 1") ![foo](http://example.com/2 "Example Domain 2")'
)
),
[
'[foo][1] ![foo][2]',
'',
'[1]: http://example.com/1 "Example Domain 1"',
'',
'[2]: http://example.com/2 "Example Domain 2"',
''
].join('\n')
)
}
)
await t.test(
'should not coalesce reference links with existing identifiers',
async function () {
assert.equal(
String(
await remark()
.use(remarkReferenceLinks)
.process(
[
'# Hello!',
'This is a [thing][1] and [that](bravo.com) is a [thing][3]',
'and [stuff](delta.com)',
'',
'[1]: alpha.com',
'[3]: charlie.com'
].join('\n')
)
),
[
'# Hello!',
'',
'This is a [thing][1] and [that][2] is a [thing][3]',
'and [stuff][4]',
'',
'[1]: alpha.com',
'',
'[3]: charlie.com',
'',
'[2]: bravo.com',
'',
'[4]: delta.com',
''
].join('\n')
)
}
)
await t.test(
'should support same URLs with different titles',
async function () {
assert.equal(
String(
await remark()
.use(remarkReferenceLinks)
.process('[This](alpha.com "alpha").\n\n[That](alpha.com "bravo").')
),
[
'[This][1].',
'',
'[That][2].',
'',
'[1]: alpha.com "alpha"',
'',
'[2]: alpha.com "bravo"',
''
].join('\n')
)
}
)
await t.test(
'should not reuse the same url as a definition if it has a different title',
async function () {
assert.equal(
String(
await remark()
.use(remarkReferenceLinks)
.process(
[
'[This](alpha.com "alpha").',
'',
'[1]: alpha.com "bravo"',
'[2]: alpha.com "charlie"'
].join('\n')
)
),
[
'[This][3].',
'',
'[1]: alpha.com "bravo"',
'',
'[2]: alpha.com "charlie"',
'',
'[3]: alpha.com "alpha"',
''
].join('\n')
)
}
)
await t.test(
'should use existing definitions if they exist',
async function () {
assert.equal(
String(
await remark()
.use(remarkReferenceLinks)
.process(
[
'[This](alpha.com "alpha").',
'',
'[That](alpha.com).',
'',
'[Thut](bravo.com "charlie").',
'',
'[this]: alpha.com "alpha"',
'[thut]: bravo.com "delta"'
].join('\n')
)
),
[
'[This][this].',
'',
'[That][1].',
'',
'[Thut][2].',
'',
'[this]: alpha.com "alpha"',
'',
'[thut]: bravo.com "delta"',
'',
'[1]: alpha.com',
'',
'[2]: bravo.com "charlie"',
''
].join('\n')
)
}
)
})