wayver's git archive


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

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

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

1use crate::ast::*;
2use crate::parser::parse_markdown;
3
4#[test]
5fn callout() {
6    let doc = parse_markdown("> [!info]\n> a\n").unwrap();
7    assert_eq!(
8        doc,
9        Document {
10            blocks: vec![Block::Callout(Callout {
11                level: "info".to_owned(),
12                title: None,
13                foldable: false,
14                open: true,
15                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
16            })]
17        }
18    );
19}
20
21#[test]
22fn callout_title() {
23    let doc = parse_markdown("> [!info] hello\n> a\n").unwrap();
24    assert_eq!(
25        doc,
26        Document {
27            blocks: vec![Block::Callout(Callout {
28                level: "info".to_owned(),
29                title: Some("hello".to_owned()),
30                foldable: false,
31                open: true,
32                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
33            })]
34        }
35    );
36}
37
38#[test]
39fn callout_nested() {
40    let doc = parse_markdown("> [!info]\n>\n> > [!warning]\n> >\n> > nested\n").unwrap();
41    assert_eq!(
42        doc,
43        Document {
44            blocks: vec![Block::Callout(Callout {
45                level: "info".to_owned(),
46                title: None,
47                foldable: false,
48                open: true,
49                blocks: vec![Block::Callout(Callout {
50                    level: "warning".to_owned(),
51                    title: None,
52                    foldable: false,
53                    open: true,
54                    blocks: vec![Block::Paragraph(vec![Inline::Text("nested".to_owned())]),]
55                })]
56            })]
57        }
58    );
59}
60
61#[test]
62fn callout_nested_title() {
63    let doc = parse_markdown("> [!info]\n>\n> > [!warning] oops\n> >\n> > nested\n").unwrap();
64    assert_eq!(
65        doc,
66        Document {
67            blocks: vec![Block::Callout(Callout {
68                level: "info".to_owned(),
69                title: None,
70                foldable: false,
71                open: true,
72                blocks: vec![Block::Callout(Callout {
73                    level: "warning".to_owned(),
74                    title: Some("oops".to_owned()),
75                    foldable: false,
76                    open: true,
77                    blocks: vec![Block::Paragraph(vec![Inline::Text("nested".to_owned())]),]
78                })]
79            })]
80        }
81    );
82}
83
84#[test]
85fn callout_foldable_open() {
86    let doc = parse_markdown("> [!info]+\n> a\n").unwrap();
87    assert_eq!(
88        doc,
89        Document {
90            blocks: vec![Block::Callout(Callout {
91                level: "info".to_owned(),
92                title: None,
93                foldable: true,
94                open: true,
95                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
96            })]
97        }
98    );
99}
100
101#[test]
102fn callout_foldable_open_title() {
103    let doc = parse_markdown("> [!info]+ hello\n> a\n").unwrap();
104    assert_eq!(
105        doc,
106        Document {
107            blocks: vec![Block::Callout(Callout {
108                level: "info".to_owned(),
109                title: Some("hello".to_owned()),
110                foldable: true,
111                open: true,
112                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
113            })]
114        }
115    );
116}
117
118#[test]
119fn callout_foldable_closed() {
120    let doc = parse_markdown("> [!info]-\n> a\n").unwrap();
121    assert_eq!(
122        doc,
123        Document {
124            blocks: vec![Block::Callout(Callout {
125                level: "info".to_owned(),
126                title: None,
127                foldable: true,
128                open: false,
129                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
130            })]
131        }
132    );
133}
134
135#[test]
136fn callout_foldable_closed_title() {
137    let doc = parse_markdown("> [!info]- hello\n> a\n").unwrap();
138    assert_eq!(
139        doc,
140        Document {
141            blocks: vec![Block::Callout(Callout {
142                level: "info".to_owned(),
143                title: Some("hello".to_owned()),
144                foldable: true,
145                open: false,
146                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
147            })]
148        }
149    );
150}
151