accent-proust 0.11.0

A Rust implementation of the Markdoc language: parse, validate, transform, render, and format.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
//! Upstream's `src/parser.test.ts`, ported.
//!
//! 1,046 lines of TypeScript, and the real specification for this stage: the
//! conformance corpus grades a *renderable* tree, so it says almost nothing
//! about the AST that produces one. These assertions are what fix the AST's
//! shape.
//!
//! # What is ported, and what is not
//!
//! Two of upstream's blocks are deliberately absent, each for a reason that
//! is already written down:
//!
//! - **`handling frontmatter`.** `DIVERGENCES.md` entry 7: frontmatter is the
//!   host's, removed before this crate sees a document. There is no
//!   `document.attributes.frontmatter` to assert.
//! - **The `location` option's line numbers.** Upstream's location is a line
//!   map, so its heading ends on line 1. This crate's is a byte range with the
//!   text borrowed, so the same heading ends where its last byte is. The
//!   assertion is ported to that shape rather than dropped, because what it is
//!   really testing -- that `file` propagates and that `location: false` removes
//!   the field -- is unchanged.
//!
//! Everything else is here, in upstream's order, with upstream's names.

mod support;

use accent_proust::ast::{NodeType, Value};
use accent_proust::parse::{ParseOptions, PulldownTokenizer, parse, parse_with};
use support::{all_error_ids, at, attribute, dedent, error_ids, outline};

/// Upstream's `convert(example, options)`, which every test calls.
fn convert<'s>(source: &'s str, options: &ParseOptions<'s>) -> accent_proust::ast::Node<'s> {
    parse_with(source, &PulldownTokenizer::new(), options)
}

const FENCE: &str = "```";

// ---- handling options ---------------------------------------------------

#[test]
fn no_args() {
    let source = dedent("# This is a test");
    let document = parse(&source);
    let heading = at(&document, &[0]);
    assert_eq!(heading.node_type, NodeType::Heading);
    assert_eq!(heading.location.expect("a location").file, None);
}

#[test]
fn filename_as_property() {
    let source = dedent("# This is a test");
    let document = convert(&source, &ParseOptions::new().file("foo.md"));
    let location = at(&document, &[0]).location.expect("a location");
    assert_eq!(location.file, Some("foo.md"));
}

#[test]
fn location_off() {
    let source = dedent("# This is a test");
    let document = convert(&source, &ParseOptions::new().file("foo.md").location(false));
    assert!(at(&document, &[0]).location.is_none());
}

#[test]
fn location_on() {
    let source = dedent("# This is a test");
    let document = convert(&source, &ParseOptions::new().file("foo.md"));
    let location = at(&document, &[0]).location.expect("a location");
    assert_eq!(location.file, Some("foo.md"));
    assert_eq!(location.start.line, 0);
    assert_eq!(location.text, "# This is a test");
    // Upstream asserts `end: {line: 1}` because its location is a half-open line
    // map. Here the same fact lives in `lines`, and `location.end` is where the
    // heading's last byte is.
    assert_eq!(at(&document, &[0]).lines, vec![0, 1]);
}

// ---- handling attributes ------------------------------------------------

#[test]
fn attributes_for_emphasis() {
    let markers = |example: &str, index: usize| {
        let source = dedent(example);
        let document = parse(&source);
        attribute(at(&document, &[0, 0, index]), "marker")
    };
    assert_eq!(markers("a*b*c", 1), "\"*\"");
    assert_eq!(markers("a**b**c", 1), "\"**\"");
    assert_eq!(markers("_foo_ bar", 0), "\"_\"");
    assert_eq!(markers("__foo__ bar", 0), "\"__\"");
    assert_eq!(markers("foo *bar* baz", 1), "\"*\"");
    assert_eq!(markers("foo **bar** baz", 1), "\"**\"");
}

#[test]
fn attributes_for_heading() {
    let source = dedent("# Sample Heading");
    let document = parse(&source);
    assert_eq!(attribute(at(&document, &[0]), "level"), "1");
}

#[test]
fn attributes_for_list() {
    let unordered = dedent("\n* Example 1\n* Example 2\n* Example 3\n");
    let ordered = dedent("\n1. Example 1\n2. Example 2\n3. Example 3\n");
    let unordered = parse(&unordered);
    let ordered = parse(&ordered);
    assert_eq!(attribute(at(&unordered, &[0]), "ordered"), "false");
    assert_eq!(attribute(at(&ordered, &[0]), "ordered"), "true");
}

