aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mdx_jsx_flow.rs
blob: ff53dcbc3b557c78471b58064767370ef3831d3a (plain) (blame)
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
extern crate micromark;
use micromark::{micromark_with_options, Constructs, Options};
use pretty_assertions::assert_eq;

#[test]
fn mdx_jsx_flow_agnostic() -> Result<(), String> {
    let mdx = Options {
        constructs: Constructs::mdx(),
        ..Options::default()
    };

    assert_eq!(
        micromark_with_options("<a />", &mdx)?,
        "",
        "should support a self-closing element"
    );

    assert_eq!(
        micromark_with_options("<a></a>", &mdx)?,
        "",
        "should support a closed element"
    );

    assert_eq!(
        micromark_with_options("<a>\nb\n</a>", &mdx)?,
        "<p>b</p>\n",
        "should support an element w/ content"
    );

    assert_eq!(
        micromark_with_options("<a>\n- b\n</a>", &mdx)?,
        "<ul>\n<li>b</li>\n</ul>\n",
        "should support an element w/ containers as content"
    );

    // To do: expressions.
    // assert_eq!(
    //     micromark_with_options("<a b c:d e=\"\" f={/* g */} {...h} />", &mdx)?,
    //     "",
    //     "should support attributes"
    // );

    Ok(())
}

// Flow is mostly the same as `text`, so we only test the relevant
// differences.
#[test]
fn mdx_jsx_flow_essence() -> Result<(), String> {
    let mdx = Options {
        constructs: Constructs::mdx(),
        ..Options::default()
    };

    assert_eq!(
        micromark_with_options("<a />", &mdx)?,
        "",
        "should support an element"
    );

    assert_eq!(
        micromark_with_options("<a>\n- b\n</a>", &mdx)?,
        "<ul>\n<li>b</li>\n</ul>\n",
        "should support an element around a container"
    );

    assert_eq!(
        micromark_with_options("<x\n  y\n>  \nb\n  </x>", &mdx)?,
        "<p>b</p>\n",
        "should support a dangling `>` in a tag (not a block quote)"
    );

    assert_eq!(
        micromark_with_options("<a>  \nb\n  </a>", &mdx)?,
        "<p>b</p>\n",
        "should support trailing initial and final whitespace around tags"
    );

    assert_eq!(
        micromark_with_options("<a> <b>\t\nc\n  </b> </a>", &mdx)?,
        "<p>c</p>\n",
        "should support tags after tags"
    );

    assert_eq!(
        micromark_with_options("> <X\n/>", &mdx).err().unwrap(),
        "2:1: Unexpected lazy line in jsx in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
        "should not support lazy flow (1)"
    );

    assert_eq!(
        micromark_with_options("> a\n> <X\n/>", &mdx)
            .err()
            .unwrap(),
        "3:1: Unexpected lazy line in jsx in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
        "should not support lazy flow (2)"
    );

    assert_eq!(
        micromark_with_options("> <a b='\nc'/> d", &mdx)
            .err()
            .unwrap(),
        "2:1: Unexpected lazy line in jsx in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
        "should not support lazy flow (3)"
    );

    assert_eq!(
        micromark_with_options("> <a b='c\n'/> d", &mdx)
            .err()
            .unwrap(),
        "2:1: Unexpected lazy line in jsx in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
        "should not support lazy flow (4)"
    );

    assert_eq!(
        micromark_with_options("> <a b='c\nd'/> e", &mdx)
            .err()
            .unwrap(),
        "2:1: Unexpected lazy line in jsx in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
        "should not support lazy flow (4)"
    );

    assert_eq!(
        micromark_with_options("> a\n<X />", &mdx)?,
        "<blockquote>\n<p>a</p>\n</blockquote>\n",
        "should not support lazy flow (5)"
    );

    Ok(())
}