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.rs55
1 files changed, 44 insertions, 11 deletions
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index a62704c39..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() {
@@ -81,6 +80,10 @@ impl FooCopy {
81 } 80 }
82} 81}
83 82
83fn str() {
84 str();
85}
86
84static mut STATIC_MUT: i32 = 0; 87static mut STATIC_MUT: i32 = 0;
85 88
86fn foo<'a, T>() -> T { 89fn foo<'a, T>() -> T {
@@ -224,15 +227,45 @@ fn bar() {
224} 227}
225 228
226#[test] 229#[test]
227fn accidentally_quadratic() { 230fn benchmark_syntax_highlighting_long_struct() {
228 let file = project_dir().join("crates/syntax/test_data/accidentally_quadratic"); 231 if skip_slow_tests() {
229 let src = fs::read_to_string(file).unwrap(); 232 return;
233 }
230 234
231 let (analysis, file_id) = fixture::file(&src); 235 let fixture = bench_fixture::big_struct();
236 let (analysis, file_id) = fixture::file(&fixture);
232 237
233 // let t = std::time::Instant::now(); 238 let hash = {
234 let _ = analysis.highlight(file_id).unwrap(); 239 let _pt = bench("syntax highlighting long struct");
235 // 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);
236} 269}
237 270
238#[test] 271#[test]