#[test]
fn attributes_for_ordered_list_start() {
    let start = |example: &str| {
        let source = dedent(example);
        let document = parse(&source);
        attribute(at(&document, &[0]), "start")
    };
    assert_eq!(start("\n* Example 1\n* Example 2\n"), "<unset>");
    assert_eq!(start("\n3. Example 1\n4. Example 2\n"), "3");
    // markdown-it omits `start` for a list beginning at 1, whatever follows.
    assert_eq!(start("\n1. Example 1\n4. Example 2\n"), "<unset>");
}

#[test]
fn attributes_for_link() {
    let source = dedent("\n[foo](/bar)\n");
    let document = parse(&source);
    let link = at(&document, &[0, 0, 0]);
    assert_eq!(link.node_type, NodeType::Link);
    assert_eq!(attribute(link, "href"), "\"/bar\"");
    assert_eq!(attribute(link, "title"), "<unset>");
}

#[test]
fn attributes_for_link_with_a_title() {
    let source = dedent("\n[foo](/bar \"title\")\n");
    let document = parse(&source);
    let link = at(&document, &[0, 0, 0]);
    assert_eq!(attribute(link, "href"), "\"/bar\"");
    assert_eq!(attribute(link, "title"), "\"title\"");
}

#[test]
fn attributes_for_text() {
    let source = dedent("\nThis is a test\n");
    let document = parse(&source);
    assert_eq!(
        attribute(at(&document, &[0, 0, 0]), "content"),
        "\"This is a test\""
    );
}

#[test]
fn attributes_for_code_fence() {
    let simple = dedent(&format!("\n{FENCE}ruby\nThis is a test\n{FENCE}\n"));
    let complex = dedent(&format!(
        "\n{FENCE}ruby this is a test\nThis is a test\n{FENCE}\n"
    ));
    let empty = dedent(&format!("\n{FENCE}\nThis is a test\n{FENCE}\n"));

    let fence = |source: &str| {
        let document = parse(source);
        let node = at(&document, &[0]);
        (
            attribute(node, "language"),
            attribute(node, "content"),
            node.node_type,
        )
    };
    assert_eq!(
        fence(&simple),
        (
            "\"ruby\"".to_string(),
            "\"This is a test\\n\"".to_string(),
            NodeType::Fence
        )
    );
    assert_eq!(
        fence(&complex),
        (
            "\"ruby\"".to_string(),
            "\"This is a test\\n\"".to_string(),
            NodeType::Fence
        )
    );
    assert_eq!(
        fence(&empty),
        (
            "<unset>".to_string(),
            "\"This is a test\\n\"".to_string(),
            NodeType::Fence
        )
    );
}

#[test]
fn attributes_for_image_with_no_title() {
    let source = dedent("![foo](/url)");
    let document = parse(&source);
    let image = at(&document, &[0, 0, 0]);
    assert_eq!(image.node_type, NodeType::Image);
    assert_eq!(attribute(image, "title"), "<unset>");
    assert_eq!(attribute(image, "src"), "\"/url\"");
    assert_eq!(attribute(image, "alt"), "\"foo\"");
}

#[test]
fn attributes_for_image_with_a_title() {
    let source = dedent("![foo](/url \"title\")");
    let document = parse(&source);
    let image = at(&document, &[0, 0, 0]);
    assert_eq!(attribute(image, "title"), "\"title\"");
    assert_eq!(attribute(image, "src"), "\"/url\"");
    assert_eq!(attribute(image, "alt"), "\"foo\"");
}

#[test]
fn attributes_for_table_with_alignments() {
    let source = dedent(
        "\n| Left | Center | Right |\n| :--- | :----: | ----: |\n| Left | Center | Right |\n",
    );
    let document = parse(&source);
    let table = at(&document, &[0]);
    let head_row = at(table, &[0, 0]);
    let body_row = at(table, &[1, 0]);
    for row in [head_row, body_row] {
        assert_eq!(attribute(at(row, &[0]), "align"), "\"left\"");
        assert_eq!(attribute(at(row, &[1]), "align"), "\"center\"");
        assert_eq!(attribute(at(row, &[2]), "align"), "\"right\"");
    }
}

// ---- structure ----------------------------------------------------------

#[test]
fn handling_a_header() {
    let source = dedent("\n# Sample Heading\n\nThis is a sample paragraph\n");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  heading level=1
    inline
      text content=\"Sample Heading\"
  paragraph
    inline
      text content=\"This is a sample paragraph\"
"
    );
}

