]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/highlight/tests.rs
Auto merge of #85971 - FabianWolff:issue-85586, r=davidtwco
[rust.git] / src / librustdoc / html / highlight / tests.rs
1 use super::write_code;
2 use crate::html::format::Buffer;
3 use expect_test::expect_file;
4 use rustc_span::create_default_session_globals_then;
5 use rustc_span::edition::Edition;
6
7 const STYLE: &str = r#"
8 <style>
9 .kw { color: #8959A8; }
10 .kw-2, .prelude-ty { color: #4271AE; }
11 .number, .string { color: #718C00; }
12 .self, .bool-val, .prelude-val, .attribute, .attribute .ident { color: #C82829; }
13 .macro, .macro-nonterminal { color: #3E999F; }
14 .lifetime { color: #B76514; }
15 .question-mark { color: #ff9011; }
16 </style>
17 "#;
18
19 #[test]
20 fn test_html_highlighting() {
21     create_default_session_globals_then(|| {
22         let src = include_str!("fixtures/sample.rs");
23         let html = {
24             let mut out = Buffer::new();
25             write_code(&mut out, src, Edition::Edition2018);
26             format!("{}<pre><code>{}</code></pre>\n", STYLE, out.into_inner())
27         };
28         expect_file!["fixtures/sample.html"].assert_eq(&html);
29     });
30 }
31
32 #[test]
33 fn test_dos_backline() {
34     create_default_session_globals_then(|| {
35         let src = "pub fn foo() {\r\n\
36     println!(\"foo\");\r\n\
37 }\r\n";
38         let mut html = Buffer::new();
39         write_code(&mut html, src, Edition::Edition2018);
40         expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner());
41     });
42 }