-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
100 lines (91 loc) · 2.41 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
/**
* @typedef {import('./index.js').TextrPlugin} TextrPlugin
*/
import assert from 'node:assert/strict'
import test from 'node:test'
import {remark} from 'remark'
import remarkTextr from 'remark-textr'
// @ts-expect-error: untyped.
import typographicQuotes_ from 'typographic-quotes'
/** @type {TextrPlugin} */
const typographicQuotes = typographicQuotes_
test('remarkTextr', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('remark-textr')).sort(), [
'default'
])
})
await t.test('should work without arguments', async function () {
assert.equal(
String(
await remark().use(remarkTextr).process('## spread operator...\n')
),
'## spread operator...\n'
)
})
await t.test('should work without plugins', async function () {
assert.equal(
String(
await remark()
.use(remarkTextr, {options: {locale: 'ru'}})
.process('## spread operator...\n')
),
'## spread operator...\n'
)
})
await t.test('should run textr on a node', async function () {
assert.equal(
String(
await remark()
.use(remarkTextr, {plugins: [ellipses]})
.process(
[
'## spread operator...',
'',
' function(...args) { return args; }',
''
].join('\n')
)
),
[
'## spread operator…',
'',
'```',
'function(...args) { return args; }',
'```',
''
].join('\n')
)
})
await t.test('should support options', async function () {
assert.equal(
String(
await remark()
.use(remarkTextr, {
plugins: ['typographic-ellipses', typographicQuotes],
options: {locale: 'ru'}
})
.process('yo "there" ...\n')
),
'yo «there» …\n'
)
})
t.test('should support syncronous transformer', function () {
assert.equal(
String(
remark()
.use(remarkTextr, {
plugins: [typographicQuotes],
options: {locale: 'ru'}
})
.processSync('yo "there" \n')
),
'yo «there»\n'
)
})
})
// Textr plugin: just a function to replace triple dots to ellipses.
/** @type {TextrPlugin} */
function ellipses(input) {
return input.replace(/\.{3}/gim, '…')
}