about summary refs log tree commit diff
path: root/tools/cheddar/src/tests.rs
blob: 8b8219b22d7cf7f4cb3299c87ea82b5872c74f5f (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
use super::*;
use std::io::BufReader;

// Markdown rendering expectation, ignoring leading and trailing
// whitespace in the input and output.
fn expect_markdown(input: &str, expected: &str) {
    let mut input_buf = BufReader::new(input.trim().as_bytes());
    let mut out_buf: Vec<u8> = vec![];
    format_markdown(&mut input_buf, &mut out_buf);

    let out_string = String::from_utf8(out_buf).expect("output should be UTF8");
    assert_eq!(out_string.trim(), expected.trim());
}

#[test]
fn renders_simple_markdown() {
    expect_markdown("hello", "<p>hello</p>\n");
}

#[test]
fn renders_callouts() {
    expect_markdown(
        "TODO some task.",
        r#"<p class="cheddar-callout cheddar-todo">
TODO some task.
</p>
"#,
    );

    expect_markdown(
        "WARNING: be careful",
        r#"<p class="cheddar-callout cheddar-warning">
WARNING: be careful
</p>
"#,
    );

    expect_markdown(
        "TIP: note the thing",
        r#"<p class="cheddar-callout cheddar-tip">
TIP: note the thing
</p>
"#,
    );
}

#[test]
fn renders_code_snippets() {
    expect_markdown(
        r#"
Code:
```nix
toString 42
```
"#,
        r#"
<p>Code:</p>
<pre style="background-color:#f6f8fa;padding:16px;">
<span style="color:#62a35c;">toString </span><span style="color:#0086b3;">42
</span></pre>
"#,
    );
}