aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting/tests.rs')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs32
1 files changed, 20 insertions, 12 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index b7fad9719..87a6e2523 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -1,6 +1,7 @@
1use std::fs; 1use std::fs;
2 2
3use test_utils::{assert_eq_text, project_dir, read_text}; 3use expect::{expect_file, ExpectFile};
4use test_utils::project_dir;
4 5
5use crate::{mock_analysis::single_file, FileRange, TextRange}; 6use crate::{mock_analysis::single_file, FileRange, TextRange};
6 7
@@ -24,6 +25,16 @@ impl Bar for Foo {
24 } 25 }
25} 26}
26 27
28impl Foo {
29 fn baz(mut self) -> i32 {
30 self.x
31 }
32
33 fn qux(&mut self) {
34 self.x = 0;
35 }
36}
37
27static mut STATIC_MUT: i32 = 0; 38static mut STATIC_MUT: i32 = 0;
28 39
29fn foo<'a, T>() -> T { 40fn foo<'a, T>() -> T {
@@ -91,7 +102,7 @@ impl<T> Option<T> {
91} 102}
92"# 103"#
93 .trim(), 104 .trim(),
94 "crates/ra_ide/src/snapshots/highlighting.html", 105 expect_file!["crates/ra_ide/test_data/highlighting.html"],
95 false, 106 false,
96 ); 107 );
97} 108}
@@ -114,7 +125,7 @@ fn bar() {
114} 125}
115"# 126"#
116 .trim(), 127 .trim(),
117 "crates/ra_ide/src/snapshots/rainbow_highlighting.html", 128 expect_file!["crates/ra_ide/test_data/rainbow_highlighting.html"],
118 true, 129 true,
119 ); 130 );
120} 131}
@@ -167,7 +178,7 @@ fn main() {
167 ); 178 );
168}"## 179}"##
169 .trim(), 180 .trim(),
170 "crates/ra_ide/src/snapshots/highlight_injection.html", 181 expect_file!["crates/ra_ide/test_data/highlight_injection.html"],
171 false, 182 false,
172 ); 183 );
173} 184}
@@ -250,7 +261,7 @@ fn main() {
250 println!("{ничоси}", ничоси = 92); 261 println!("{ничоси}", ничоси = 92);
251}"# 262}"#
252 .trim(), 263 .trim(),
253 "crates/ra_ide/src/snapshots/highlight_strings.html", 264 expect_file!["crates/ra_ide/test_data/highlight_strings.html"],
254 false, 265 false,
255 ); 266 );
256} 267}
@@ -278,7 +289,7 @@ fn main() {
278} 289}
279"# 290"#
280 .trim(), 291 .trim(),
281 "crates/ra_ide/src/snapshots/highlight_unsafe.html", 292 expect_file!["crates/ra_ide/test_data/highlight_unsafe.html"],
282 false, 293 false,
283 ); 294 );
284} 295}
@@ -354,7 +365,7 @@ macro_rules! noop {
354} 365}
355"# 366"#
356 .trim(), 367 .trim(),
357 "crates/ra_ide/src/snapshots/highlight_doctest.html", 368 expect_file!["crates/ra_ide/test_data/highlight_doctest.html"],
358 false, 369 false,
359 ); 370 );
360} 371}
@@ -362,11 +373,8 @@ macro_rules! noop {
362/// Highlights the code given by the `ra_fixture` argument, renders the 373/// Highlights the code given by the `ra_fixture` argument, renders the
363/// result as HTML, and compares it with the HTML file given as `snapshot`. 374/// result as HTML, and compares it with the HTML file given as `snapshot`.
364/// Note that the `snapshot` file is overwritten by the rendered HTML. 375/// Note that the `snapshot` file is overwritten by the rendered HTML.
365fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) { 376fn check_highlighting(ra_fixture: &str, expect: ExpectFile, rainbow: bool) {
366 let (analysis, file_id) = single_file(ra_fixture); 377 let (analysis, file_id) = single_file(ra_fixture);
367 let dst_file = project_dir().join(snapshot);
368 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap(); 378 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
369 let expected_html = &read_text(&dst_file); 379 expect.assert_eq(actual_html)
370 fs::write(dst_file, &actual_html).unwrap();
371 assert_eq_text!(expected_html, actual_html);
372} 380}