#[test]
fn handling_an_image() {
    let source = dedent("![Alt](/logo.png)");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  paragraph
    inline
      image alt=\"Alt\" src=\"/logo.png\"
"
    );
}

#[test]
fn handling_lists_with_bullets() {
    let source = dedent("\n* foo\n* bar\n");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  list ordered=false marker=\"*\"
    item
      inline
        text content=\"foo\"
    item
      inline
        text content=\"bar\"
"
    );
}

#[test]
fn handling_lists_with_numbers() {
    let source = dedent("\n1. foo\n2. bar\n");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  list ordered=true marker=\".\"
    item
      inline
        text content=\"foo\"
    item
      inline
        text content=\"bar\"
"
    );
}

#[test]
fn handling_fenced_code_with_a_language() {
    let source = dedent(&format!("\n{FENCE}ruby\nputs \"foo\"\n{FENCE}\n"));
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  fence content=\"puts \\\"foo\\\"\\n\" language=\"ruby\"
"
    );
}

#[test]
fn handling_fenced_code_with_an_annotation() {
    let source = dedent(&format!("\n{FENCE}ruby {{% #foo .bar %}}\ntest\n{FENCE}\n"));
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  fence content=\"test\\n\" language=\"ruby\" id=\"foo\" class={bar: true}
"
    );
}

// ---- tags ---------------------------------------------------------------

#[test]
fn tags_at_block_level_with_a_class() {
    let source =
        dedent("\n{% callout .foo .bar %}\n### Heading\n\nThis is a paragraph\n{% /callout %}\n");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  tag[callout] class={foo: true, bar: true}
    heading level=3
      inline
        text content=\"Heading\"
    paragraph
      inline
        text content=\"This is a paragraph\"
"
    );
}

#[test]
fn tags_at_block_level_with_nesting() {
    let source =
        dedent("\n{% callout %}\n{% callout %}\nThis is a test\n{% /callout %}\n{% /callout %}\n");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  tag[callout]
    tag[callout]
      paragraph
        inline
          text content=\"This is a test\"
"
    );
}

// ---- annotations --------------------------------------------------------

#[test]
fn annotations_in_a_header_with_an_id() {
    let source = dedent("# Sample Heading {% #foo-bar %}");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  heading level=1 id=\"foo-bar\"
    inline
      text content=\"Sample Heading \"
"
    );
}

#[test]
fn annotations_in_a_header_with_a_class() {
    let source = dedent("# Sample Heading {% .foo-bar .test %}");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  heading level=1 class={foo-bar: true, test: true}
    inline
      text content=\"Sample Heading \"
"
    );
}

#[test]
fn annotations_in_a_header_with_complex_values() {
    let source = dedent("# Sample Heading {% #asdf .foo-bar .test foo=\"bar\" %}");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  heading level=1 id=\"asdf\" class={foo-bar: true, test: true} foo=\"bar\"
    inline
      text content=\"Sample Heading \"
"
    );
}

// ---- variables ----------------------------------------------------------

#[test]
fn variables_by_itself_on_a_line() {
    let source = dedent("{% $test %}");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  paragraph
    inline
      text content=$test
"
    );
}

#[test]
fn variables_in_an_inline_text_node() {
    let source = dedent("This is a test: {% $test %}");
    assert_eq!(
        outline(&parse(&source)),
        "\
document
  paragraph
    inline
      text content=\"This is a test: \"
      text content=$test
"
    );
}

/// Ported together with upstream's `ast/variable.test.ts`, which asserts the
/// same path shape by constructing a `Variable` directly.
///
/// Its third case, resolution against a config, is not ported here: `resolve`
/// reads a `Config`, which belongs to the transform stage, and Goal A left it
/// out of the value lattice for that reason.
#[test]
fn variables_with_nested_property_access() {
    let source = dedent("{% $bar.baz[1].test %}");
    let document = parse(&source);
    let text = at(&document, &[0, 0, 0]);
    let Some(Value::Variable(variable)) = text.get("content") else {
        panic!("expected a variable, got {:?}", text.get("content"));
    };
    assert_eq!(variable.path.len(), 4);
    assert_eq!(attribute(text, "content"), "$bar.baz[1].test");
}

#[test]
fn a_variable_with_a_string_index() {
    let source = dedent("{% $foo[\"this is a test\"] %}");
    let document = parse(&source);
    assert_eq!(
        attribute(at(&document, &[0, 0, 0]), "content"),
        "$foo.this is a test"
    );
}

