-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
135 lines (103 loc) · 3.76 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
import test from 'tape';
import { u } from 'unist-builder'
import { remark } from 'remark'
import dedent from 'dedent'
import { removePosition } from 'unist-util-remove-position'
import sectionize from './index.js'
test('sectionize', function (t) {
const document = dedent`
# Heading 1
Some text under heading 1.
## Heading 1.1
Additional text.
## Heading 1.2
_More_ additional text.
### Heading 1.2.1
> Blockquote
Text.
##### Bad heading
Lorem ipsum.
### Heading 1.2.2
Dolor sit amet.
# Heading 2
Another top level heading.
###### Another bad heading
When will it end?
`
const expected = u('root', {}, [
u('section', { depth: 1, data: { hName: 'section' } }, [
u('heading', { depth: 1 }, [u('text', { value: 'Heading 1' })]),
u('paragraph', {}, [u('text', { value: 'Some text under heading 1.' })]),
u('section', { depth: 2, data: { hName: 'section' } }, [
u('heading', { depth: 2 }, [u('text', { value: 'Heading 1.1' })]),
u('paragraph', {}, [u('text', { value: 'Additional text.' })])
]),
u('section', { depth: 2, data: { hName: 'section' } }, [
u('heading', { depth: 2 }, [u('text', { value: 'Heading 1.2' })]),
u('paragraph', {}, [
u('emphasis', {}, [u('text', { value: 'More' })]),
u('text', { value: ' additional text.' })
]),
u('section', { depth: 3, data: { hName: 'section' } }, [
u('heading', { depth: 3 }, [u('text', { value: 'Heading 1.2.1' })]),
u('blockquote', {}, [
u('paragraph', {}, [u('text', { value: 'Blockquote' })])
]),
u('paragraph', {}, [u('text', { value: 'Text.' })]),
u('section', { depth: 5, data: { hName: 'section' } }, [
u('heading', { depth: 5 }, [u('text', { value: 'Bad heading' })]),
u('paragraph', {}, [u('text', { value: 'Lorem ipsum.' })])
])
]),
u('section', { depth: 3, data: { hName: 'section' } }, [
u('heading', { depth: 3 }, [u('text', { value: 'Heading 1.2.2' })]),
u('paragraph', {}, [u('text', { value: 'Dolor sit amet.' })])
])
])
]),
u('section', { depth: 1, data: { hName: 'section' } }, [
u('heading', { depth: 1 }, [u('text', { value: 'Heading 2' })]),
u('paragraph', {}, [u('text', { value: 'Another top level heading.' })]),
u('section', { depth: 6, data: { hName: 'section' } }, [
u('heading', { depth: 6 }, [
u('text', { value: 'Another bad heading' })
]),
u('paragraph', {}, [u('text', { value: 'When will it end?' })])
])
])
])
const tree = remark().parse(document)
sectionize()(tree)
removePosition(tree, true)
t.deepEqual(tree, expected)
t.end()
})
test('sectionize with orphan nodes at start', function (t) {
const document = dedent`
Some orphan text.
> An orphan blockquote.
## Heading 1
Some text under heading 1.
## Heading 2
Additional text.
`
const expected = u('root', {}, [
u('paragraph', {}, [u('text', { value: 'Some orphan text.' })]),
u('blockquote', {}, [
u('paragraph', {}, [u('text', { value: 'An orphan blockquote.' })])
]),
u('section', { depth: 2, data: { hName: 'section' } }, [
u('heading', { depth: 2 }, [u('text', { value: 'Heading 1' })]),
u('paragraph', {}, [u('text', { value: 'Some text under heading 1.' })]),
]),
u('section', { depth: 2, data: { hName: 'section' } }, [
u('heading', { depth: 2 }, [u('text', { value: 'Heading 2' })]),
u('paragraph', {}, [u('text', { value: 'Additional text.' })])
]),
])
const tree = remark().parse(document)
sectionize()(tree)
removePosition(tree, true)
t.deepEqual(tree, expected)
t.end()
})