summary refs log tree commit diff
path: root/src/librustdoc/html/highlight/tests.rs
blob: a505865b149c4bc91e0ee1e4480686c38df96502 (plain)
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
use super::write_code;
use crate::html::format::Buffer;
use expect_test::expect_file;
use rustc_span::create_default_session_globals_then;
use rustc_span::edition::Edition;

const STYLE: &str = r#"
<style>
.kw { color: #8959A8; }
.kw-2, .prelude-ty { color: #4271AE; }
.number, .string { color: #718C00; }
.self, .bool-val, .prelude-val, .attribute, .attribute .ident { color: #C82829; }
.macro, .macro-nonterminal { color: #3E999F; }
.lifetime { color: #B76514; }
.question-mark { color: #ff9011; }
</style>
"#;

#[test]
fn test_html_highlighting() {
    create_default_session_globals_then(|| {
        let src = include_str!("fixtures/sample.rs");
        let html = {
            let mut out = Buffer::new();
            write_code(&mut out, src, Edition::Edition2018);
            format!("{}<pre><code>{}</code></pre>\n", STYLE, out.into_inner())
        };
        expect_file!["fixtures/sample.html"].assert_eq(&html);
    });
}

#[test]
fn test_dos_backline() {
    create_default_session_globals_then(|| {
        let src = "pub fn foo() {\r\n\
    println!(\"foo\");\r\n\
}\r\n";
        let mut html = Buffer::new();
        write_code(&mut html, src, Edition::Edition2018);
        expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner());
    });
}