// ---- robustness ---------------------------------------------------------

#[test]
fn parsing_nested_tags_with_indentation_should_not_throw() {
    // Upstream writes this one without its `convert` dedent, because the
    // indentation is the point.
    let document =
        parse("{% tag1 %}\n      {% tag2 %}\n          Contents\n      {% /tag2 %}\n{% /tag1 %}\n");
    assert_eq!(document.node_type, NodeType::Document);
}

#[test]
fn parsing_comments() {
    let source = dedent("\nthis is a test\n\n<!-- foo -->\n");
    let document = convert(&source, &ParseOptions::new().allow_comments(true));
    assert_eq!(
        outline(&document),
        "\
document
  paragraph
    inline
      text content=\"this is a test\"
  comment content=\"foo\"
"
    );
}

// ---- attribute errors ---------------------------------------------------

#[test]
fn error_for_duplicate_attributes() {
    let source = dedent("{% foo bar=1 bar=2 bar=3 bar=4 /%}");
    let document = parse(&source);
    assert_eq!(
        error_ids(at(&document, &[0])),
        [
            "duplicate-attribute",
            "duplicate-attribute",
            "duplicate-attribute"
        ]
    );
}

#[test]
fn error_for_duplicate_ids() {
    let source = dedent("{% foo #bar #baz #qux /%}");
    let document = parse(&source);
    assert_eq!(
        error_ids(at(&document, &[0])),
        ["duplicate-attribute", "duplicate-attribute"]
    );
}

#[test]
fn error_with_annotation_values() {
    let source = dedent("testing {% foo=1 foo=2 %}");
    let document = parse(&source);
    let paragraph = at(&document, &[0]);
    assert_eq!(paragraph.node_type, NodeType::Paragraph);
    assert_eq!(error_ids(paragraph), ["duplicate-attribute"]);
}

#[test]
fn error_across_annotations_on_the_same_node() {
    let source = dedent("testing {% foo=1 %} another test {% foo=1 %}");
    let document = parse(&source);
    assert_eq!(error_ids(at(&document, &[0])), ["duplicate-attribute"]);
}

#[test]
fn no_error_for_multiple_classes() {
    let source = dedent("{% foo .bar .baz .qux /%}");
    let document = parse(&source);
    assert!(error_ids(at(&document, &[0])).is_empty());
}

/// Upstream writes this fence without an annotation, because its fences process
/// tags by default. `DIVERGENCES.md` entry 1 inverts that, so the port opts in
/// -- which is the same test of the same rule, with the opt-in made explicit.
#[test]
fn displays_error_for_annotations_in_a_fence() {
    let source = dedent("\n~~~ {% process=true %}\ntest\n{% #foo %}\ntest\n~~~\n");
    let document = parse(&source);
    let fence = at(&document, &[0]);
    assert_eq!(fence.node_type, NodeType::Fence);
    assert!(fence.annotations.len() == 1, "only `process` is annotated");
    assert_eq!(error_ids(fence), ["no-inline-annotations"]);
}

// ---- inline identification ----------------------------------------------

#[test]
fn correctly_identifies_inlines() {
    let source = dedent(
        "\n# This is a test\n\n{% foo %}\nAnother {% bar %}test{% /bar %} test\n{% /foo %}\n\n* bar\n",
    );
    let document = parse(&source);

    let flags: Vec<(String, bool)> = std::iter::once(&document)
        .chain(document.walk())
        .map(|node| (node.name().to_string(), node.inline))
        .collect();

    assert_eq!(
        flags,
        [
            ("document".to_string(), false),
            ("heading".to_string(), false),
            ("inline".to_string(), false),
            ("text".to_string(), true),
            ("foo".to_string(), false),
            ("paragraph".to_string(), false),
            ("inline".to_string(), false),
            ("text".to_string(), true),
            ("bar".to_string(), true),
            ("text".to_string(), true),
            ("text".to_string(), true),
            ("list".to_string(), false),
            ("item".to_string(), false),
            ("inline".to_string(), false),
            ("text".to_string(), true),
        ]
    );
}

// ---- structural errors --------------------------------------------------

#[test]
fn with_unmatched_closing_tag() {
    let source = dedent("\n{% foo %}\nTest\n{% /bar %}\n");
    let document = parse(&source);
    assert_eq!(error_ids(at(&document, &[0]))[0], "missing-closing");
}

