From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../html/highlight/fixtures/decorations.html | 2 + .../html/highlight/fixtures/dos_line.html | 3 + .../html/highlight/fixtures/highlight.html | 4 ++ src/librustdoc/html/highlight/fixtures/sample.html | 37 ++++++++++ src/librustdoc/html/highlight/fixtures/sample.rs | 26 +++++++ src/librustdoc/html/highlight/fixtures/union.html | 8 +++ src/librustdoc/html/highlight/fixtures/union.rs | 8 +++ src/librustdoc/html/highlight/tests.rs | 81 ++++++++++++++++++++++ 8 files changed, 169 insertions(+) create mode 100644 src/librustdoc/html/highlight/fixtures/decorations.html create mode 100644 src/librustdoc/html/highlight/fixtures/dos_line.html create mode 100644 src/librustdoc/html/highlight/fixtures/highlight.html create mode 100644 src/librustdoc/html/highlight/fixtures/sample.html create mode 100644 src/librustdoc/html/highlight/fixtures/sample.rs create mode 100644 src/librustdoc/html/highlight/fixtures/union.html create mode 100644 src/librustdoc/html/highlight/fixtures/union.rs create mode 100644 src/librustdoc/html/highlight/tests.rs (limited to 'src/librustdoc/html/highlight') diff --git a/src/librustdoc/html/highlight/fixtures/decorations.html b/src/librustdoc/html/highlight/fixtures/decorations.html new file mode 100644 index 000000000..45f567880 --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/decorations.html @@ -0,0 +1,2 @@ +let x = 1; +let y = 2; \ No newline at end of file diff --git a/src/librustdoc/html/highlight/fixtures/dos_line.html b/src/librustdoc/html/highlight/fixtures/dos_line.html new file mode 100644 index 000000000..1c8dbffe7 --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/dos_line.html @@ -0,0 +1,3 @@ +pub fn foo() { +println!("foo"); +} diff --git a/src/librustdoc/html/highlight/fixtures/highlight.html b/src/librustdoc/html/highlight/fixtures/highlight.html new file mode 100644 index 000000000..abc2db179 --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/highlight.html @@ -0,0 +1,4 @@ +use crate::a::foo; +use self::whatever; +let x = super::b::foo; +let y = Self::whatever; \ No newline at end of file diff --git a/src/librustdoc/html/highlight/fixtures/sample.html b/src/librustdoc/html/highlight/fixtures/sample.html new file mode 100644 index 000000000..b117a12e3 --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/sample.html @@ -0,0 +1,37 @@ + + +
#![crate_type = "lib"]
+
+use std::path::{Path, PathBuf};
+
+#[cfg(target_os = "linux")]
+fn main() -> () {
+    let foo = true && false || true;
+    let _: *const () = 0;
+    let _ = &foo;
+    let _ = &&foo;
+    let _ = *foo;
+    mac!(foo, &mut bar);
+    assert!(self.length < N && index <= self.length);
+    ::std::env::var("gateau").is_ok();
+    #[rustfmt::skip]
+    let s:std::path::PathBuf = std::path::PathBuf::new();
+    let mut s = String::new();
+
+    match &s {
+        ref mut x => {}
+    }
+}
+
+macro_rules! bar {
+    ($foo:tt) => {};
+}
+
diff --git a/src/librustdoc/html/highlight/fixtures/sample.rs b/src/librustdoc/html/highlight/fixtures/sample.rs new file mode 100644 index 000000000..fbfdc6767 --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/sample.rs @@ -0,0 +1,26 @@ +#![crate_type = "lib"] + +use std::path::{Path, PathBuf}; + +#[cfg(target_os = "linux")] +fn main() -> () { + let foo = true && false || true; + let _: *const () = 0; + let _ = &foo; + let _ = &&foo; + let _ = *foo; + mac!(foo, &mut bar); + assert!(self.length < N && index <= self.length); + ::std::env::var("gateau").is_ok(); + #[rustfmt::skip] + let s:std::path::PathBuf = std::path::PathBuf::new(); + let mut s = String::new(); + + match &s { + ref mut x => {} + } +} + +macro_rules! bar { + ($foo:tt) => {}; +} diff --git a/src/librustdoc/html/highlight/fixtures/union.html b/src/librustdoc/html/highlight/fixtures/union.html new file mode 100644 index 000000000..c0acf31a0 --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/union.html @@ -0,0 +1,8 @@ +union Foo { + i: i8, + u: i8, +} + +fn main() { + let union = 0; +} diff --git a/src/librustdoc/html/highlight/fixtures/union.rs b/src/librustdoc/html/highlight/fixtures/union.rs new file mode 100644 index 000000000..269ee115d --- /dev/null +++ b/src/librustdoc/html/highlight/fixtures/union.rs @@ -0,0 +1,8 @@ +union Foo { + i: i8, + u: i8, +} + +fn main() { + let union = 0; +} 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#" + +"#; + +#[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!("{}
{}
\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()); + }); +} -- cgit v1.2.3