@@ -11,6 +11,8 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
11
11
import { toMarkdown } from 'mdast-util-to-markdown'
12
12
import { headingRange } from 'mdast-util-heading-range'
13
13
14
+ // To do: remove casts when `from-markdown` is released.
15
+
14
16
test ( 'headingRange' , async function ( t ) {
15
17
await t . test ( 'should expose the public api' , async function ( ) {
16
18
assert . deepEqual (
@@ -157,13 +159,16 @@ test('headingRange', async function (t) {
157
159
await t . test (
158
160
'should not remove anything when `null` is given' ,
159
161
async function ( ) {
160
- const tree = fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
162
+ const tree = /** @type {Root } */ (
163
+ fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
164
+ )
161
165
162
166
headingRange ( tree , 'foo' , function ( ) {
163
167
return null
164
168
} )
165
169
166
170
assert . equal (
171
+ // @ts -expect-error: remove when `to-markdown` is released.
167
172
toMarkdown ( tree ) ,
168
173
[ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' )
169
174
)
@@ -173,35 +178,46 @@ test('headingRange', async function (t) {
173
178
await t . test (
174
179
'should replace all previous nodes otherwise' ,
175
180
async function ( ) {
176
- const tree = fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
181
+ const tree = /** @type {Root } */ (
182
+ fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
183
+ )
177
184
178
185
headingRange ( tree , 'foo' , function ( ) {
179
186
return [ ]
180
187
} )
181
188
182
- assert . equal ( toMarkdown ( tree ) , [ 'Foo' , '' ] . join ( '\n' ) )
189
+ assert . equal (
190
+ // @ts -expect-error: remove when `to-markdown` is released.
191
+ toMarkdown ( tree ) ,
192
+ [ 'Foo' , '' ] . join ( '\n' )
193
+ )
183
194
}
184
195
)
185
196
186
197
await t . test ( 'should insert all returned nodes' , async function ( ) {
187
- const tree = fromMarkdown (
188
- [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' , '## Baz' , '' ] . join ( '\n' )
198
+ const tree = /** @type {Root } */ (
199
+ fromMarkdown (
200
+ [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' , '## Baz' , '' ] . join ( '\n' )
201
+ )
189
202
)
190
203
191
204
headingRange ( tree , 'foo' , function ( start , _ , end ) {
192
205
return [ start , { type : 'thematicBreak' } , end ]
193
206
} )
194
207
195
208
assert . equal (
209
+ // @ts -expect-error: remove when `to-markdown` is released.
196
210
toMarkdown ( tree ) ,
197
211
[ 'Foo' , '' , '## Foo' , '' , '***' , '' , '## Baz' , '' ] . join ( '\n' )
198
212
)
199
213
} )
200
214
201
215
await t . test ( 'should not insert an empty `end`' , async function ( ) {
202
- const tree = fromMarkdown (
203
- [ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
204
- '\n'
216
+ const tree = /** @type {Root } */ (
217
+ fromMarkdown (
218
+ [ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
219
+ '\n'
220
+ )
205
221
)
206
222
)
207
223
@@ -211,6 +227,7 @@ test('headingRange', async function (t) {
211
227
} )
212
228
213
229
assert . equal (
230
+ // @ts -expect-error: remove when `to-markdown` is released.
214
231
toMarkdown ( tree ) ,
215
232
[ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
216
233
'\n'
@@ -335,7 +352,7 @@ test('headingRange', async function (t) {
335
352
* Output markdown.
336
353
*/
337
354
function checkAndRemove ( value , options ) {
338
- const tree = fromMarkdown ( value )
355
+ const tree = /** @type { Root } */ ( fromMarkdown ( value ) )
339
356
340
357
headingRange ( tree , options , function ( start , _ , end , scope ) {
341
358
assert . equal ( typeof scope . start , 'number' )
@@ -344,5 +361,6 @@ function checkAndRemove(value, options) {
344
361
return [ start , end ]
345
362
} )
346
363
364
+ // @ts -expect-error: remove when `to-markdown` is released.
347
365
return toMarkdown ( tree )
348
366
}
0 commit comments