Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/syntax_highlighting/tests.rs')
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs35
1 files changed, 33 insertions, 2 deletions
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index dd359326c6..8198701d68 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -9,6 +9,7 @@ use crate::{FileRange, HighlightConfig, HlTag, TextRange, fixture};
const HL_CONFIG: HighlightConfig = HighlightConfig {
strings: true,
+ comments: true,
punctuation: true,
specialize_punctuation: true,
specialize_operator: true,
@@ -1220,16 +1221,25 @@ fn foo(x: &fn(&dyn Trait)) {}
/// Highlights the code given by the `ra_fixture` argument, renders the
/// result as HTML, and compares it with the HTML file given as `snapshot`.
/// Note that the `snapshot` file is overwritten by the rendered HTML.
-fn check_highlighting(
+fn check_highlighting_with_config(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
+ config: HighlightConfig,
expect: ExpectFile,
rainbow: bool,
) {
let (analysis, file_id) = fixture::file(ra_fixture.trim());
- let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
+ let actual_html = &analysis.highlight_as_html_with_config(config, file_id, rainbow).unwrap();
expect.assert_eq(actual_html)
}
+fn check_highlighting(
+ #[rust_analyzer::rust_fixture] ra_fixture: &str,
+ expect: ExpectFile,
+ rainbow: bool,
+) {
+ check_highlighting_with_config(ra_fixture, HL_CONFIG, expect, rainbow)
+}
+
#[test]
fn benchmark_syntax_highlighting_long_struct() {
if skip_slow_tests() {
@@ -1435,3 +1445,24 @@ fn main() {
false,
);
}
+
+#[test]
+fn test_comment_highlighting_disabled() {
+ // Test that comments are not highlighted when disabled
+ check_highlighting_with_config(
+ r#"
+// This is a regular comment
+/// This is a doc comment
+fn main() {
+ // Another comment
+ println!("Hello, world!");
+}
+"#,
+ HighlightConfig {
+ comments: false, // Disable comment highlighting
+ ..HL_CONFIG
+ },
+ expect_file!["./test_data/highlight_comments_disabled.html"],
+ false,
+ );
+}