aboutsummaryrefslogtreecommitdiffstats
path: root/tests/misc_default_line_ending.rs
blob: 10a82939d82dd39046420d27e9467e81a92d49d6 (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 markdown::{to_html, to_html_with_options, CompileOptions, LineEnding, Options};
use pretty_assertions::assert_eq;

#[test]
fn default_line_ending() -> Result<(), String> {
    assert_eq!(
        to_html("> a"),
        "<blockquote>\n<p>a</p>\n</blockquote>",
        "should use `\\n` default"
    );

    assert_eq!(
        to_html("> a\n"),
        "<blockquote>\n<p>a</p>\n</blockquote>\n",
        "should infer the first line ending (1)"
    );

    assert_eq!(
        to_html("> a\r"),
        "<blockquote>\r<p>a</p>\r</blockquote>\r",
        "should infer the first line ending (2)"
    );

    assert_eq!(
        to_html("> a\r\n"),
        "<blockquote>\r\n<p>a</p>\r\n</blockquote>\r\n",
        "should infer the first line ending (3)"
    );

    assert_eq!(
        to_html_with_options(
            "> a",
            &Options {
                compile: CompileOptions {
                    default_line_ending: LineEnding::CarriageReturn,
                    ..Default::default()
                },
                ..Default::default()
            }
        )?,
        "<blockquote>\r<p>a</p>\r</blockquote>",
        "should support the given line ending"
    );

    assert_eq!(
        to_html_with_options(
            "> a\n",
            &Options {
                compile: CompileOptions {
                    default_line_ending: LineEnding::CarriageReturn,
                    ..Default::default()
                },
                ..Default::default()
            }
        )?,
        // To do: is this a bug in `to_html.js` that it uses `\r` for earlier line endings?
        // "<blockquote>\r<p>a</p>\r</blockquote>\n",
        "<blockquote>\n<p>a</p>\n</blockquote>\n",
        "should support the given line ending, even if line endings exist"
    );

    Ok(())
}