wayver's git archive


an obsidian renderer
git clone https://git.wayver.dev/sable

sable-markdown/src/parser/blocks/tests/list.rs@2b84405277e54ab809e328cf0237374d4b4dbd0c

raw
Date Commit Message Author Files + -
2026-02-23 01:55 initial mvp wayverd 139 17808 0
...

1use crate::{ast::*, parser::parse_markdown};
2
3#[test]
4fn list1() {
5    let doc = parse_markdown("1. a").unwrap();
6    assert_eq!(
7        doc,
8        Document {
9            blocks: vec![Block::List(List {
10                kind: ListKind::Ordered(ListOrderedKindOptions { start: 1 }),
11                items: vec![ListItem {
12                    task: None,
13                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
14                }]
15            })]
16        }
17    );
18}
19
20#[test]
21fn list2() {
22    let doc = parse_markdown("0100. a").unwrap();
23    assert_eq!(
24        doc,
25        Document {
26            blocks: vec![Block::List(List {
27                kind: ListKind::Ordered(ListOrderedKindOptions { start: 100 }),
28                items: vec![ListItem {
29                    task: None,
30                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
31                }]
32            })]
33        }
34    );
35}
36
37#[test]
38fn list3() {
39    let doc = parse_markdown("1) a").unwrap();
40    assert_eq!(
41        doc,
42        Document {
43            blocks: vec![Block::List(List {
44                kind: ListKind::Ordered(ListOrderedKindOptions { start: 1 }),
45                items: vec![ListItem {
46                    task: None,
47                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
48                }]
49            })]
50        }
51    );
52}
53
54#[test]
55fn list4() {
56    let doc = parse_markdown(" -   a").unwrap();
57    assert_eq!(
58        doc,
59        Document {
60            blocks: vec![Block::List(List {
61                kind: ListKind::Bullet(ListBulletKind::Dash),
62                items: vec![ListItem {
63                    task: None,
64                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
65                }]
66            })]
67        }
68    );
69}
70
71#[test]
72fn list5() {
73    let doc = parse_markdown("1. a\n2. b").unwrap();
74    assert_eq!(
75        doc,
76        Document {
77            blocks: vec![Block::List(List {
78                kind: ListKind::Ordered(ListOrderedKindOptions { start: 1 }),
79                items: vec![
80                    ListItem {
81                        task: None,
82                        blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
83                    },
84                    ListItem {
85                        task: None,
86                        blocks: vec![Block::Paragraph(vec![Inline::Text("b".to_owned())])]
87                    }
88                ]
89            })]
90        }
91    );
92}
93
94#[test]
95fn list6() {
96    let doc = parse_markdown(" - a\nb").unwrap();
97    assert_eq!(
98        doc,
99        Document {
100            blocks: vec![Block::List(List {
101                kind: ListKind::Bullet(ListBulletKind::Dash),
102                items: vec![ListItem {
103                    task: None,
104                    blocks: vec![Block::Paragraph(vec![Inline::Text("a\nb".to_owned())])]
105                }]
106            })]
107        }
108    );
109}
110
111#[test]
112fn list7() {
113    let doc = parse_markdown(" - a\nb\n\nc").unwrap();
114    assert_eq!(
115        doc,
116        Document {
117            blocks: vec![
118                Block::List(List {
119                    kind: ListKind::Bullet(ListBulletKind::Dash),
120                    items: vec![ListItem {
121                        task: None,
122                        blocks: vec![Block::Paragraph(vec![Inline::Text("a\nb".to_owned())])]
123                    }]
124                }),
125                Block::Paragraph(vec![Inline::Text("c".to_owned())])
126            ]
127        },
128    );
129}
130
131#[test]
132fn list8() {
133    let doc = parse_markdown(" - a\nb\n\n   c").unwrap();
134    assert_eq!(
135        doc,
136        Document {
137            blocks: vec![Block::List(List {
138                kind: ListKind::Bullet(ListBulletKind::Dash),
139                items: vec![ListItem {
140                    task: None,
141                    blocks: vec![
142                        Block::Paragraph(vec![Inline::Text("a\nb".to_owned())]),
143                        Block::Paragraph(vec![Inline::Text("c".to_owned())]),
144                    ]
145                }]
146            })]
147        },
148    );
149}
150
151#[test]
152fn list9() {
153    let doc = parse_markdown("1. list1\n   * list2\n   * list2\n2. list1").unwrap();
154    assert_eq!(
155        doc,
156        Document {
157            blocks: vec![Block::List(List {
158                kind: ListKind::Ordered(ListOrderedKindOptions { start: 1 }),
159                items: vec![
160                    ListItem {
161                        task: None,
162                        blocks: vec![
163                            Block::Paragraph(vec![Inline::Text("list1".to_owned())]),
164                            Block::List(List {
165                                kind: ListKind::Bullet(ListBulletKind::Star),
166                                items: vec![
167                                    ListItem {
168                                        task: None,
169                                        blocks: vec![Block::Paragraph(vec![Inline::Text(
170                                            "list2".to_owned()
171                                        )]),]
172                                    },
173                                    ListItem {
174                                        task: None,
175                                        blocks: vec![Block::Paragraph(vec![Inline::Text(
176                                            "list2".to_owned()
177                                        )]),]
178                                    }
179                                ]
180                            })
181                        ]
182                    },
183                    ListItem {
184                        task: None,
185                        blocks: vec![Block::Paragraph(vec![Inline::Text("list1".to_owned())])]
186                    }
187                ]
188            })]
189        },
190    );
191}
192
193#[test]
194fn list10() {
195    let doc = parse_markdown(" * list1\n * list1").unwrap();
196    assert_eq!(
197        doc,
198        Document {
199            blocks: vec![Block::List(List {
200                kind: ListKind::Bullet(ListBulletKind::Star),
201                items: vec![
202                    ListItem {
203                        task: None,
204                        blocks: vec![Block::Paragraph(vec![Inline::Text("list1".to_owned())])]
205                    },
206                    ListItem {
207                        task: None,
208                        blocks: vec![Block::Paragraph(vec![Inline::Text("list1".to_owned())])]
209                    }
210                ]
211            })]
212        },
213    );
214}
215
216#[test]
217fn task_list1() {
218    let doc = parse_markdown(" - [ ] a").unwrap();
219    assert_eq!(
220        doc,
221        Document {
222            blocks: vec![Block::List(List {
223                kind: ListKind::Bullet(ListBulletKind::Dash),
224                items: vec![ListItem {
225                    task: Some(TaskState::Incomplete),
226                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
227                }]
228            })]
229        },
230    );
231}
232
233#[test]
234fn task_list2() {
235    let doc = parse_markdown(" - [x] a").unwrap();
236    assert_eq!(
237        doc,
238        Document {
239            blocks: vec![Block::List(List {
240                kind: ListKind::Bullet(ListBulletKind::Dash),
241                items: vec![ListItem {
242                    task: Some(TaskState::Complete),
243                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
244                }]
245            })]
246        },
247    );
248}
249
250#[test]
251fn task_list3() {
252    let doc = parse_markdown(" -   [x]   a").unwrap();
253    assert_eq!(
254        doc,
255        Document {
256            blocks: vec![Block::List(List {
257                kind: ListKind::Bullet(ListBulletKind::Dash),
258                items: vec![ListItem {
259                    task: Some(TaskState::Complete),
260                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
261                }]
262            })]
263        },
264    );
265}
266
267#[test]
268fn task_list4() {
269    let doc = parse_markdown(" - [ ] ").unwrap();
270    assert_eq!(
271        doc,
272        Document {
273            blocks: vec![Block::List(List {
274                kind: ListKind::Bullet(ListBulletKind::Dash),
275                items: vec![ListItem {
276                    task: Some(TaskState::Incomplete),
277                    blocks: vec![]
278                }]
279            })]
280        },
281    );
282}
283
284#[test]
285fn task_list5() {
286    let doc = parse_markdown("  -  [ ] \n\n     a").unwrap();
287    assert_eq!(
288        doc,
289        Document {
290            blocks: vec![Block::List(List {
291                kind: ListKind::Bullet(ListBulletKind::Dash),
292                items: vec![ListItem {
293                    task: Some(TaskState::Incomplete),
294                    blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())])]
295                }]
296            })]
297        },
298    );
299}
300