1
+ /**
2
+ * @typedef {import('mdast').BlockContent } BlockContent
3
+ * @typedef {import('mdast').List } List
4
+ */
5
+
1
6
import test from 'tape'
2
7
import { removePosition } from 'unist-util-remove-position'
3
8
import { fromMarkdown as from } from 'mdast-util-from-markdown'
@@ -554,7 +559,7 @@ test('blockquote', (t) => {
554
559
}
555
560
]
556
561
} ) ,
557
- '> a\n> b\n>\n> * c\n> d\n>\n> * ***\n>\n> * e\n> f\n' ,
562
+ '> a\n> b\n>\n> - c\n> d\n>\n> - ***\n>\n> - e\n> f\n' ,
558
563
'should support a list in a block quote'
559
564
)
560
565
@@ -1931,7 +1936,7 @@ test('list', (t) => {
1931
1936
}
1932
1937
]
1933
1938
} ) ,
1934
- '* a\n\n* ***\n\n* b\n' ,
1939
+ '- a\n\n- ***\n\n- b\n' ,
1935
1940
'should support a list w/ items'
1936
1941
)
1937
1942
@@ -1952,7 +1957,7 @@ test('list', (t) => {
1952
1957
}
1953
1958
]
1954
1959
} ) ,
1955
- '* a\n* ***\n' ,
1960
+ '- a\n- ***\n' ,
1956
1961
'should not use blank lines between items for lists w/ `spread: false`'
1957
1962
)
1958
1963
@@ -1974,7 +1979,7 @@ test('list', (t) => {
1974
1979
}
1975
1980
]
1976
1981
} ) ,
1977
- '* a\n\n b\n* ***\n' ,
1982
+ '- a\n\n b\n- ***\n' ,
1978
1983
'should support a list w/ `spread: false`, w/ a spread item'
1979
1984
)
1980
1985
@@ -2442,6 +2447,122 @@ test('listItem', (t) => {
2442
2447
'should not use blank lines between child blocks for items w/ `spread: false`'
2443
2448
)
2444
2449
2450
+ /**
2451
+ * @param {BlockContent|BlockContent[] } [d]
2452
+ * @returns {List }
2453
+ */
2454
+ function createList ( d ) {
2455
+ return {
2456
+ type : 'list' ,
2457
+ children : [
2458
+ { type : 'listItem' , children : Array . isArray ( d ) ? d : d ? [ d ] : [ ] }
2459
+ ]
2460
+ }
2461
+ }
2462
+
2463
+ t . equal (
2464
+ to ( createList ( createList ( createList ( ) ) ) , { otherBullet : '+' } ) ,
2465
+ '* * +\n' ,
2466
+ 'should support `otherBullet`'
2467
+ )
2468
+
2469
+ t . equal (
2470
+ to ( createList ( createList ( createList ( ) ) ) , { bullet : '-' } ) ,
2471
+ '- - *\n' ,
2472
+ 'should default to an `otherBullet` different from `bullet` (1)'
2473
+ )
2474
+
2475
+ t . equal (
2476
+ to ( createList ( createList ( createList ( ) ) ) , { bullet : '*' } ) ,
2477
+ '* * -\n' ,
2478
+ 'should default to an `otherBullet` different from `bullet` (2)'
2479
+ )
2480
+
2481
+ t . throws (
2482
+ ( ) => {
2483
+ // @ts -expect-error: runtime.
2484
+ to ( createList ( createList ( createList ( ) ) ) , { otherBullet : '?' } )
2485
+ } ,
2486
+ / C a n n o t s e r i a l i z e i t e m s w i t h ` \? ` f o r ` o p t i o n s \. o t h e r B u l l e t ` , e x p e c t e d / ,
2487
+ 'should throw when given an incorrect `otherBullet`'
2488
+ )
2489
+
2490
+ t . throws (
2491
+ ( ) => {
2492
+ to ( createList ( createList ( createList ( ) ) ) , { bullet : '-' , otherBullet : '-' } )
2493
+ } ,
2494
+ / E x p e c t e d ` b u l l e t ` \( ` - ` \) a n d ` o t h e r B u l l e t ` \( ` - ` \) t o b e d i f f e r e n t / ,
2495
+ 'should throw when an `otherBullet` is given equal to `bullet`'
2496
+ )
2497
+
2498
+ t . equal (
2499
+ to ( {
2500
+ type : 'list' ,
2501
+ children : [ { type : 'listItem' , children : [ { type : 'thematicBreak' } ] } ]
2502
+ } ) ,
2503
+ '- ***\n' ,
2504
+ 'should use a different bullet than a thematic rule marker, if the first child of a list item is a thematic break (1)'
2505
+ )
2506
+
2507
+ t . equal (
2508
+ to ( {
2509
+ type : 'list' ,
2510
+ children : [
2511
+ {
2512
+ type : 'listItem' ,
2513
+ children : [
2514
+ { type : 'paragraph' , children : [ { type : 'text' , value : 'a' } ] }
2515
+ ]
2516
+ } ,
2517
+ { type : 'listItem' , children : [ { type : 'thematicBreak' } ] }
2518
+ ]
2519
+ } ) ,
2520
+ '- a\n\n- ***\n' ,
2521
+ 'should use a different bullet than a thematic rule marker, if the first child of a list item is a thematic break (2)'
2522
+ )
2523
+
2524
+ t . equal (
2525
+ to ( createList ( createList ( ) ) ) ,
2526
+ '* *\n' ,
2527
+ 'should *not* use a different bullet for an empty list item in two lists'
2528
+ )
2529
+
2530
+ t . equal (
2531
+ to ( createList ( createList ( createList ( ) ) ) ) ,
2532
+ '* * -\n' ,
2533
+ 'should use a different bullet for an empty list item in three lists'
2534
+ )
2535
+
2536
+ t . equal (
2537
+ to ( createList ( createList ( createList ( createList ( ) ) ) ) ) ,
2538
+ '* * * -\n' ,
2539
+ 'should use a different bullet for an empty list item in four lists'
2540
+ )
2541
+
2542
+ t . equal (
2543
+ to ( createList ( createList ( createList ( createList ( createList ( ) ) ) ) ) ) ,
2544
+ '* * * * -\n' ,
2545
+ 'should use a different bullet for an empty list item in five lists'
2546
+ )
2547
+
2548
+ // Note: this case isn’t needed, but there’s no way to check in the code
2549
+ // that each list item is the head of its parental list.
2550
+ t . equal (
2551
+ to (
2552
+ createList (
2553
+ createList ( [
2554
+ createList ( {
2555
+ type : 'paragraph' ,
2556
+ children : [ { type : 'text' , value : 'a' } ]
2557
+ } ) ,
2558
+ createList ( )
2559
+ ] )
2560
+ )
2561
+ ) ,
2562
+ '* * * a\n\n <!---->\n\n -\n' ,
2563
+ 'should use a different bullet for an empty list item at non-head in two lists'
2564
+ )
2565
+
2445
2566
t . end ( )
2446
2567
} )
2447
2568
@@ -3064,5 +3185,21 @@ test('roundtrip', (t) => {
3064
3185
'should roundtrip a sole blank line in fenced code'
3065
3186
)
3066
3187
3188
+ doc = '* * -\n'
3189
+
3190
+ t . equal (
3191
+ to ( from ( doc ) ) ,
3192
+ doc ,
3193
+ 'should roundtrip an empty list item in two more lists'
3194
+ )
3195
+
3196
+ doc = '- ***\n'
3197
+
3198
+ t . equal (
3199
+ to ( from ( doc ) ) ,
3200
+ doc ,
3201
+ 'should roundtrip a thematic break at the start of a list item'
3202
+ )
3203
+
3067
3204
t . end ( )
3068
3205
} )
0 commit comments