diff options
author | Mikhail Rakhmanov <[email protected]> | 2020-06-13 07:42:15 +0100 |
---|---|---|
committer | Mikhail Rakhmanov <[email protected]> | 2020-06-13 07:42:15 +0100 |
commit | 16bbf4ab7f132e6e5e5318dccdef9a5d71afdd7f (patch) | |
tree | 4b79fa8c046be56b02427ba843e70cdf3ac05767 /crates/ra_ide/src/syntax_highlighting/tests.rs | |
parent | eeb8b9e236796da8734ba81a49164864497f7226 (diff) | |
parent | b56ad148db0c69eb279c225f45d324b4e80e7367 (diff) |
Merge branch 'master' into keyword_completion
# Conflicts:
# docs/user/generated_features.adoc
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting/tests.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 123 |
1 files changed, 101 insertions, 22 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index eb43a23da..949bf59a0 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | 9 | ||
10 | #[test] | 10 | #[test] |
11 | fn test_highlighting() { | 11 | fn test_highlighting() { |
12 | let (analysis, file_id) = single_file( | 12 | check_highlighting( |
13 | r#" | 13 | r#" |
14 | #[derive(Clone, Debug)] | 14 | #[derive(Clone, Debug)] |
15 | struct Foo { | 15 | struct Foo { |
@@ -65,6 +65,8 @@ fn main() { | |||
65 | let y = &mut x; | 65 | let y = &mut x; |
66 | let z = &y; | 66 | let z = &y; |
67 | 67 | ||
68 | let Foo { x: z, y } = Foo { x: z, y }; | ||
69 | |||
68 | y; | 70 | y; |
69 | } | 71 | } |
70 | 72 | ||
@@ -84,17 +86,14 @@ impl<T> Option<T> { | |||
84 | } | 86 | } |
85 | "# | 87 | "# |
86 | .trim(), | 88 | .trim(), |
89 | "crates/ra_ide/src/snapshots/highlighting.html", | ||
90 | false, | ||
87 | ); | 91 | ); |
88 | let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlighting.html"); | ||
89 | let actual_html = &analysis.highlight_as_html(file_id, false).unwrap(); | ||
90 | let expected_html = &read_text(&dst_file); | ||
91 | fs::write(dst_file, &actual_html).unwrap(); | ||
92 | assert_eq_text!(expected_html, actual_html); | ||
93 | } | 92 | } |
94 | 93 | ||
95 | #[test] | 94 | #[test] |
96 | fn test_rainbow_highlighting() { | 95 | fn test_rainbow_highlighting() { |
97 | let (analysis, file_id) = single_file( | 96 | check_highlighting( |
98 | r#" | 97 | r#" |
99 | fn main() { | 98 | fn main() { |
100 | let hello = "hello"; | 99 | let hello = "hello"; |
@@ -110,12 +109,9 @@ fn bar() { | |||
110 | } | 109 | } |
111 | "# | 110 | "# |
112 | .trim(), | 111 | .trim(), |
112 | "crates/ra_ide/src/snapshots/rainbow_highlighting.html", | ||
113 | true, | ||
113 | ); | 114 | ); |
114 | let dst_file = project_dir().join("crates/ra_ide/src/snapshots/rainbow_highlighting.html"); | ||
115 | let actual_html = &analysis.highlight_as_html(file_id, true).unwrap(); | ||
116 | let expected_html = &read_text(&dst_file); | ||
117 | fs::write(dst_file, &actual_html).unwrap(); | ||
118 | assert_eq_text!(expected_html, actual_html); | ||
119 | } | 115 | } |
120 | 116 | ||
121 | #[test] | 117 | #[test] |
@@ -153,7 +149,7 @@ fn test_ranges() { | |||
153 | 149 | ||
154 | #[test] | 150 | #[test] |
155 | fn test_flattening() { | 151 | fn test_flattening() { |
156 | let (analysis, file_id) = single_file( | 152 | check_highlighting( |
157 | r##" | 153 | r##" |
158 | fn fixture(ra_fixture: &str) {} | 154 | fn fixture(ra_fixture: &str) {} |
159 | 155 | ||
@@ -167,13 +163,9 @@ fn main() { | |||
167 | ); | 163 | ); |
168 | }"## | 164 | }"## |
169 | .trim(), | 165 | .trim(), |
166 | "crates/ra_ide/src/snapshots/highlight_injection.html", | ||
167 | false, | ||
170 | ); | 168 | ); |
171 | |||
172 | let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_injection.html"); | ||
173 | let actual_html = &analysis.highlight_as_html(file_id, false).unwrap(); | ||
174 | let expected_html = &read_text(&dst_file); | ||
175 | fs::write(dst_file, &actual_html).unwrap(); | ||
176 | assert_eq_text!(expected_html, actual_html); | ||
177 | } | 169 | } |
178 | 170 | ||
179 | #[test] | 171 | #[test] |
@@ -192,7 +184,7 @@ macro_rules! test {} | |||
192 | fn test_string_highlighting() { | 184 | fn test_string_highlighting() { |
193 | // The format string detection is based on macro-expansion, | 185 | // The format string detection is based on macro-expansion, |
194 | // thus, we have to copy the macro definition from `std` | 186 | // thus, we have to copy the macro definition from `std` |
195 | let (analysis, file_id) = single_file( | 187 | check_highlighting( |
196 | r#" | 188 | r#" |
197 | macro_rules! println { | 189 | macro_rules! println { |
198 | ($($arg:tt)*) => ({ | 190 | ($($arg:tt)*) => ({ |
@@ -218,6 +210,7 @@ fn main() { | |||
218 | println!("{argument}", argument = "test"); // => "test" | 210 | println!("{argument}", argument = "test"); // => "test" |
219 | println!("{name} {}", 1, name = 2); // => "2 1" | 211 | println!("{name} {}", 1, name = 2); // => "2 1" |
220 | println!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b" | 212 | println!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b" |
213 | println!("{{{}}}", 2); // => "{2}" | ||
221 | println!("Hello {:5}!", "x"); | 214 | println!("Hello {:5}!", "x"); |
222 | println!("Hello {:1$}!", "x", 5); | 215 | println!("Hello {:1$}!", "x", 5); |
223 | println!("Hello {1:0$}!", 5, "x"); | 216 | println!("Hello {1:0$}!", 5, "x"); |
@@ -249,10 +242,96 @@ fn main() { | |||
249 | println!("{ничоси}", ничоси = 92); | 242 | println!("{ничоси}", ничоси = 92); |
250 | }"# | 243 | }"# |
251 | .trim(), | 244 | .trim(), |
245 | "crates/ra_ide/src/snapshots/highlight_strings.html", | ||
246 | false, | ||
252 | ); | 247 | ); |
248 | } | ||
249 | |||
250 | #[test] | ||
251 | fn test_unsafe_highlighting() { | ||
252 | check_highlighting( | ||
253 | r#" | ||
254 | unsafe fn unsafe_fn() {} | ||
255 | |||
256 | struct HasUnsafeFn; | ||
257 | |||
258 | impl HasUnsafeFn { | ||
259 | unsafe fn unsafe_method(&self) {} | ||
260 | } | ||
261 | |||
262 | fn main() { | ||
263 | let x = &5 as *const usize; | ||
264 | unsafe { | ||
265 | unsafe_fn(); | ||
266 | HasUnsafeFn.unsafe_method(); | ||
267 | let y = *(x); | ||
268 | let z = -x; | ||
269 | } | ||
270 | } | ||
271 | "# | ||
272 | .trim(), | ||
273 | "crates/ra_ide/src/snapshots/highlight_unsafe.html", | ||
274 | false, | ||
275 | ); | ||
276 | } | ||
277 | |||
278 | #[test] | ||
279 | fn test_highlight_doctest() { | ||
280 | check_highlighting( | ||
281 | r#" | ||
282 | impl Foo { | ||
283 | /// Constructs a new `Foo`. | ||
284 | /// | ||
285 | /// # Examples | ||
286 | /// | ||
287 | /// ``` | ||
288 | /// # #![allow(unused_mut)] | ||
289 | /// let mut foo: Foo = Foo::new(); | ||
290 | /// ``` | ||
291 | pub const fn new() -> Foo { | ||
292 | Foo { } | ||
293 | } | ||
294 | |||
295 | /// `bar` method on `Foo`. | ||
296 | /// | ||
297 | /// # Examples | ||
298 | /// | ||
299 | /// ``` | ||
300 | /// let foo = Foo::new(); | ||
301 | /// | ||
302 | /// // calls bar on foo | ||
303 | /// assert!(foo.bar()); | ||
304 | /// | ||
305 | /// /* multi-line | ||
306 | /// comment */ | ||
307 | /// | ||
308 | /// let multi_line_string = "Foo | ||
309 | /// bar | ||
310 | /// "; | ||
311 | /// | ||
312 | /// ``` | ||
313 | /// | ||
314 | /// ``` | ||
315 | /// let foobar = Foo::new().bar(); | ||
316 | /// ``` | ||
317 | pub fn foo(&self) -> bool { | ||
318 | true | ||
319 | } | ||
320 | } | ||
321 | "# | ||
322 | .trim(), | ||
323 | "crates/ra_ide/src/snapshots/highlight_doctest.html", | ||
324 | false, | ||
325 | ) | ||
326 | } | ||
253 | 327 | ||
254 | let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_strings.html"); | 328 | /// Highlights the code given by the `ra_fixture` argument, renders the |
255 | let actual_html = &analysis.highlight_as_html(file_id, false).unwrap(); | 329 | /// result as HTML, and compares it with the HTML file given as `snapshot`. |
330 | /// Note that the `snapshot` file is overwritten by the rendered HTML. | ||
331 | fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) { | ||
332 | let (analysis, file_id) = single_file(ra_fixture); | ||
333 | let dst_file = project_dir().join(snapshot); | ||
334 | let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap(); | ||
256 | let expected_html = &read_text(&dst_file); | 335 | let expected_html = &read_text(&dst_file); |
257 | fs::write(dst_file, &actual_html).unwrap(); | 336 | fs::write(dst_file, &actual_html).unwrap(); |
258 | assert_eq_text!(expected_html, actual_html); | 337 | assert_eq_text!(expected_html, actual_html); |