Debian Codegraph @

src/tests/sourcepos_chars.rs

raw
1 use pretty_assertions::assert_eq;
2
3 use super::*;
4
5 fn first_sourcepos(input: &str, sourcepos_chars: bool) -> Sourcepos {
6 let arena = Arena::new();
7 let mut options = Options::default();
8 options.parse.sourcepos_chars = sourcepos_chars;
9 let root = parse_document(&arena, input, &options);
10 root.descendants()
11 .find(|n| matches!(n.data().value, NodeValue::Paragraph))
12 .map(|n| n.data().sourcepos)
13 .expect("no matching node found")
14 }
15
16 #[test]
17 fn sourcepos_chars_one_byte() {
18 const INPUT: &str = "a";
19 let sp = first_sourcepos(INPUT, false);
20 assert_eq!(sp, sourcepos!((1:1-1:1)));
21 let spc = first_sourcepos(INPUT, true);
22 assert_eq!(spc, sourcepos!((1:1-1:1)));
23 }
24
25 #[test]
26 fn sourcepos_chars_two_byte() {
27 const INPUT: &str = "ษฝ";
28 let sp = first_sourcepos(INPUT, false);
29 assert_eq!(sp, sourcepos!((1:1-1:2)));
30 let spc = first_sourcepos(INPUT, true);
31 assert_eq!(spc, sourcepos!((1:1-1:1)));
32 }
33
34 #[test]
35 fn sourcepos_chars_three_byte() {
36 const INPUT: &str = "ๅฅฝ";
37 let sp = first_sourcepos(INPUT, false);
38 assert_eq!(sp, sourcepos!((1:1-1:3)));
39 let spc = first_sourcepos(INPUT, true);
40 assert_eq!(spc, sourcepos!((1:1-1:1)));
41 }
42
43 #[test]
44 fn sourcepos_chars_four_byte() {
45 const INPUT: &str = "๐€€";
46 let sp = first_sourcepos(INPUT, false);
47 assert_eq!(sp, sourcepos!((1:1-1:4)));
48 let spc = first_sourcepos(INPUT, true);
49 assert_eq!(spc, sourcepos!((1:1-1:1)));
50 }
51
52 #[test]
53 fn sourcepos_chars_multiple_one_byte_characters() {
54 const INPUT: &str = "aaa";
55 let sp = first_sourcepos(INPUT, false);
56 assert_eq!(sp, sourcepos!((1:1-1:3)));
57 let spc = first_sourcepos(INPUT, true);
58 assert_eq!(spc, sourcepos!((1:1-1:3)));
59 }
60
61 #[test]
62 fn sourcepos_chars_multiple_two_byte_characters() {
63 const INPUT: &str = "ษฝษฝษฝ";
64 let sp = first_sourcepos(INPUT, false);
65 assert_eq!(sp, sourcepos!((1:1-1:6)));
66 let spc = first_sourcepos(INPUT, true);
67 assert_eq!(spc, sourcepos!((1:1-1:3)));
68 }
69
70 #[test]
71 fn sourcepos_chars_multiple_three_byte_characters() {
72 const INPUT: &str = "ๅฅฝๅฅฝๅฅฝ";
73 let sp = first_sourcepos(INPUT, false);
74 assert_eq!(sp, sourcepos!((1:1-1:9)));
75 let spc = first_sourcepos(INPUT, true);
76 assert_eq!(spc, sourcepos!((1:1-1:3)));
77 }
78
79 #[test]
80 fn sourcepos_chars_multiple_four_byte_characters() {
81 const INPUT: &str = "๐€€๐€€๐€€";
82 let sp = first_sourcepos(INPUT, false);
83 assert_eq!(sp, sourcepos!((1:1-1:12)));
84 let spc = first_sourcepos(INPUT, true);
85 assert_eq!(spc, sourcepos!((1:1-1:3)));
86 }
87
88 #[test]
89 fn sourcepos_chars_multiple_mixed_characters() {
90 const INPUT: &str = "aษฝๅฅฝ๐€€";
91 let sp = first_sourcepos(INPUT, false);
92 assert_eq!(sp, sourcepos!((1:1-1:10)));
93 let spc = first_sourcepos(INPUT, true);
94 assert_eq!(spc, sourcepos!((1:1-1:4)));
95
96 const REVERSED: &str = "๐€€ๅฅฝษฝa";
97 let sp2 = first_sourcepos(REVERSED, false);
98 assert_eq!(sp2, sourcepos!((1:1-1:10)));
99 let spc2 = first_sourcepos(REVERSED, true);
100 assert_eq!(spc2, sourcepos!((1:1-1:4)));
101
102 const MIXED: &str = "a๐€€ษฝๅฅฝ";
103 let sp3 = first_sourcepos(MIXED, false);
104 assert_eq!(sp3, sourcepos!((1:1-1:10)));
105 let spc3 = first_sourcepos(MIXED, true);
106 assert_eq!(spc3, sourcepos!((1:1-1:4)));
107
108 const REVERSED_MIXED: &str = "ๅฅฝษฝ๐€€a";
109 let sp4 = first_sourcepos(REVERSED_MIXED, false);
110 assert_eq!(sp4, sourcepos!((1:1-1:10)));
111 let spc4 = first_sourcepos(REVERSED_MIXED, true);
112 assert_eq!(spc4, sourcepos!((1:1-1:4)));
113 }
114
115 #[test]
116 fn sourcepos_chars_character_and_combining_characters() {
117 const INPUT: &str = "eฬ";
118 let sp = first_sourcepos(INPUT, false);
119 assert_eq!(sp, sourcepos!((1:1-1:3)));
120 let spc = first_sourcepos(INPUT, true);
121 assert_eq!(spc, sourcepos!((1:1-1:2)));
122
123 const THAI: &str = "เธเน‰เน‰เน‰";
124 let sp2 = first_sourcepos(THAI, false);
125 assert_eq!(sp2, sourcepos!((1:1-1:12)));
126 let spc2 = first_sourcepos(THAI, true);
127 assert_eq!(spc2, sourcepos!((1:1-1:4)));
128 }
129
130 #[test]
131 fn sourcepos_chars_emoji() {
132 // heart without variation selector
133 const ONLY_HEART: &str = "โค";
134 let sp = first_sourcepos(ONLY_HEART, false);
135 assert_eq!(sp, sourcepos!((1:1-1:3)));
136 let spc = first_sourcepos(ONLY_HEART, true);
137 assert_eq!(spc, sourcepos!((1:1-1:1)));
138
139 // heart + variation selector
140 const HEART_WITH_VARIANT: &str = "โค๏ธ";
141 let sp = first_sourcepos(HEART_WITH_VARIANT, false);
142 assert_eq!(sp, sourcepos!((1:1-1:6)));
143 let spc = first_sourcepos(HEART_WITH_VARIANT, true);
144 assert_eq!(spc, sourcepos!((1:1-1:2)));
145
146 // family emoji with multiple code points
147 const FAMILY: &str = "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ";
148 let sp = first_sourcepos(FAMILY, false);
149 assert_eq!(sp, sourcepos!((1:1-1:25)));
150 let spc = first_sourcepos(FAMILY, true);
151 assert_eq!(spc, sourcepos!((1:1-1:7)));
152
153 // family emoji with skin tone modifiers
154 const FAMILY_WITH_SKIN_TONES: &str = "๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ";
155 let sp = first_sourcepos(FAMILY_WITH_SKIN_TONES, false);
156 assert_eq!(sp, sourcepos!((1:1-1:29)));
157 let spc = first_sourcepos(FAMILY_WITH_SKIN_TONES, true);
158 assert_eq!(spc, sourcepos!((1:1-1:8)));
159
160 // flag emoji with regional indicator symbols
161 const FLAG: &str = "๐Ÿ‡บ๐Ÿ‡ธ";
162 let sp = first_sourcepos(FLAG, false);
163 assert_eq!(sp, sourcepos!((1:1-1:8)));
164 let spc = first_sourcepos(FLAG, true);
165 assert_eq!(spc, sourcepos!((1:1-1:2)));
166 }
167
168 #[test]
169 fn sourcepos_chars_confusables() {
170 const INPUT: &str = "๐™ฐA๐ดแ—…๐‘จ๐šจ๐•ฌ๐– ะฮ‘๐›ข๐–๐’œ๐œœ๐–ฝ€๐“๐ž๏ผก๐—”๐˜ˆแŽช๊“ฎ๐€๐”„๐”ธ๐Š ๐˜ผ";
171 let sp = first_sourcepos(INPUT, false);
172 assert_eq!(sp, sourcepos!((1:1-1:97)));
173 let spc = first_sourcepos(INPUT, true);
174 assert_eq!(spc, sourcepos!((1:1-1:27)));
175 }
176
177 #[test]
178 fn sourcepos_chars_rtl() {
179 const INPUT: &str = "ืฉืœื•ื";
180 let sp = first_sourcepos(INPUT, false);
181 assert_eq!(sp, sourcepos!((1:1-1:8)));
182 let spc = first_sourcepos(INPUT, true);
183 assert_eq!(spc, sourcepos!((1:1-1:4)));
184 }
185
186 #[test]
187 fn sourcepos_chars_rtl_ltr_isolates() {
188 const LTR_ISOLATE: &str = "A\u{2066}ืฉืœื•ื\u{2069}B";
189 let sp = first_sourcepos(LTR_ISOLATE, false);
190 assert_eq!(sp, sourcepos!((1:1-1:16)));
191 let spc = first_sourcepos(LTR_ISOLATE, true);
192 assert_eq!(spc, sourcepos!((1:1-1:8)));
193
194 const RTL_ISOLATE: &str = "A\u{2067}ืฉืœื•ื\u{2069}B";
195 let sp2 = first_sourcepos(RTL_ISOLATE, false);
196 assert_eq!(sp2, sourcepos!((1:1-1:16)));
197 let spc2 = first_sourcepos(RTL_ISOLATE, true);
198 assert_eq!(spc2, sourcepos!((1:1-1:8)));
199 }
200
201 #[test]
202 fn sourcepos_chars_one_byte_strong() {
203 // Byte layout of "a**a**a" (7 bytes): a=1, **=2-3, a=4, **=5-6, a=7
204 assert_ast_match!(
205 [],
206 "a**a**a",
207 (document (1:1-1:7) [
208 (paragraph (1:1-1:7) [
209 (text (1:1-1:1) "a")
210 (strong (1:2-1:6) [
211 (text (1:4-1:4) "a")
212 ])
213 (text (1:7-1:7) "a")
214 ])
215 ])
216 );
217
218 // Char layout of "a**a**a" (7 chars): a=1, **=2-3, a=4, **=5-6, a=7
219 assert_ast_match!(
220 [parse.sourcepos_chars],
221 "a**a**a",
222 (document (1:1-1:7) [
223 (paragraph (1:1-1:7) [
224 (text (1:1-1:1) "a")
225 (strong (1:2-1:6) [
226 (text (1:4-1:4) "a")
227 ])
228 (text (1:7-1:7) "a")
229 ])
230 ])
231 );
232 }
233
234 #[test]
235 fn sourcepos_chars_two_byte_strong() {
236 // Byte layout of "ษฝ**ษฝ**ษฝ" (10 bytes): ษฝ=1-2, **=3-4, ษฝ=5-6, **=7-8, ษฝ=9-10
237 assert_ast_match!(
238 [],
239 "ษฝ**ษฝ**ษฝ",
240 (document (1:1-1:10) [
241 (paragraph (1:1-1:10) [
242 (text (1:1-1:2) "ษฝ")
243 (strong (1:3-1:8) [
244 (text (1:5-1:6) "ษฝ")
245 ])
246 (text (1:9-1:10) "ษฝ")
247 ])
248 ])
249 );
250
251 // Char layout of "ษฝ**ษฝ**ษฝ" (7 chars): ษฝ=1, **=2-3, ษฝ=4, **=5-6, ษฝ=7
252 assert_ast_match!(
253 [parse.sourcepos_chars],
254 "ษฝ**ษฝ**ษฝ",
255 (document (1:1-1:7) [
256 (paragraph (1:1-1:7) [
257 (text (1:1-1:1) "ษฝ")
258 (strong (1:2-1:6) [
259 (text (1:4-1:4) "ษฝ")
260 ])
261 (text (1:7-1:7) "ษฝ")
262 ])
263 ])
264 );
265 }
266
267 #[test]
268 fn sourcepos_chars_three_byte_strong() {
269 // Byte layout of "ๅฅฝ**ๅฅฝ**ๅฅฝ" (13 bytes): ๅฅฝ=1-3, **=4-5, ๅฅฝ=6-8, **=9-10, ๅฅฝ=11-13
270 assert_ast_match!(
271 [],
272 "ๅฅฝ**ๅฅฝ**ๅฅฝ",
273 (document (1:1-1:13) [
274 (paragraph (1:1-1:13) [
275 (text (1:1-1:3) "ๅฅฝ")
276 (strong (1:4-1:10) [
277 (text (1:6-1:8) "ๅฅฝ")
278 ])
279 (text (1:11-1:13) "ๅฅฝ")
280 ])
281 ])
282 );
283
284 // Char layout of "ๅฅฝ**ๅฅฝ**ๅฅฝ" (7 chars): ๅฅฝ=1, **=2-3, ๅฅฝ=4, **=5-6, ๅฅฝ=7
285 assert_ast_match!(
286 [parse.sourcepos_chars],
287 "ๅฅฝ**ๅฅฝ**ๅฅฝ",
288 (document (1:1-1:7) [
289 (paragraph (1:1-1:7) [
290 (text (1:1-1:1) "ๅฅฝ")
291 (strong (1:2-1:6) [
292 (text (1:4-1:4) "ๅฅฝ")
293 ])
294 (text (1:7-1:7) "ๅฅฝ")
295 ])
296 ])
297 );
298 }
299
300 #[test]
301 fn sourcepos_chars_four_byte_strong() {
302 // Byte layout of "๐€€**๐€€**๐€€" (16 bytes): ๐€€=1-4, **=5-6, ๐€€=7-10, **=11-12, ๐€€=13-16
303 assert_ast_match!(
304 [],
305 "๐€€**๐€€**๐€€",
306 (document (1:1-1:16) [
307 (paragraph (1:1-1:16) [
308 (text (1:1-1:4) "๐€€")
309 (strong (1:5-1:12) [
310 (text (1:7-1:10) "๐€€")
311 ])
312 (text (1:13-1:16) "๐€€")
313 ])
314 ])
315 );
316
317 // Char layout of "๐€€**๐€€**๐€€" (7 chars): ๐€€=1, **=2-3, ๐€€=4, **=5-6, ๐€€=7
318 assert_ast_match!(
319 [parse.sourcepos_chars],
320 "๐€€**๐€€**๐€€",
321 (document (1:1-1:7) [
322 (paragraph (1:1-1:7) [
323 (text (1:1-1:1) "๐€€")
324 (strong (1:2-1:6) [
325 (text (1:4-1:4) "๐€€")
326 ])
327 (text (1:7-1:7) "๐€€")
328 ])
329 ])
330 );
331 }
332
333 #[test]
334 fn sourcepos_chars_alerts() {
335 assert_ast_match!(
336 [extension.alerts, extension.multiline_block_quotes],
337 ">>> [!note]\n"
338 "๐€€\n"
339 ">>>\n",
340 (document (1:1-3:3) [
341 (alert (1:1-2:4) [
342 (paragraph (2:1-2:4) [
343 (text (2:1-2:4) "๐€€")
344 ])
345 ])
346 ])
347 );
348
349 assert_ast_match!(
350 [parse.sourcepos_chars, extension.alerts, extension.multiline_block_quotes],
351 ">>> [!note]\n"
352 "๐€€\n"
353 ">>>\n",
354 (document (1:1-3:3) [
355 (alert (1:1-2:1) [
356 (paragraph (2:1-2:1) [
357 (text (2:1-2:1) "๐€€")
358 ])
359 ])
360 ])
361 );
362 }
363
364 #[test]
365 fn sourcepos_chars_cjk_friendly_emphasis() {
366 assert_ast_match!(
367 [extension.cjk_friendly_emphasis],
368 "์Šคํฌ๋ฆฝํŠธ**์•ˆ๋…•**ํ•˜์„ธ์š”",
369 (document (1:1-1:31) [
370 (paragraph (1:1-1:31) [
371 (text (1:1-1:12) "์Šคํฌ๋ฆฝํŠธ")
372 (strong (1:13-1:22) [
373 (text (1:15-1:20) "์•ˆ๋…•")
374 ])
375 (text (1:23-1:31) "ํ•˜์„ธ์š”")
376 ])
377 ])
378 );
379
380 assert_ast_match!(
381 [parse.sourcepos_chars, extension.cjk_friendly_emphasis],
382 "์Šคํฌ๋ฆฝํŠธ**์•ˆ๋…•**ํ•˜์„ธ์š”",
383 (document (1:1-1:13) [
384 (paragraph (1:1-1:13) [
385 (text (1:1-1:4) "์Šคํฌ๋ฆฝํŠธ")
386 (strong (1:5-1:10) [
387 (text (1:7-1:8) "์•ˆ๋…•")
388 ])
389 (text (1:11-1:13) "ํ•˜์„ธ์š”")
390 ])
391 ])
392 );
393 }
394
395 #[test]
396 fn sourcepos_chars_code() {
397 // Inline code
398 assert_ast_match!(
399 [],
400 "`๐€€`",
401 (document (1:1-1:6) [
402 (paragraph (1:1-1:6) [
403 (code (1:1-1:6) "๐€€")
404 ])
405 ])
406 );
407
408 assert_ast_match!(
409 [parse.sourcepos_chars],
410 "`๐€€`",
411 (document (1:1-1:3) [
412 (paragraph (1:1-1:3) [
413 (code (1:1-1:3) "๐€€")
414 ])
415 ])
416 );
417
418 // Code block
419 assert_ast_match!(
420 [],
421 "```\n๐€€\n```\n",
422 (document (1:1-3:3) [
423 (code_block (1:1-3:3) "๐€€\n")
424 ])
425 );
426
427 assert_ast_match!(
428 [parse.sourcepos_chars],
429 "```\n๐€€\n```\n",
430 (document (1:1-3:3) [
431 (code_block (1:1-3:3) "๐€€\n")
432 ])
433 );
434 }
435
436 #[test]
437 fn sourcepos_chars_frontmatter() {
438 assert_ast_match!(
439 [extension.front_matter_delimiter = Some("---".to_owned())],
440 "---\ntitle: ๐€€\n---\n\n# ๐€€\n\n๐€€",
441 (document (1:1-7:4) [
442 (frontmatter (1:1-3:3) "---\ntitle: ๐€€\n---\n\n")
443 (heading (5:1-5:6) [
444 (text (5:3-5:6) "๐€€")
445 ])
446 (paragraph (7:1-7:4) [
447 (text (7:1-7:4) "๐€€")
448 ])
449 ])
450 );
451
452 assert_ast_match!(
453 [parse.sourcepos_chars, extension.front_matter_delimiter = Some("---".to_owned())],
454 "---\ntitle: ๐€€\n---\n\n# ๐€€\n\n๐€€",
455 (document (1:1-7:1) [
456 (frontmatter (1:1-3:3) "---\ntitle: ๐€€\n---\n\n")
457 (heading (5:1-5:3) [
458 (text (5:3-5:3) "๐€€")
459 ])
460 (paragraph (7:1-7:1) [
461 (text (7:1-7:1) "๐€€")
462 ])
463 ])
464 );
465 }
466
467 #[test]
468 fn sourcepos_chars_link() {
469 assert_ast_match!(
470 [],
471 "[๐€€](๐€)",
472 (document (1:1-1:12) [
473 (paragraph (1:1-1:12) [
474 (link (1:1-1:12) "๐€" [
475 (text (1:2-1:5) "๐€€")
476 ])
477 ])
478 ])
479 );
480
481 assert_ast_match!(
482 [parse.sourcepos_chars],
483 "[๐€€](๐€)",
484 (document (1:1-1:6) [
485 (paragraph (1:1-1:6) [
486 (link (1:1-1:6) "๐€" [
487 (text (1:2-1:2) "๐€€")
488 ])
489 ])
490 ])
491 );
492
493 // Link with a title
494 assert_ast_match!(
495 [],
496 "[๐€€](๐€ \"๐€‚\")",
497 (document (1:1-1:19) [
498 (paragraph (1:1-1:19) [
499 (link (1:1-1:19) "๐€" [
500 (text (1:2-1:5) "๐€€")
501 ])
502 ])
503 ])
504 );
505
506 assert_ast_match!(
507 [parse.sourcepos_chars],
508 "[๐€€](๐€ \"๐€‚\")",
509 (document (1:1-1:10) [
510 (paragraph (1:1-1:10) [
511 (link (1:1-1:10) "๐€" [
512 (text (1:2-1:2) "๐€€")
513 ])
514 ])
515 ])
516 );
517 }
518
519 #[test]
520 fn sourcepos_chars_lists() {
521 // Unordered list
522 assert_ast_match!(
523 [],
524 "- ๐€€\n- ๐€\n",
525 (document (1:1-2:6) [
526 (list (1:1-2:6) [
527 (item (1:1-1:6) [
528 (paragraph (1:3-1:6) [
529 (text (1:3-1:6) "๐€€")
530 ])
531 ])
532 (item (2:1-2:6) [
533 (paragraph (2:3-2:6) [
534 (text (2:3-2:6) "๐€")
535 ])
536 ])
537 ])
538 ])
539 );
540
541 assert_ast_match!(
542 [parse.sourcepos_chars],
543 "- ๐€€\n- ๐€\n",
544 (document (1:1-2:3) [
545 (list (1:1-2:3) [
546 (item (1:1-1:3) [
547 (paragraph (1:3-1:3) [
548 (text (1:3-1:3) "๐€€")
549 ])
550 ])
551 (item (2:1-2:3) [
552 (paragraph (2:3-2:3) [
553 (text (2:3-2:3) "๐€")
554 ])
555 ])
556 ])
557 ])
558 );
559
560 // Ordered list
561 assert_ast_match!(
562 [],
563 "1. ๐€€\n2. ๐€\n",
564 (document (1:1-2:7) [
565 (list (1:1-2:7) [
566 (item (1:1-1:7) [
567 (paragraph (1:4-1:7) [
568 (text (1:4-1:7) "๐€€")
569 ])
570 ])
571 (item (2:1-2:7) [
572 (paragraph (2:4-2:7) [
573 (text (2:4-2:7) "๐€")
574 ])
575 ])
576 ])
577 ])
578 );
579
580 assert_ast_match!(
581 [parse.sourcepos_chars],
582 "1. ๐€€\n2. ๐€\n",
583 (document (1:1-2:4) [
584 (list (1:1-2:4) [
585 (item (1:1-1:4) [
586 (paragraph (1:4-1:4) [
587 (text (1:4-1:4) "๐€€")
588 ])
589 ])
590 (item (2:1-2:4) [
591 (paragraph (2:4-2:4) [
592 (text (2:4-2:4) "๐€")
593 ])
594 ])
595 ])
596 ])
597 );
598 }
599
600 #[test]
601 fn sourcepos_chars_softbreak() {
602 // Single-byte characters
603 assert_ast_match!(
604 [],
605 "a\n"
606 "b\n",
607 (document (1:1-2:1) [
608 (paragraph (1:1-2:1) [
609 (text (1:1-1:1) "a")
610 (softbreak (1:2-1:2))
611 (text (2:1-2:1) "b")
612 ])
613 ])
614 );
615
616 assert_ast_match!(
617 [parse.sourcepos_chars],
618 "a\n"
619 "b\n",
620 (document (1:1-2:1) [
621 (paragraph (1:1-2:1) [
622 (text (1:1-1:1) "a")
623 (softbreak (1:2-1:2))
624 (text (2:1-2:1) "b")
625 ])
626 ])
627 );
628
629 // Two-byte characters
630 assert_ast_match!(
631 [],
632 "ษฝ\n"
633 "ษพ\n",
634 (document (1:1-2:2) [
635 (paragraph (1:1-2:2) [
636 (text (1:1-1:2) "ษฝ")
637 (softbreak (1:3-1:3))
638 (text (2:1-2:2) "ษพ")
639 ])
640 ])
641 );
642
643 assert_ast_match!(
644 [parse.sourcepos_chars],
645 "ษฝ\n"
646 "ษพ\n",
647 (document (1:1-2:1) [
648 (paragraph (1:1-2:1) [
649 (text (1:1-1:1) "ษฝ")
650 (softbreak (1:2-1:2))
651 (text (2:1-2:1) "ษพ")
652 ])
653 ])
654 );
655
656 // Three-byte characters
657 assert_ast_match!(
658 [],
659 "ๅฅฝ\n"
660 "ๅฅพ\n",
661 (document (1:1-2:3) [
662 (paragraph (1:1-2:3) [
663 (text (1:1-1:3) "ๅฅฝ")
664 (softbreak (1:4-1:4))
665 (text (2:1-2:3) "ๅฅพ")
666 ])
667 ])
668 );
669
670 assert_ast_match!(
671 [parse.sourcepos_chars],
672 "ๅฅฝ\n"
673 "ๅฅพ\n",
674 (document (1:1-2:1) [
675 (paragraph (1:1-2:1) [
676 (text (1:1-1:1) "ๅฅฝ")
677 (softbreak (1:2-1:2))
678 (text (2:1-2:1) "ๅฅพ")
679 ])
680 ])
681 );
682
683 // Four-byte characters
684 assert_ast_match!(
685 [],
686 "๐€€\n"
687 "๐€\n",
688 (document (1:1-2:4) [
689 (paragraph (1:1-2:4) [
690 (text (1:1-1:4) "๐€€")
691 (softbreak (1:5-1:5))
692 (text (2:1-2:4) "๐€")
693 ])
694 ])
695 );
696
697 assert_ast_match!(
698 [parse.sourcepos_chars],
699 "๐€€\n"
700 "๐€\n",
701 (document (1:1-2:1) [
702 (paragraph (1:1-2:1) [
703 (text (1:1-1:1) "๐€€")
704 (softbreak (1:2-1:2))
705 (text (2:1-2:1) "๐€")
706 ])
707 ])
708 );
709 }
710
711 #[test]
712 fn sourcepos_chars_table() {
713 assert_ast_match!(
714 [extension.table],
715 "| ๐€€ | ๐€ |\n"
716 "| - | - |\n"
717 "| ๐€‚ | ๐€ƒ |\n"
718 ,
719 (document (1:1-3:15) [
720 (table (1:1-3:15) [
721 (table_row (1:1-1:15) [
722 (table_cell (1:2-1:7) [
723 (text (1:3-1:6) "๐€€")
724 ])
725 (table_cell (1:9-1:14) [
726 (text (1:10-1:13) "๐€")
727 ])
728 ])
729 (table_row (3:1-3:15) [
730 (table_cell (3:2-3:7) [
731 (text (3:3-3:6) "๐€‚")
732 ])
733 (table_cell (3:9-3:14) [
734 (text (3:10-3:13) "๐€ƒ")
735 ])
736 ])
737 ])
738 ])
739 );
740
741 assert_ast_match!(
742 [parse.sourcepos_chars, extension.table],
743 "| ๐€€ | ๐€ |\n"
744 "| - | - |\n"
745 "| ๐€‚ | ๐€ƒ |\n"
746 ,
747 (document (1:1-3:9) [
748 (table (1:1-3:9) [
749 (table_row (1:1-1:9) [
750 (table_cell (1:2-1:4) [
751 (text (1:3-1:3) "๐€€")
752 ])
753 (table_cell (1:6-1:8) [
754 (text (1:7-1:7) "๐€")
755 ])
756 ])
757 (table_row (3:1-3:9) [
758 (table_cell (3:2-3:4) [
759 (text (3:3-3:3) "๐€‚")
760 ])
761 (table_cell (3:6-3:8) [
762 (text (3:7-3:7) "๐€ƒ")
763 ])
764 ])
765 ])
766 ])
767 );
768 }
769
770 #[test]
771 fn sourcepos_chars_tasklist() {
772 assert_ast_match!(
773 [extension.tasklist],
774 "- [x] ๐€€\n"
775 " - [ ] ๐€\n"
776 " - [x] ๐€‚\n"
777 "- [ ] ๐€ƒ\n",
778 (document (1:1-4:10) [
779 (list (1:1-4:10) [
780 (taskitem (1:1-3:12) [
781 (paragraph (1:7-1:10) [
782 (text (1:7-1:10) "๐€€")
783 ])
784 (list (2:3-3:12) [
785 (taskitem (2:3-2:12) [
786 (paragraph (2:9-2:12) [
787 (text (2:9-2:12) "๐€")
788 ])
789 ])
790 (taskitem (3:3-3:12) [
791 (paragraph (3:9-3:12) [
792 (text (3:9-3:12) "๐€‚")
793 ])
794 ])
795 ])
796 ])
797 (taskitem (4:1-4:10) [
798 (paragraph (4:7-4:10) [
799 (text (4:7-4:10) "๐€ƒ")
800 ])
801 ])
802 ])
803 ])
804 );
805
806 assert_ast_match!(
807 [parse.sourcepos_chars, extension.tasklist],
808 "- [x] ๐€€\n"
809 " - [ ] ๐€\n"
810 " - [x] ๐€‚\n"
811 "- [ ] ๐€ƒ\n",
812 (document (1:1-4:7) [
813 (list (1:1-4:7) [
814 (taskitem (1:1-3:9) [
815 (paragraph (1:7-1:7) [
816 (text (1:7-1:7) "๐€€")
817 ])
818 (list (2:3-3:9) [
819 (taskitem (2:3-2:9) [
820 (paragraph (2:9-2:9) [
821 (text (2:9-2:9) "๐€")
822 ])
823 ])
824 (taskitem (3:3-3:9) [
825 (paragraph (3:9-3:9) [
826 (text (3:9-3:9) "๐€‚")
827 ])
828 ])
829 ])
830 ])
831 (taskitem (4:1-4:7) [
832 (paragraph (4:7-4:7) [
833 (text (4:7-4:7) "๐€ƒ")
834 ])
835 ])
836 ])
837 ])
838 );
839 }
840
841 #[test]
842 fn sourcepos_chars_thematic_break() {
843 assert_ast_match!(
844 [],
845 "๐€€\n\n"
846 "---\n\n"
847 "๐€\n",
848 (document (1:1-5:4) [
849 (paragraph (1:1-1:4) [
850 (text (1:1-1:4) "๐€€")
851 ])
852 (thematic_break (3:1-3:3))
853 (paragraph (5:1-5:4) [
854 (text (5:1-5:4) "๐€")
855 ])
856 ])
857 );
858
859 assert_ast_match!(
860 [parse.sourcepos_chars],
861 "๐€€\n\n"
862 "---\n\n"
863 "๐€\n",
864 (document (1:1-5:1) [
865 (paragraph (1:1-1:1) [
866 (text (1:1-1:1) "๐€€")
867 ])
868 (thematic_break (3:1-3:3))
869 (paragraph (5:1-5:1) [
870 (text (5:1-5:1) "๐€")
871 ])
872 ])
873 );
874 }