| 1 |
use super::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn fenced_codeblock_closed_and_unclosed_root() { |
| 5 |
let arena = Arena::new(); |
| 6 |
let options = Options::default(); |
| 7 |
|
| 8 |
let md_closed = "```\nfn this_has_a_closing_fence() {}\n```\n"; |
| 9 |
let root = parse_document(&arena, md_closed, &options); |
| 10 |
let mut found = false; |
| 11 |
for n in root.descendants() { |
| 12 |
if let NodeValue::CodeBlock(ncb) = &n.data().value { |
| 13 |
assert!(ncb.fenced, "expected fenced code block"); |
| 14 |
assert!(ncb.closed, "expected closed code block"); |
| 15 |
found = true; |
| 16 |
break; |
| 17 |
} |
| 18 |
} |
| 19 |
assert!(found, "expected a code block node"); |
| 20 |
|
| 21 |
let md_unclosed = "```\nfn this_does_not() {}\n"; |
| 22 |
let root2 = parse_document(&arena, md_unclosed, &options); |
| 23 |
let mut found2 = false; |
| 24 |
for n in root2.descendants() { |
| 25 |
if let NodeValue::CodeBlock(ncb) = &n.data().value { |
| 26 |
assert!(ncb.fenced, "expected fenced code block"); |
| 27 |
assert!(!ncb.closed, "expected unclosed code block"); |
| 28 |
found2 = true; |
| 29 |
break; |
| 30 |
} |
| 31 |
} |
| 32 |
assert!(found2, "expected a code block node"); |
| 33 |
} |
| 34 |
|
| 35 |
#[test] |
| 36 |
fn fenced_codeblock_closed_and_unclosed_in_blockquote() { |
| 37 |
let arena = Arena::new(); |
| 38 |
let options = Options::default(); |
| 39 |
|
| 40 |
let md_closed = "> ```\n> fn this_has_a_closing_fence() {}\n> ```\n"; |
| 41 |
let root = parse_document(&arena, md_closed, &options); |
| 42 |
let mut found = false; |
| 43 |
for n in root.descendants() { |
| 44 |
if let NodeValue::CodeBlock(ncb) = &n.data().value { |
| 45 |
assert!(ncb.fenced, "expected fenced code block in blockquote"); |
| 46 |
assert!(ncb.closed, "expected closed code block in blockquote"); |
| 47 |
found = true; |
| 48 |
break; |
| 49 |
} |
| 50 |
} |
| 51 |
assert!(found, "expected a code block node"); |
| 52 |
|
| 53 |
let md_unclosed = "> ```\n> paragraph\n"; |
| 54 |
let root2 = parse_document(&arena, md_unclosed, &options); |
| 55 |
let mut found2 = false; |
| 56 |
for n in root2.descendants() { |
| 57 |
if let NodeValue::CodeBlock(ncb) = &n.data().value { |
| 58 |
assert!(ncb.fenced, "expected fenced code block in blockquote"); |
| 59 |
assert!(!ncb.closed, "expected unclosed code block in blockquote"); |
| 60 |
found2 = true; |
| 61 |
break; |
| 62 |
} |
| 63 |
} |
| 64 |
assert!(found2, "expected a code block node"); |
| 65 |
} |
| 66 |
|
| 67 |
#[test] |
| 68 |
fn fenced_codeblock_closed_sourcepos() { |
| 69 |
assert_ast_match!( |
| 70 |
[], |
| 71 |
"```\ncode\n```", |
| 72 |
(document (1:1-3:3) [ |
| 73 |
(code_block (1:1-3:3) "code\n") |
| 74 |
]) |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
#[test] |
| 79 |
fn fenced_codeblock_unclosed_sourcepos() { |
| 80 |
assert_ast_match!( |
| 81 |
[], |
| 82 |
"```\ncode\n", |
| 83 |
(document (1:1-2:4) [ |
| 84 |
(code_block (1:1-2:4) "code\n") |
| 85 |
]) |
| 86 |
); |
| 87 |
|
| 88 |
assert_ast_match!( |
| 89 |
[], |
| 90 |
"```\n> code\n", |
| 91 |
(document (1:1-2:6) [ |
| 92 |
(code_block (1:1-2:6) "> code\n") |
| 93 |
]) |
| 94 |
); |
| 95 |
|
| 96 |
assert_ast_match!( |
| 97 |
[], |
| 98 |
"> ```\nparagraph\n", |
| 99 |
(document (1:1-2:9) [ |
| 100 |
(block_quote (1:1-1:5) [ |
| 101 |
(code_block (1:3-1:5) "") |
| 102 |
]) |
| 103 |
(paragraph (2:1-2:9) [ |
| 104 |
(text (2:1-2:9) "paragraph") |
| 105 |
]) |
| 106 |
]) |
| 107 |
); |
| 108 |
|
| 109 |
assert_ast_match!( |
| 110 |
[], |
| 111 |
"> ```\n> code\n", |
| 112 |
(document (1:1-2:6) [ |
| 113 |
(block_quote (1:1-2:6) [ |
| 114 |
(code_block (1:3-2:6) "code\n") |
| 115 |
]) |
| 116 |
]) |
| 117 |
); |
| 118 |
|
| 119 |
assert_ast_match!( |
| 120 |
[], |
| 121 |
"* ```\nparagraph\n", |
| 122 |
(document (1:1-2:9) [ |
| 123 |
(list (1:1-1:5) [ |
| 124 |
(item (1:1-1:5) [ |
| 125 |
(code_block (1:3-1:5) "") |
| 126 |
]) |
| 127 |
]) |
| 128 |
(paragraph (2:1-2:9) [ |
| 129 |
(text (2:1-2:9) "paragraph") |
| 130 |
]) |
| 131 |
]) |
| 132 |
); |
| 133 |
|
| 134 |
assert_ast_match!( |
| 135 |
[], |
| 136 |
"```\n* code\n", |
| 137 |
(document (1:1-2:6) [ |
| 138 |
(code_block (1:1-2:6) "* code\n") |
| 139 |
]) |
| 140 |
); |
| 141 |
|
| 142 |
assert_ast_match!( |
| 143 |
[], |
| 144 |
"* ```\n* paragraph\n", |
| 145 |
(document (1:1-2:11) [ |
| 146 |
(list (1:1-2:11) [ |
| 147 |
(item (1:1-1:5) [ |
| 148 |
(code_block (1:3-1:5) "") |
| 149 |
]) |
| 150 |
(item (2:1-2:11) [ |
| 151 |
(paragraph (2:3-2:11) [ |
| 152 |
(text (2:3-2:11) "paragraph") |
| 153 |
]) |
| 154 |
]) |
| 155 |
]) |
| 156 |
]) |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
#[test] |
| 161 |
fn closed_list_between_fenced_codeblocks_sourcepos() { |
| 162 |
assert_ast_match!( |
| 163 |
[], |
| 164 |
"```\n" |
| 165 |
"code\n" |
| 166 |
"```\n" |
| 167 |
"- list\n" |
| 168 |
"```\n" |
| 169 |
"code\n" |
| 170 |
"```\n", |
| 171 |
(document (1:1-7:3) [ |
| 172 |
(code_block (1:1-3:3) "code\n") |
| 173 |
(list (4:1-4:6) [ |
| 174 |
(item (4:1-4:6) [ |
| 175 |
(paragraph (4:3-4:6) [ |
| 176 |
(text (4:3-4:6) "list") |
| 177 |
]) |
| 178 |
]) |
| 179 |
]) |
| 180 |
(code_block (5:1-7:3) "code\n") |
| 181 |
]) |
| 182 |
); |
| 183 |
} |
| 184 |
|
| 185 |
#[test] |
| 186 |
fn closed_list_before_fenced_codeblocks_sourcepos() { |
| 187 |
assert_ast_match!( |
| 188 |
[], |
| 189 |
"- list\n" |
| 190 |
"```\n" |
| 191 |
"code\n" |
| 192 |
"```\n", |
| 193 |
(document (1:1-4:3) [ |
| 194 |
(list (1:1-1:6) [ |
| 195 |
(item (1:1-1:6) [ |
| 196 |
(paragraph (1:3-1:6) [ |
| 197 |
(text (1:3-1:6) "list") |
| 198 |
]) |
| 199 |
]) |
| 200 |
]) |
| 201 |
(code_block (2:1-4:3) "code\n") |
| 202 |
]) |
| 203 |
); |
| 204 |
} |
| 205 |
|
| 206 |
#[test] |
| 207 |
fn closed_list_after_fenced_codeblocks_sourcepos() { |
| 208 |
assert_ast_match!( |
| 209 |
[], |
| 210 |
"```\n" |
| 211 |
"code\n" |
| 212 |
"```\n" |
| 213 |
"- list\n", |
| 214 |
(document (1:1-4:6) [ |
| 215 |
(code_block (1:1-3:3) "code\n") |
| 216 |
(list (4:1-4:6) [ |
| 217 |
(item (4:1-4:6) [ |
| 218 |
(paragraph (4:3-4:6) [ |
| 219 |
(text (4:3-4:6) "list") |
| 220 |
]) |
| 221 |
]) |
| 222 |
]) |
| 223 |
]) |
| 224 |
); |
| 225 |
} |
| 226 |
|
| 227 |
#[test] |
| 228 |
fn nested_list_between_fenced_codeblocks_sourcepos() { |
| 229 |
assert_ast_match!( |
| 230 |
[], |
| 231 |
"```\n" |
| 232 |
"code\n" |
| 233 |
"```\n" |
| 234 |
"1. list\n" |
| 235 |
" * nested list\n" |
| 236 |
"```\n" |
| 237 |
"code\n" |
| 238 |
"```\n", |
| 239 |
(document (1:1-8:3) [ |
| 240 |
(code_block (1:1-3:3) "code\n") |
| 241 |
(list (4:1-5:17) [ |
| 242 |
(item (4:1-5:17) [ |
| 243 |
(paragraph (4:4-4:7) [ |
| 244 |
(text (4:4-4:7) "list") |
| 245 |
]) |
| 246 |
(list (5:5-5:17) [ |
| 247 |
(item (5:5-5:17) [ |
| 248 |
(paragraph (5:7-5:17) [ |
| 249 |
(text (5:7-5:17) "nested list") |
| 250 |
]) |
| 251 |
]) |
| 252 |
]) |
| 253 |
]) |
| 254 |
]) |
| 255 |
(code_block (6:1-8:3) "code\n") |
| 256 |
]) |
| 257 |
); |
| 258 |
} |
| 259 |
|
| 260 |
#[test] |
| 261 |
fn nested_list_before_fenced_codeblock_sourcepos() { |
| 262 |
assert_ast_match!( |
| 263 |
[], |
| 264 |
"1. list\n" |
| 265 |
" * nested list\n" |
| 266 |
"```\n" |
| 267 |
"code\n" |
| 268 |
"```\n", |
| 269 |
(document (1:1-5:3) [ |
| 270 |
(list (1:1-2:17) [ |
| 271 |
(item (1:1-2:17) [ |
| 272 |
(paragraph (1:4-1:7) [ |
| 273 |
(text (1:4-1:7) "list") |
| 274 |
]) |
| 275 |
(list (2:5-2:17) [ |
| 276 |
(item (2:5-2:17) [ |
| 277 |
(paragraph (2:7-2:17) [ |
| 278 |
(text (2:7-2:17) "nested list") |
| 279 |
]) |
| 280 |
]) |
| 281 |
]) |
| 282 |
]) |
| 283 |
]) |
| 284 |
(code_block (3:1-5:3) "code\n") |
| 285 |
]) |
| 286 |
); |
| 287 |
} |
| 288 |
|
| 289 |
#[test] |
| 290 |
fn nested_list_after_fenced_codeblock_sourcepos() { |
| 291 |
assert_ast_match!( |
| 292 |
[], |
| 293 |
"```\n" |
| 294 |
"code\n" |
| 295 |
"```\n" |
| 296 |
"1. list\n" |
| 297 |
" * nested list\n", |
| 298 |
(document (1:1-5:17) [ |
| 299 |
(code_block (1:1-3:3) "code\n") |
| 300 |
(list (4:1-5:17) [ |
| 301 |
(item (4:1-5:17) [ |
| 302 |
(paragraph (4:4-4:7) [ |
| 303 |
(text (4:4-4:7) "list") |
| 304 |
]) |
| 305 |
(list (5:5-5:17) [ |
| 306 |
(item (5:5-5:17) [ |
| 307 |
(paragraph (5:7-5:17) [ |
| 308 |
(text (5:7-5:17) "nested list") |
| 309 |
]) |
| 310 |
]) |
| 311 |
]) |
| 312 |
]) |
| 313 |
]) |
| 314 |
]) |
| 315 |
); |
| 316 |
} |