@@ -9,35 +9,39 @@ import test from 'tape'
9
9
import remark from 'remark'
10
10
import { headingRange } from './index.js'
11
11
12
- test ( 'mdast-util-heading-range()' , function ( t ) {
13
- t . plan ( 57 )
12
+ test ( 'mdast-util-heading-range()' , ( t ) => {
13
+ t . plan ( 58 )
14
14
15
15
t . equal ( typeof headingRange , 'function' , 'should be a function' )
16
16
17
17
t . throws (
18
- function ( ) {
18
+ ( ) => {
19
19
headingRange (
20
20
/** @type {Root } */ ( { type : 'root' , children : [ ] } ) ,
21
21
null ,
22
- function ( ) { }
22
+ ( ) => { }
23
23
)
24
24
} ,
25
25
/ ^ T y p e E r r o r : E x p e c t e d ` s t r i n g ` , ` r e g e x p ` , o r ` f u n c t i o n ` f o r ` t e s t ` , n o t ` n u l l ` $ / ,
26
26
'should throw when `null` is passed in'
27
27
)
28
28
29
29
t . throws (
30
- function ( ) {
30
+ ( ) => {
31
31
headingRange (
32
32
/** @type {Root } */ ( { type : 'root' , children : [ ] } ) ,
33
33
undefined ,
34
- function ( ) { }
34
+ ( ) => { }
35
35
)
36
36
} ,
37
37
/ ^ T y p e E r r o r : E x p e c t e d ` s t r i n g ` , ` r e g e x p ` , o r ` f u n c t i o n ` f o r ` t e s t ` , n o t ` u n d e f i n e d ` $ / ,
38
38
'should throw when `undefined` is passed in'
39
39
)
40
40
41
+ t . doesNotThrow ( ( ) => {
42
+ headingRange ( /** @type {Root } */ ( { type : 'root' } ) , 'x' , ( ) => { } )
43
+ } , 'should not throw when a non-parent is passed' )
44
+
41
45
t . equal (
42
46
process (
43
47
t ,
@@ -63,7 +67,7 @@ test('mdast-util-heading-range()', function (t) {
63
67
t ,
64
68
[ '# Fo' , '' , '## Fooooo' , '' , 'Bar' , '' , '# Fo' , '' ] . join ( '\n' ) ,
65
69
/** @type {Options } */
66
- function ( value ) {
70
+ ( value ) => {
67
71
return value . toLowerCase ( ) . indexOf ( 'foo' ) === 0
68
72
}
69
73
) ,
@@ -133,58 +137,52 @@ test('mdast-util-heading-range()', function (t) {
133
137
)
134
138
135
139
remark ( )
136
- . use ( function ( ) {
140
+ . use ( ( ) => {
137
141
return function ( node ) {
138
- headingRange ( node , 'foo' , function ( ) {
142
+ headingRange ( node , 'foo' , ( ) => {
139
143
return null
140
144
} )
141
145
}
142
146
} )
143
- . process (
144
- [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) ,
145
- function ( error , file ) {
146
- t . ifError ( error , 'should not fail (#1)' )
147
+ . process ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) , ( error , file ) => {
148
+ t . ifError ( error , 'should not fail (#1)' )
147
149
148
- t . equal (
149
- String ( file ) ,
150
- [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) ,
151
- 'should not remove anything when `null` is given'
152
- )
153
- }
154
- )
150
+ t . equal (
151
+ String ( file ) ,
152
+ [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) ,
153
+ 'should not remove anything when `null` is given'
154
+ )
155
+ } )
155
156
156
157
remark ( )
157
- . use ( function ( ) {
158
+ . use ( ( ) => {
158
159
return function ( node ) {
159
- headingRange ( node , 'foo' , function ( ) {
160
+ headingRange ( node , 'foo' , ( ) => {
160
161
return [ ]
161
162
} )
162
163
}
163
164
} )
164
- . process (
165
- [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) ,
166
- function ( error , file ) {
167
- t . ifError ( error , 'should not fail (#2)' )
165
+ . process ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) , ( error , file ) => {
166
+ t . ifError ( error , 'should not fail (#2)' )
168
167
169
- t . equal (
170
- String ( file ) ,
171
- [ 'Foo' , '' ] . join ( '\n' ) ,
172
- 'should replace all previous nodes otherwise'
173
- )
174
- }
175
- )
168
+ t . equal (
169
+ String ( file ) ,
170
+ [ 'Foo' , '' ] . join ( '\n' ) ,
171
+ 'should replace all previous nodes otherwise'
172
+ )
173
+ } )
176
174
177
175
remark ( )
178
- . use ( function ( ) {
176
+ . use ( ( ) => {
179
177
return function ( node ) {
180
- headingRange ( node , 'foo' , function ( start , _ , end ) {
178
+ headingRange ( node , 'foo' , ( start , _ , end ) => {
181
179
return [ start , { type : 'thematicBreak' } , end ]
182
180
} )
183
181
}
184
182
} )
185
183
. process (
186
184
[ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' , '## Baz' , '' ] . join ( '\n' ) ,
187
- function ( error , file ) {
185
+ ( error , file ) => {
188
186
t . ifError ( error , 'should not fail (#3)' )
189
187
190
188
t . equal (
@@ -196,9 +194,9 @@ test('mdast-util-heading-range()', function (t) {
196
194
)
197
195
198
196
remark ( )
199
- . use ( function ( ) {
197
+ . use ( ( ) => {
200
198
return function ( node ) {
201
- headingRange ( node , 'foo' , function ( start , nodes , end ) {
199
+ headingRange ( node , 'foo' , ( start , nodes , end ) => {
202
200
t . equal ( nodes . length , 3 )
203
201
return [ start , ...nodes , end ]
204
202
} )
@@ -208,7 +206,7 @@ test('mdast-util-heading-range()', function (t) {
208
206
[ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
209
207
'\n'
210
208
) ,
211
- function ( error , file ) {
209
+ ( error , file ) => {
212
210
t . ifError ( error , 'should not fail (#4)' )
213
211
214
212
t . equal (
@@ -325,9 +323,9 @@ test('mdast-util-heading-range()', function (t) {
325
323
*/
326
324
function process ( t , value , options ) {
327
325
return remark ( )
328
- . use ( function ( ) {
326
+ . use ( ( ) => {
329
327
return function ( node ) {
330
- headingRange ( node , options , function ( start , _ , end , scope ) {
328
+ headingRange ( node , options , ( start , _ , end , scope ) => {
331
329
t . equal ( typeof scope . start , 'number' )
332
330
t . assert ( typeof scope . end === 'number' || scope . end === null )
333
331
t . equal ( scope . parent . type , 'root' )
0 commit comments