3 use test_utils::{assert_eq_text, project_dir, read_text};
6 mock_analysis::{single_file, MockAnalysis},
11 fn test_highlighting() {
12 let (analysis, file_id) = single_file(
14 #[derive(Clone, Debug)]
20 fn foo<'a, T>() -> T {
25 ($($tt:tt)*) => {$($tt)*}
36 println!("Hello, {}!", 92);
38 let mut vec = Vec::new();
41 vec.push(Foo { x, y: 1 });
43 unsafe { vec.set_len(0); }
59 fn and<U>(self, other: Option<U>) -> Option<(T, U)> {
61 None => unimplemented!(),
69 let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlighting.html");
70 let actual_html = &analysis.highlight_as_html(file_id, false).unwrap();
71 let expected_html = &read_text(&dst_file);
72 fs::write(dst_file, &actual_html).unwrap();
73 assert_eq_text!(expected_html, actual_html);
77 fn test_rainbow_highlighting() {
78 let (analysis, file_id) = single_file(
82 let x = hello.to_string();
83 let y = hello.to_string();
85 let x = "other color please!";
86 let y = x.to_string();
90 let mut hello = "hello";
95 let dst_file = project_dir().join("crates/ra_ide/src/snapshots/rainbow_highlighting.html");
96 let actual_html = &analysis.highlight_as_html(file_id, true).unwrap();
97 let expected_html = &read_text(&dst_file);
98 fs::write(dst_file, &actual_html).unwrap();
99 assert_eq_text!(expected_html, actual_html);
103 fn accidentally_quadratic() {
104 let file = project_dir().join("crates/ra_syntax/test_data/accidentally_quadratic");
105 let src = fs::read_to_string(file).unwrap();
107 let mut mock = MockAnalysis::new();
108 let file_id = mock.add_file("/main.rs", &src);
109 let host = mock.analysis_host();
111 // let t = std::time::Instant::now();
112 let _ = host.analysis().highlight(file_id).unwrap();
113 // eprintln!("elapsed: {:?}", t.elapsed());
118 let (analysis, file_id) = single_file(
120 #[derive(Clone, Debug)]
128 let highlights = &analysis
129 .highlight_range(FileRange { file_id, range: TextRange::offset_len(82.into(), 1.into()) })
132 assert_eq!(&highlights[0].highlight.to_string(), "field.declaration");
136 fn test_flattening() {
137 let (analysis, file_id) = single_file(
139 fn fixture(ra_fixture: &str) {}
145 println!("2 + 2 = {}", 4);
153 let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_injection.html");
154 let actual_html = &analysis.highlight_as_html(file_id, false).unwrap();
155 let expected_html = &read_text(&dst_file);
156 fs::write(dst_file, &actual_html).unwrap();
157 assert_eq_text!(expected_html, actual_html);
162 let (analysis, file_id) = single_file(
169 let _ = analysis.highlight(file_id).unwrap();