sable-markdown/src/parser/blocks/tests/link_definition.rs@main
raw
1use crate::{ast::*, parser::parse_markdown};
2
3#[test]
4fn link_definition1() {
5 let doc = parse_markdown("[foo]: /url \"title\"").unwrap();
6 assert_eq!(
7 doc,
8 Document {
9 blocks: vec![Block::Definition(LinkDefinition {
10 label: vec![Inline::Text("foo".to_owned())],
11 destination: "/url".to_owned(),
12 title: Some("title".to_owned())
13 })]
14 }
15 );
16}
17
18#[test]
19fn link_definition2() {
20 let doc = parse_markdown(
21 " [foo]:
22 /url
23 'the title'
24",
25 )
26 .unwrap();
27 assert_eq!(
28 doc,
29 Document {
30 blocks: vec![Block::Definition(LinkDefinition {
31 label: vec![Inline::Text("foo".to_owned())],
32 destination: "/url".to_owned(),
33 title: Some("the title".to_owned())
34 })]
35 }
36 );
37}
38
39#[test]
40fn link_definition3() {
41 let doc = parse_markdown("[Foo*bar\\]]:my_(url) 'title (with parens)'").unwrap();
42 assert_eq!(
43 doc,
44 Document {
45 blocks: vec![Block::Definition(LinkDefinition {
46 label: vec![Inline::Text("Foo*bar]".to_owned())],
47 destination: "my_(url)".to_owned(),
48 title: Some("title (with parens)".to_owned())
49 })]
50 }
51 );
52}
53
54#[test]
55fn link_definition4() {
56 let doc = parse_markdown(
57 "[Foo bar]:
58<my url>
59'title'",
60 )
61 .unwrap();
62 assert_eq!(
63 doc,
64 Document {
65 blocks: vec![Block::Definition(LinkDefinition {
66 label: vec![Inline::Text("Foo bar".to_owned())],
67 destination: "my url".to_owned(),
68 title: Some("title".to_owned())
69 })]
70 }
71 );
72}
73
74#[test]
75fn link_definition5() {
76 let doc = parse_markdown(
77 "[foo]: /url '
78title
79line1
80line2
81'",
82 )
83 .unwrap();
84 assert_eq!(
85 doc,
86 Document {
87 blocks: vec![Block::Definition(LinkDefinition {
88 label: vec![Inline::Text("foo".to_owned())],
89 destination: "/url".to_owned(),
90 title: Some("\ntitle\nline1\nline2\n".to_owned())
91 })]
92 }
93 );
94}
95
96#[test]
97fn link_definition6() {
98 let doc = parse_markdown(
99 "[foo]:
100/url",
101 )
102 .unwrap();
103 assert_eq!(
104 doc,
105 Document {
106 blocks: vec![Block::Definition(LinkDefinition {
107 label: vec![Inline::Text("foo".to_owned())],
108 destination: "/url".to_owned(),
109 title: None
110 })]
111 }
112 );
113}
114
115#[test]
116fn link_definition7() {
117 let doc = parse_markdown("[foo]: <>").unwrap();
118 assert_eq!(
119 doc,
120 Document {
121 blocks: vec![Block::Definition(LinkDefinition {
122 label: vec![Inline::Text("foo".to_owned())],
123 destination: "".to_owned(),
124 title: None
125 })]
126 }
127 );
128}
129
130
167