aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/tests/test.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-24 10:38:21 +0100
committerAleksey Kladov <[email protected]>2019-07-24 10:49:19 +0100
commit459241f272748ff2e57b2c7e84f5a04f78d67edb (patch)
tree2353f8f068962313d0b2748aab58b71c4ca456d2 /crates/ra_syntax/tests/test.rs
parent4d544fbf9b664b6a29d358d3cb41cdd7cd15e4d6 (diff)
move syntax tests to unit tests
Diffstat (limited to 'crates/ra_syntax/tests/test.rs')
-rw-r--r--crates/ra_syntax/tests/test.rs104
1 files changed, 0 insertions, 104 deletions
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs
deleted file mode 100644
index cabd3e9bd..000000000
--- a/crates/ra_syntax/tests/test.rs
+++ /dev/null
@@ -1,104 +0,0 @@
1extern crate ra_syntax;
2extern crate test_utils;
3extern crate walkdir;
4
5use std::{
6 fmt::Write,
7 path::{Component, PathBuf},
8};
9
10use ra_syntax::{fuzz, SourceFile};
11use test_utils::{collect_tests, dir_tests, project_dir, read_text};
12
13#[test]
14fn lexer_tests() {
15 dir_tests(&test_data_dir(), &["lexer"], |text, _| {
16 let tokens = ra_syntax::tokenize(text);
17 dump_tokens(&tokens, text)
18 })
19}
20
21#[test]
22fn parser_tests() {
23 dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], |text, path| {
24 let parse = SourceFile::parse(text);
25 let errors = parse.errors();
26 assert_eq!(
27 errors,
28 &[] as &[ra_syntax::SyntaxError],
29 "There should be no errors in the file {:?}",
30 path.display(),
31 );
32 parse.debug_dump()
33 });
34 dir_tests(&test_data_dir(), &["parser/err", "parser/inline/err"], |text, path| {
35 let parse = SourceFile::parse(text);
36 let errors = parse.errors();
37 assert!(!errors.is_empty(), "There should be errors in the file {:?}", path.display());
38 parse.debug_dump()
39 });
40}
41
42#[test]
43fn parser_fuzz_tests() {
44 for (_, text) in collect_tests(&test_data_dir(), &["parser/fuzz-failures"]) {
45 fuzz::check_parser(&text)
46 }
47}
48
49#[test]
50fn reparse_fuzz_tests() {
51 for (_, text) in collect_tests(&test_data_dir(), &["reparse/fuzz-failures"]) {
52 let check = fuzz::CheckReparse::from_data(text.as_bytes()).unwrap();
53 println!("{:?}", check);
54 check.run();
55 }
56}
57
58/// Test that Rust-analyzer can parse and validate the rust-analyzer
59/// FIXME: Use this as a benchmark
60#[test]
61fn self_hosting_parsing() {
62 use std::ffi::OsStr;
63 let dir = project_dir().join("crates");
64 let mut count = 0;
65 for entry in walkdir::WalkDir::new(dir)
66 .into_iter()
67 .filter_entry(|entry| {
68 !entry.path().components().any(|component| {
69 // Get all files which are not in the crates/ra_syntax/tests/data folder
70 component == Component::Normal(OsStr::new("data"))
71 })
72 })
73 .map(|e| e.unwrap())
74 .filter(|entry| {
75 // Get all `.rs ` files
76 !entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs")))
77 })
78 {
79 count += 1;
80 let text = read_text(entry.path());
81 SourceFile::parse(&text).ok().expect("There should be no errors in the file");
82 }
83 assert!(
84 count > 30,
85 "self_hosting_parsing found too few files - is it running in the right directory?"
86 )
87}
88
89fn test_data_dir() -> PathBuf {
90 project_dir().join("crates/ra_syntax/tests/data")
91}
92
93fn dump_tokens(tokens: &[ra_syntax::Token], text: &str) -> String {
94 let mut acc = String::new();
95 let mut offset = 0;
96 for token in tokens {
97 let len: u32 = token.len.into();
98 let len = len as usize;
99 let token_text = &text[offset..offset + len];
100 offset += len;
101 write!(acc, "{:?} {} {:?}\n", token.kind, token.len, token_text).unwrap()
102 }
103 acc
104}