aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mdx_swc.rs
blob: c9a2a61d8940bd6500667051492a92768c585ceb (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
extern crate micromark;
mod test_utils;
use micromark::{micromark_with_options, Constructs, Options};
use pretty_assertions::assert_eq;
use test_utils::{parse_esm, parse_expression};

#[test]
fn mdx_swc() -> Result<(), String> {
    let mdx = Options {
        constructs: Constructs::mdx(),
        mdx_esm_parse: Some(Box::new(parse_esm)),
        mdx_expression_parse: Some(Box::new(parse_expression)),
        ..Options::default()
    };

    assert_eq!(
        micromark_with_options("{'}'}", &mdx)?,
        "",
        "should support JavaScript-aware flow expressions w/ `mdx_expression_parse`"
    );

    assert_eq!(
        micromark_with_options("a {'}'} b", &mdx)?,
        "<p>a  b</p>",
        "should support JavaScript-aware text expressions w/ `mdx_expression_parse`"
    );

    assert_eq!(
        micromark_with_options("<a {...a/*}*/} />", &mdx)?,
        "",
        "should support JavaScript-aware attribute expressions w/ `mdx_expression_parse`"
    );

    assert_eq!(
        micromark_with_options("<a b={'}'} />", &mdx)?,
        "",
        "should support JavaScript-aware attribute value expressions w/ `mdx_expression_parse`"
    );

    assert_eq!(
        micromark_with_options("import a from 'b'\n\nexport {a}\n\n# c", &mdx)?,
        "<h1>c</h1>",
        "should support JavaScript-aware ESM w/ `mdx_esm_parse`"
    );

    Ok(())
}