Skip to content

Commit 73bccbb

Browse files
committed
Fix for changes in @types/unist
1 parent ced059f commit 73bccbb

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

test.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @typedef {import('mdast').Root} Root
3+
*/
4+
5+
import assert from 'assert'
16
import test from 'tape'
27
import remark from 'remark'
38
import {headingStyle} from './index.js'
@@ -18,95 +23,101 @@ test('headingStyle', function (t) {
1823
'should NOT fail on undetectable nodes'
1924
)
2025

21-
t.equal(
22-
headingStyle(remark.parse('# ATX').children[0]),
23-
'atx',
24-
'should detect atx'
25-
)
26+
t.equal(headingStyle(parseFirstNode('# ATX')), 'atx', 'should detect atx')
2627

2728
t.equal(
28-
headingStyle(remark.parse('# ATX #').children[0]),
29+
headingStyle(parseFirstNode('# ATX #')),
2930
'atx-closed',
3031
'should detect closed atx'
3132
)
3233

3334
t.equal(
34-
headingStyle(remark.parse('ATX\n===').children[0]),
35+
headingStyle(parseFirstNode('ATX\n===')),
3536
'setext',
3637
'should detect closed setext'
3738
)
3839

3940
t.equal(
40-
headingStyle(remark.parse('### ATX').children[0]),
41+
headingStyle(parseFirstNode('### ATX')),
4142
null,
4243
'should work on ambiguous nodes'
4344
)
4445

4546
t.equal(
46-
headingStyle(remark.parse('### ATX').children[0], 'atx'),
47+
headingStyle(parseFirstNode('### ATX'), 'atx'),
4748
'atx',
4849
'should work on ambiguous nodes (preference to atx)'
4950
)
5051

5152
t.equal(
52-
headingStyle(remark.parse('### ATX').children[0], 'setext'),
53+
headingStyle(parseFirstNode('### ATX'), 'setext'),
5354
'setext',
5455
'should work on ambiguous nodes (preference to setext)'
5556
)
5657

5758
t.equal(
58-
headingStyle(remark.parse('###### ######').children[0]),
59+
headingStyle(parseFirstNode('###### ######')),
5960
'atx-closed',
6061
'should work on empty nodes (#1)'
6162
)
6263

6364
t.equal(
64-
headingStyle(remark.parse('### ###').children[0]),
65+
headingStyle(parseFirstNode('### ###')),
6566
'atx-closed',
6667
'should work on empty nodes (#2)'
6768
)
6869

6970
t.equal(
70-
headingStyle(remark.parse('# #').children[0]),
71+
headingStyle(parseFirstNode('# #')),
7172
'atx-closed',
7273
'should work on empty nodes (#3)'
7374
)
7475

7576
t.equal(
76-
headingStyle(remark.parse('###### ').children[0], 'atx'),
77+
headingStyle(parseFirstNode('###### '), 'atx'),
7778
'atx',
7879
'should work on empty nodes (#4)'
7980
)
8081

8182
t.equal(
82-
headingStyle(remark.parse('### ').children[0], 'atx'),
83+
headingStyle(parseFirstNode('### '), 'atx'),
8384
'atx',
8485
'should work on empty nodes (#5)'
8586
)
8687

8788
t.equal(
88-
headingStyle(remark.parse('## ').children[0]),
89+
headingStyle(parseFirstNode('## ')),
8990
'atx',
9091
'should work on empty nodes (#6)'
9192
)
9293

9394
t.equal(
94-
headingStyle(remark.parse('###### ').children[0], 'setext'),
95+
headingStyle(parseFirstNode('###### '), 'setext'),
9596
'setext',
9697
'should work on empty nodes (#7)'
9798
)
9899

99100
t.equal(
100-
headingStyle(remark.parse('### ').children[0], 'setext'),
101+
headingStyle(parseFirstNode('### '), 'setext'),
101102
'setext',
102103
'should work on empty nodes (#8)'
103104
)
104105

105106
t.equal(
106-
headingStyle(remark.parse('## ').children[0], 'setext'),
107+
headingStyle(parseFirstNode('## '), 'setext'),
107108
'atx',
108109
'should work on empty nodes (#9)'
109110
)
110111

111112
t.end()
112113
})
114+
115+
/**
116+
* @param {string} doc
117+
*/
118+
function parseFirstNode(doc) {
119+
const tree = /** @type {Root} */ (remark.parse(doc))
120+
const head = tree.children[0]
121+
assert(head.type === 'heading')
122+
return head
123+
}

0 commit comments

Comments
 (0)