|
1 | 1 | use super::write_code;
|
2 |
| - |
3 |
| -fn highlight(src: &str) -> String { |
4 |
| - let mut out = String::new(); |
5 |
| - write_code(&mut out, src); |
6 |
| - out |
7 |
| -} |
8 |
| - |
9 |
| -#[test] |
10 |
| -fn function() { |
11 |
| - assert_eq!( |
12 |
| - highlight("fn main() {}"), |
13 |
| - r#"<span class="kw">fn</span> <span class="ident">main</span>() {}"#, |
14 |
| - ); |
15 |
| -} |
16 |
| - |
17 |
| -#[test] |
18 |
| -fn statement() { |
19 |
| - assert_eq!( |
20 |
| - highlight("let foo = true;"), |
21 |
| - concat!( |
22 |
| - r#"<span class="kw">let</span> <span class="ident">foo</span> "#, |
23 |
| - r#"<span class="op">=</span> <span class="bool-val">true</span>;"#, |
24 |
| - ), |
25 |
| - ); |
26 |
| -} |
| 2 | +use expect_test::expect_file; |
27 | 3 |
|
28 | 4 | #[test]
|
29 |
| -fn inner_attr() { |
30 |
| - assert_eq!( |
31 |
| - highlight(r##"#![crate_type = "lib"]"##), |
32 |
| - concat!( |
33 |
| - r##"<span class="attribute">#![<span class="ident">crate_type</span> "##, |
34 |
| - r##"<span class="op">=</span> <span class="string">"lib"</span>]</span>"##, |
35 |
| - ), |
36 |
| - ); |
| 5 | +fn test_html_highlighting() { |
| 6 | + let src = include_str!("fixtures/sample.rs"); |
| 7 | + let html = { |
| 8 | + let mut out = String::new(); |
| 9 | + write_code(&mut out, src); |
| 10 | + format!("{}<pre><code>{}</code></pre>\n", STYLE, out) |
| 11 | + }; |
| 12 | + expect_file!["src/librustdoc/html/highlight/fixtures/sample.html"].assert_eq(&html); |
37 | 13 | }
|
38 | 14 |
|
39 |
| -#[test] |
40 |
| -fn outer_attr() { |
41 |
| - assert_eq!( |
42 |
| - highlight(r##"#[cfg(target_os = "linux")]"##), |
43 |
| - concat!( |
44 |
| - r##"<span class="attribute">#[<span class="ident">cfg</span>("##, |
45 |
| - r##"<span class="ident">target_os</span> <span class="op">=</span> "##, |
46 |
| - r##"<span class="string">"linux"</span>)]</span>"##, |
47 |
| - ), |
48 |
| - ); |
49 |
| -} |
50 |
| - |
51 |
| -#[test] |
52 |
| -fn mac() { |
53 |
| - assert_eq!( |
54 |
| - highlight("mac!(foo bar)"), |
55 |
| - concat!( |
56 |
| - r#"<span class="macro">mac</span><span class="macro">!</span>("#, |
57 |
| - r#"<span class="ident">foo</span> <span class="ident">bar</span>)"#, |
58 |
| - ), |
59 |
| - ); |
60 |
| -} |
61 |
| - |
62 |
| -// Regression test for #72684 |
63 |
| -#[test] |
64 |
| -fn andand() { |
65 |
| - assert_eq!(highlight("&&"), r#"<span class="op">&&</span>"#); |
66 |
| -} |
| 15 | +const STYLE: &str = r#" |
| 16 | +<style> |
| 17 | +.kw { color: #8959A8; } |
| 18 | +.kw-2, .prelude-ty { color: #4271AE; } |
| 19 | +.number, .string { color: #718C00; } |
| 20 | +.self, .bool-val, .prelude-val, .attribute, .attribute .ident { color: #C82829; } |
| 21 | +.macro, .macro-nonterminal { color: #3E999F; } |
| 22 | +.lifetime { color: #B76514; } |
| 23 | +.question-mark { color: #ff9011; } |
| 24 | +</style> |
| 25 | +"#; |
0 commit comments