diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/librustdoc/html/highlight/tests.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/html/highlight/tests.rs')
-rw-r--r-- | src/librustdoc/html/highlight/tests.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/librustdoc/html/highlight/tests.rs b/src/librustdoc/html/highlight/tests.rs new file mode 100644 index 000000000..1fea7e983 --- /dev/null +++ b/src/librustdoc/html/highlight/tests.rs @@ -0,0 +1,81 @@ +use super::{write_code, DecorationInfo}; +use crate::html::format::Buffer; +use expect_test::expect_file; +use rustc_data_structures::fx::FxHashMap; +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, None, None); + 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, None, None); + expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner()); + }); +} + +#[test] +fn test_keyword_highlight() { + create_default_session_globals_then(|| { + let src = "use crate::a::foo; +use self::whatever; +let x = super::b::foo; +let y = Self::whatever;"; + + let mut html = Buffer::new(); + write_code(&mut html, src, Edition::Edition2018, None, None); + expect_file!["fixtures/highlight.html"].assert_eq(&html.into_inner()); + }); +} + +#[test] +fn test_union_highlighting() { + create_default_session_globals_then(|| { + let src = include_str!("fixtures/union.rs"); + let mut html = Buffer::new(); + write_code(&mut html, src, Edition::Edition2018, None, None); + expect_file!["fixtures/union.html"].assert_eq(&html.into_inner()); + }); +} + +#[test] +fn test_decorations() { + create_default_session_globals_then(|| { + let src = "let x = 1; +let y = 2;"; + let mut decorations = FxHashMap::default(); + decorations.insert("example", vec![(0, 10)]); + + let mut html = Buffer::new(); + write_code(&mut html, src, Edition::Edition2018, None, Some(DecorationInfo(decorations))); + expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner()); + }); +} |