-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
105 lines (92 loc) · 2.3 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {compact} from 'mdast-util-compact'
import {u} from 'unist-builder'
test('compact', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('mdast-util-compact')).sort(), [
'compact'
])
})
await t.test('should compact texts', async function () {
const tree = u('paragraph', [
u('text', 'alpha'),
u('text', ' '),
u('text', 'bravo')
])
compact(tree)
assert.deepEqual(tree, u('paragraph', [u('text', 'alpha bravo')]))
})
await t.test('should merge positions', async function () {
const tree = u('paragraph', [
u(
'text',
{position: {start: {line: 1, column: 1}, end: {line: 1, column: 6}}},
'alpha'
),
u(
'text',
{position: {start: {line: 1, column: 6}, end: {line: 1, column: 7}}},
' '
),
u(
'text',
{
position: {
start: {line: 1, column: 7},
end: {line: 1, column: 12}
}
},
'bravo'
)
])
compact(tree)
assert.deepEqual(
tree,
u('paragraph', [
u(
'text',
{position: {start: {line: 1, column: 1}, end: {line: 1, column: 12}}},
'alpha bravo'
)
])
)
})
await t.test(
'should compact texts with incompatible positions',
async function () {
const tree = u('paragraph', [
u('text', 'at'),
u(
'text',
{
position: {
start: {line: 1, column: 3},
end: {line: 1, column: 8}
}
},
'&'
),
u('text', 't')
])
compact(tree)
assert.deepEqual(tree, u('paragraph', [u('text', 'at&t')]))
}
)
await t.test('should compact blockquotes', async function () {
const tree = u('root', [
u('blockquote', [u('paragraph', [u('text', 'Alpha.')])]),
u('blockquote', [u('paragraph', [u('text', 'Bravo.')])])
])
compact(tree)
assert.deepEqual(
tree,
u('root', [
u('blockquote', [
u('paragraph', [u('text', 'Alpha.')]),
u('paragraph', [u('text', 'Bravo.')])
])
])
)
})
})