diff options
author | Leander Tentrup <[email protected]> | 2020-04-02 13:34:51 +0100 |
---|---|---|
committer | Leander Tentrup <[email protected]> | 2020-04-03 08:46:07 +0100 |
commit | bb45aca9093ffe61cf444d538b3de737117c9a64 (patch) | |
tree | 7f7672e3347fa4054480b0d035caeb94d7f0af32 /crates/ra_ide/src/syntax_highlighting | |
parent | 3c9e9d3f3ebbc7a22d932dd2a3fd63f1e44c4568 (diff) |
Flatten nested highlight ranges during DFS traversal
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 98c030791..7f442bd0f 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -131,3 +131,19 @@ fn test_ranges() { | |||
131 | 131 | ||
132 | assert_eq!(&highlights[0].highlight.to_string(), "field.declaration"); | 132 | assert_eq!(&highlights[0].highlight.to_string(), "field.declaration"); |
133 | } | 133 | } |
134 | |||
135 | #[test] | ||
136 | fn test_flattening() { | ||
137 | let (analysis, file_id) = single_file(r#"#[cfg(feature = "foo")]"#); | ||
138 | |||
139 | let highlights = analysis.highlight(file_id).unwrap(); | ||
140 | |||
141 | // The source code snippet contains 2 nested highlights: | ||
142 | // 1) Attribute spanning the whole string | ||
143 | // 2) The string "foo" | ||
144 | // The resulting flattening splits the attribute range: | ||
145 | assert_eq!(highlights.len(), 3); | ||
146 | assert_eq!(&highlights[0].highlight.to_string(), "attribute"); | ||
147 | assert_eq!(&highlights[1].highlight.to_string(), "string_literal"); | ||
148 | assert_eq!(&highlights[2].highlight.to_string(), "attribute"); | ||
149 | } | ||