aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/syntax_highlighting/tests.rs')
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs51
1 files changed, 40 insertions, 11 deletions
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 1854da914..9d0cd1af5 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -1,9 +1,8 @@
1use std::fs;
2
3use expect_test::{expect_file, ExpectFile}; 1use expect_test::{expect_file, ExpectFile};
4use test_utils::project_dir; 2use ide_db::SymbolKind;
3use test_utils::{bench, bench_fixture, skip_slow_tests};
5 4
6use crate::{fixture, FileRange, TextRange}; 5use crate::{fixture, FileRange, HlTag, TextRange};
7 6
8#[test] 7#[test]
9fn test_highlighting() { 8fn test_highlighting() {
@@ -228,15 +227,45 @@ fn bar() {
228} 227}
229 228
230#[test] 229#[test]
231fn accidentally_quadratic() { 230fn benchmark_syntax_highlighting_long_struct() {
232 let file = project_dir().join("crates/syntax/test_data/accidentally_quadratic"); 231 if skip_slow_tests() {
233 let src = fs::read_to_string(file).unwrap(); 232 return;
233 }
234 234
235 let (analysis, file_id) = fixture::file(&src); 235 let fixture = bench_fixture::big_struct();
236 let (analysis, file_id) = fixture::file(&fixture);
236 237
237 // let t = std::time::Instant::now(); 238 let hash = {
238 let _ = analysis.highlight(file_id).unwrap(); 239 let _pt = bench("syntax highlighting long struct");
239 // eprintln!("elapsed: {:?}", t.elapsed()); 240 analysis
241 .highlight(file_id)
242 .unwrap()
243 .iter()
244 .filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Struct))
245 .count()
246 };
247 assert_eq!(hash, 2001);
248}
249
250#[test]
251fn benchmark_syntax_highlighting_parser() {
252 if skip_slow_tests() {
253 return;
254 }
255
256 let fixture = bench_fixture::glorious_old_parser();
257 let (analysis, file_id) = fixture::file(&fixture);
258
259 let hash = {
260 let _pt = bench("syntax highlighting parser");
261 analysis
262 .highlight(file_id)
263 .unwrap()
264 .iter()
265 .filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function))
266 .count()
267 };
268 assert_eq!(hash, 1629);
240} 269}
241 270
242#[test] 271#[test]