1 use super::{write_code, DecorationInfo};
2 use crate::html::format::Buffer;
3 use expect_test::expect_file;
4 use rustc_data_structures::fx::FxHashMap;
5 use rustc_span::create_default_session_globals_then;
6 use rustc_span::edition::Edition;
8 const STYLE: &str = r#"
10 .kw { color: #8959A8; }
11 .kw-2, .prelude-ty { color: #4271AE; }
12 .number, .string { color: #718C00; }
13 .self, .bool-val, .prelude-val, .attribute, .attribute .ident { color: #C82829; }
14 .macro, .macro-nonterminal { color: #3E999F; }
15 .lifetime { color: #B76514; }
16 .question-mark { color: #ff9011; }
21 fn test_html_highlighting() {
22 create_default_session_globals_then(|| {
23 let src = include_str!("fixtures/sample.rs");
25 let mut out = Buffer::new();
26 write_code(&mut out, src, Edition::Edition2018, None, None);
27 format!("{}<pre><code>{}</code></pre>\n", STYLE, out.into_inner())
29 expect_file!["fixtures/sample.html"].assert_eq(&html);
34 fn test_dos_backline() {
35 create_default_session_globals_then(|| {
36 let src = "pub fn foo() {\r\n\
37 println!(\"foo\");\r\n\
39 let mut html = Buffer::new();
40 write_code(&mut html, src, Edition::Edition2018, None, None);
41 expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner());
46 fn test_keyword_highlight() {
47 create_default_session_globals_then(|| {
48 let src = "use crate::a::foo;
50 let x = super::b::foo;
51 let y = Self::whatever;";
53 let mut html = Buffer::new();
54 write_code(&mut html, src, Edition::Edition2018, None, None);
55 expect_file!["fixtures/highlight.html"].assert_eq(&html.into_inner());
60 fn test_union_highlighting() {
61 create_default_session_globals_then(|| {
62 let src = include_str!("fixtures/union.rs");
63 let mut html = Buffer::new();
64 write_code(&mut html, src, Edition::Edition2018, None, None);
65 expect_file!["fixtures/union.html"].assert_eq(&html.into_inner());
70 fn test_decorations() {
71 create_default_session_globals_then(|| {
74 let mut decorations = FxHashMap::default();
75 decorations.insert("example", vec![(0, 10)]);
77 let mut html = Buffer::new();
78 write_code(&mut html, src, Edition::Edition2018, None, Some(DecorationInfo(decorations)));
79 expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner());