wayver's git archive


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

sable-markdown/src/parser/blocks/tests/table.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 table1() {
5    let doc = parse_markdown(
6        "| foo | bar |
7| --- | --- |
8| baz | bim |",
9    )
10    .unwrap();
11    assert_eq!(
12        doc,
13        Document {
14            blocks: vec![Block::Table(Table {
15                rows: vec![
16                    vec![
17                        vec![Inline::Text("foo".to_owned())],
18                        vec![Inline::Text("bar".to_owned())]
19                    ],
20                    vec![
21                        vec![Inline::Text("baz".to_owned())],
22                        vec![Inline::Text("bim".to_owned())]
23                    ]
24                ],
25                alignments: vec![Alignment::None, Alignment::None]
26            })]
27        }
28    );
29}
30
31#[test]
32fn table2() {
33    let doc = parse_markdown(
34        "| foo | bar |
35| :-- | --: |
36| baz | bim |",
37    )
38    .unwrap();
39    assert_eq!(
40        doc,
41        Document {
42            blocks: vec![Block::Table(Table {
43                rows: vec![
44                    vec![
45                        vec![Inline::Text("foo".to_owned())],
46                        vec![Inline::Text("bar".to_owned())]
47                    ],
48                    vec![
49                        vec![Inline::Text("baz".to_owned())],
50                        vec![Inline::Text("bim".to_owned())]
51                    ]
52                ],
53                alignments: vec![Alignment::Left, Alignment::Right]
54            })]
55        }
56    );
57}
58
59#[test]
60fn table3() {
61    let doc = parse_markdown(
62        "| foo | bar |
63| --- | --- |
64| baz | b\\|im |",
65    )
66    .unwrap();
67    assert_eq!(
68        doc,
69        Document {
70            blocks: vec![Block::Table(Table {
71                rows: vec![
72                    vec![
73                        vec![Inline::Text("foo".to_owned())],
74                        vec![Inline::Text("bar".to_owned())]
75                    ],
76                    vec![
77                        vec![Inline::Text("baz".to_owned())],
78                        vec![Inline::Text("b|im".to_owned())]
79                    ]
80                ],
81                alignments: vec![Alignment::None, Alignment::None]
82            })]
83        }
84    );
85}
86
87#[test]
88fn table4() {
89    let doc = parse_markdown(
90        "| abc | def |
91| --- | --- |
92| bar |
93| bar | baz | boo |",
94    )
95    .unwrap();
96    assert_eq!(
97        doc,
98        Document {
99            blocks: vec![Block::Table(Table {
100                rows: vec![
101                    vec![
102                        vec![Inline::Text("abc".to_owned())],
103                        vec![Inline::Text("def".to_owned())]
104                    ],
105                    vec![
106                        vec![Inline::Text("bar".to_owned())],
107                        vec![Inline::Text(String::new())],
108                    ],
109                    vec![
110                        vec![Inline::Text("bar".to_owned())],
111                        vec![Inline::Text("baz".to_owned())],
112                    ]
113                ],
114                alignments: vec![Alignment::None, Alignment::None]
115            })]
116        }
117    );
118}
119