Markdown parser fork with extended syntax for personal use.
1use markdown::mdast::{InlineCode, Node};
2use mdast_util_to_markdown::to_markdown as to;
3use pretty_assertions::assert_eq;
4
5#[test]
6fn text() {
7 assert_eq!(
8 to(&Node::InlineCode(InlineCode {
9 value: String::new(),
10 position: None
11 }))
12 .unwrap(),
13 "``\n",
14 "should support an empty code text"
15 );
16
17 assert_eq!(
18 to(&Node::InlineCode(InlineCode {
19 value: String::from("a"),
20 position: None
21 }))
22 .unwrap(),
23 "`a`\n",
24 "should support a code text"
25 );
26
27 assert_eq!(
28 to(&Node::InlineCode(InlineCode {
29 value: String::from(" "),
30 position: None
31 }))
32 .unwrap(),
33 "` `\n",
34 "should support a space"
35 );
36
37 assert_eq!(
38 to(&Node::InlineCode(InlineCode {
39 value: String::from("\n"),
40 position: None
41 }))
42 .unwrap(),
43 "`\n`\n",
44 "should support an eol"
45 );
46
47 assert_eq!(
48 to(&Node::InlineCode(InlineCode {
49 value: String::from(" "),
50 position: None
51 }))
52 .unwrap(),
53 "` `\n",
54 "should support several spaces"
55 );
56
57 assert_eq!(
58 to(&Node::InlineCode(InlineCode {
59 value: String::from("a`b"),
60 position: None
61 }))
62 .unwrap(),
63 "``a`b``\n",
64 "should use a fence of two grave accents if the value contains one"
65 );
66
67 assert_eq!(
68 to(&Node::InlineCode(InlineCode {
69 value: String::from("a``b"),
70 position: None
71 }))
72 .unwrap(),
73 "`a``b`\n",
74 "should use a fence of one grave accent if the value contains two"
75 );
76
77 assert_eq!(
78 to(&Node::InlineCode(InlineCode {
79 value: String::from("a``b`c"),
80 position: None
81 }))
82 .unwrap(),
83 "```a``b`c```\n",
84 "should use a fence of three grave accents if the value contains two and one"
85 );
86
87 assert_eq!(
88 to(&Node::InlineCode(InlineCode {
89 value: String::from("`a"),
90 position: None
91 }))
92 .unwrap(),
93 "`` `a ``\n",
94 "should pad w/ a space if the value starts w/ a grave accent"
95 );
96
97 assert_eq!(
98 to(&Node::InlineCode(InlineCode {
99 value: String::from("a`"),
100 position: None
101 }))
102 .unwrap(),
103 "`` a` ``\n",
104 "should pad w/ a space if the value ends w/ a grave accent"
105 );
106
107 assert_eq!(
108 to(&Node::InlineCode(InlineCode {
109 value: String::from(" a "),
110 position: None
111 }))
112 .unwrap(),
113 "` a `\n",
114 "should pad w/ a space if the value starts and ends w/ a space"
115 );
116
117 assert_eq!(
118 to(&Node::InlineCode(InlineCode {
119 value: String::from(" a"),
120 position: None
121 }))
122 .unwrap(),
123 "` a`\n",
124 "should not pad w/ spaces if the value ends w/ a non-space"
125 );
126
127 assert_eq!(
128 to(&Node::InlineCode(InlineCode {
129 value: String::from("a "),
130 position: None
131 }))
132 .unwrap(),
133 "`a `\n",
134 "should not pad w/ spaces if the value starts w/ a non-space"
135 );
136
137 assert_eq!(
138 to(&Node::InlineCode(InlineCode {
139 value: String::from("a\n- b"),
140 position: None
141 }))
142 .unwrap(),
143 "`a - b`\n",
144 "should prevent breaking out of code (-)"
145 );
146
147 assert_eq!(
148 to(&Node::InlineCode(InlineCode {
149 value: String::from("a\n#"),
150 position: None
151 }))
152 .unwrap(),
153 "`a #`\n",
154 "should prevent breaking out of code (#)"
155 );
156
157 assert_eq!(
158 to(&Node::InlineCode(InlineCode {
159 value: String::from("a\n1. "),
160 position: None
161 }))
162 .unwrap(),
163 "`a 1. `\n",
164 "should prevent breaking out of code (\\d\\.)"
165 );
166
167 assert_eq!(
168 to(&Node::InlineCode(InlineCode {
169 value: String::from("a\r- b"),
170 position: None
171 }))
172 .unwrap(),
173 "`a - b`\n",
174 "should prevent breaking out of code (cr)"
175 );
176
177 assert_eq!(
178 to(&Node::InlineCode(InlineCode {
179 value: String::from("a\r\n- b"),
180 position: None
181 }))
182 .unwrap(),
183 "`a - b`\n",
184 "should prevent breaking out of code (crlf)"
185 );
186}