1+ /**
2+ * @typedef {import('mdast').BlockContent } BlockContent
3+ * @typedef {import('mdast').List } List
4+ */
5+
16import test from 'tape'
27import { removePosition } from 'unist-util-remove-position'
38import { fromMarkdown as from } from 'mdast-util-from-markdown'
@@ -554,7 +559,7 @@ test('blockquote', (t) => {
554559 }
555560 ]
556561 } ) ,
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' ,
558563 'should support a list in a block quote'
559564 )
560565
@@ -1931,7 +1936,7 @@ test('list', (t) => {
19311936 }
19321937 ]
19331938 } ) ,
1934- '* a\n\n* ***\n\n* b\n' ,
1939+ '- a\n\n- ***\n\n- b\n' ,
19351940 'should support a list w/ items'
19361941 )
19371942
@@ -1952,7 +1957,7 @@ test('list', (t) => {
19521957 }
19531958 ]
19541959 } ) ,
1955- '* a\n* ***\n' ,
1960+ '- a\n- ***\n' ,
19561961 'should not use blank lines between items for lists w/ `spread: false`'
19571962 )
19581963
@@ -1974,7 +1979,7 @@ test('list', (t) => {
19741979 }
19751980 ]
19761981 } ) ,
1977- '* a\n\n b\n* ***\n' ,
1982+ '- a\n\n b\n- ***\n' ,
19781983 'should support a list w/ `spread: false`, w/ a spread item'
19791984 )
19801985
@@ -2442,6 +2447,122 @@ test('listItem', (t) => {
24422447 'should not use blank lines between child blocks for items w/ `spread: false`'
24432448 )
24442449
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+
24452566 t . end ( )
24462567} )
24472568
@@ -3064,5 +3185,21 @@ test('roundtrip', (t) => {
30643185 'should roundtrip a sole blank line in fenced code'
30653186 )
30663187
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+
30673204 t . end ( )
30683205} )
0 commit comments