#[test]
fn missing_opening() {
    let source = dedent("\nThis a test\n{% /foo %}\n");
    let document = parse(&source);
    assert_eq!(error_ids(at(&document, &[1]))[0], "missing-opening");
}

#[test]
fn with_missing_closing_tag() {
    let source = dedent("\n{% foo %}\nTest\n");
    let document = parse(&source);
    assert_eq!(error_ids(at(&document, &[0]))[0], "missing-closing");
}

#[test]
fn a_tag_that_does_not_parse_becomes_an_error_node() {
    let source = dedent("{% test foo={,} /%}");
    let document = parse(&source);
    let node = at(&document, &[0]);
    assert_eq!(node.node_type, NodeType::Error);
    assert_eq!(error_ids(node), ["parse-error"]);
    assert_eq!(
        node.errors[0].message,
        "Expected \"}\", identifier, string, or whitespace but \",\" found."
    );
    // The grammar reports offsets into the tag body; the parser translates them
    // into the document, which is what makes an editor able to underline it.
    let location = node.errors[0].location.expect("a location");
    assert_eq!(
        location.start.offset, 13,
        "the offset of the `,` in the document"
    );
    assert_eq!(location.text, ",");
}

#[test]
fn an_unclosed_tag_is_ordinary_text() {
    let source = dedent("hello {% world");
    let document = parse(&source);
    assert!(all_error_ids(&document).is_empty());
    assert_eq!(
        attribute(at(&document, &[0, 0, 0]), "content"),
        "\"hello {% world\""
    );
}

// Upstream's `table parsing` block. It asserts which tags survive the table
// rewrite that runs at the end of the parse, so it belongs here rather than
// with the rewrite's own suite: what it is really testing is that
// `conditionalTags` reaches the pass from the parser's arguments.

/// Upstream's `setupTableDoc`.
fn table_document(rows: &[&str]) -> String {
    dedent(&format!(
        "{{% table %}}\n- column 1\n- column 2\n---\n{}\n{{% /table %}}\n",
        rows.join("\n")
    ))
}

/// Every tag name in a document, in walk order.
fn tag_names(document: &accent_proust::ast::Node<'_>) -> Vec<String> {
    document
        .walk()
        .filter(|node| node.node_type == NodeType::Tag)
        .filter_map(|node| node.tag.clone())
        .collect()
}

#[test]
fn should_preserve_default_if_tag_during_table_parsing_without_extra_parser_args() {
    let source = table_document(&[
        "{% if $fakeCondition.condition1 %}\n- cell 1\n- cell 2\n{% else /%}\n- cell 3\n- cell 4\n{% /if %}",
    ]);
    let names = tag_names(&parse(&source));
    assert!(names.contains(&"if".to_string()), "{names:?}");
}

#[test]
fn should_not_preserve_unregistered_tags_during_table_parsing_without_extra_parser_args() {
    let source = table_document(&[
        "{% if-pref conditions=[{platform: \"web\"}] %}\n- cell 1\n- cell 2\n{% /if-pref %}\n\
         {% if-pref conditions=[{platform: \"ios\"}] %}\n- cell 1\n- cell 2\n{% /if-pref %}",
    ]);
    let names = tag_names(&parse(&source));
    assert!(!names.contains(&"if-pref".to_string()), "{names:?}");
}

#[test]
fn should_preserve_registered_tags_and_ignore_unregistered_ones_with_extra_parser_args() {
    let source = table_document(&[
        "{% if-pref conditions=[{platform: \"web\"}] %}\n- cell 1\n- cell 2\n{% /if-pref %}\n\
         {% if-pref conditions=[{platform: \"ios\"}] %}\n- cell 1\n- cell 2\n{% /if-pref %}",
        "{% if $fakeCondition.condition1 %}\n- cell 1\n- cell 2\n{% else /%}\n- cell 3\n- cell 4\n{% /if %}",
        "{% unregistered-if-tag $fakeCondition.condition2 %}\n- cell 1\n- cell 2\n{% /unregistered-if-tag %}",
    ]);
    let options =
        ParseOptions::new().conditional_tags(vec!["if".to_string(), "if-pref".to_string()]);
    let names = tag_names(&convert(&source, &options));
    assert!(names.contains(&"if".to_string()), "{names:?}");
    assert!(names.contains(&"if-pref".to_string()), "{names:?}");
    assert!(
        !names.contains(&"unregistered-if-tag".to_string()),
        "{names:?}"
    );
}