]>
git.proxmox.com Git - rustc.git/blob - src/librustdoc/html/highlight/tests.rs
1 use rustc_session
::parse
::ParseSess
;
2 use rustc_span
::edition
::Edition
;
3 use rustc_span
::with_session_globals
;
4 use rustc_span
::FileName
;
8 fn highlight(src
: &str) -> String
{
11 with_session_globals(Edition
::Edition2018
, || {
12 let sess
= ParseSess
::with_silent_emitter();
13 let source_file
= sess
.source_map().new_source_file(
14 FileName
::Custom(String
::from("rustdoc-highlighting")),
18 let mut classifier
= Classifier
::new(&sess
, source_file
);
19 classifier
.write_source(&mut out
).unwrap();
22 String
::from_utf8(out
).unwrap()
28 highlight("fn main() {}"),
29 r
#"<span class="kw">fn</span> <span class="ident">main</span>() {}"#,
36 highlight("let foo = true;"),
38 r
#"<span class="kw">let</span> <span class="ident">foo</span> "#,
39 r
#"<span class="op">=</span> <span class="bool-val">true</span>;"#,
47 highlight(r
##"#![crate_type = "lib"]"##),
49 r
##"<span class="attribute">#![<span class="ident">crate_type</span> "##,
50 r
##"<span class="op">=</span> <span class="string">"lib"</span>]</span>"##,
58 highlight(r
##"#[cfg(target_os = "linux")]"##),
60 r
##"<span class="attribute">#[<span class="ident">cfg</span>("##,
61 r
##"<span class="ident">target_os</span> <span class="op">=</span> "##,
62 r
##"<span class="string">"linux"</span>)]</span>"##,
70 highlight("mac!(foo bar)"),
72 r
#"<span class="macro">mac</span><span class="macro">!</span>("#,
73 r
#"<span class="ident">foo</span> <span class="ident">bar</span>)"#,
78 // Regression test for #72684
81 assert_eq
!(highlight("&&"), r
#"<span class="op">&&</span>"#);