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; const STYLE: &str = r#" "#; #[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, None, None); format!("{STYLE}
{}
\n", 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, 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, 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, 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 z = 3; let a = 4;"; let mut decorations = FxHashMap::default(); decorations.insert("example", vec![(0, 10), (11, 21)]); decorations.insert("example2", vec![(22, 32)]); let mut html = Buffer::new(); write_code(&mut html, src, None, Some(DecorationInfo(decorations))); expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner()); }); }