diff options
Diffstat (limited to 'crates/ra_syntax/tests/test.rs')
-rw-r--r-- | crates/ra_syntax/tests/test.rs | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index c17b6ffa6..4266864bd 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs | |||
@@ -16,7 +16,7 @@ use ra_syntax::{ | |||
16 | 16 | ||
17 | #[test] | 17 | #[test] |
18 | fn lexer_tests() { | 18 | fn lexer_tests() { |
19 | dir_tests(&["lexer"], |text| { | 19 | dir_tests(&["lexer"], |text, _| { |
20 | let tokens = ra_syntax::tokenize(text); | 20 | let tokens = ra_syntax::tokenize(text); |
21 | dump_tokens(&tokens, text) | 21 | dump_tokens(&tokens, text) |
22 | }) | 22 | }) |
@@ -24,10 +24,28 @@ fn lexer_tests() { | |||
24 | 24 | ||
25 | #[test] | 25 | #[test] |
26 | fn parser_tests() { | 26 | fn parser_tests() { |
27 | dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { | 27 | dir_tests(&["parser/inline/ok", "parser/ok"], |text, path| { |
28 | let file = SourceFileNode::parse(text); | 28 | let file = SourceFileNode::parse(text); |
29 | let errors = file.errors(); | ||
30 | assert_eq!( | ||
31 | &*errors, | ||
32 | &[] as &[ra_syntax::SyntaxError], | ||
33 | "There should be no errors in the file {:?}", | ||
34 | path.display() | ||
35 | ); | ||
29 | dump_tree(file.syntax()) | 36 | dump_tree(file.syntax()) |
30 | }) | 37 | }); |
38 | dir_tests(&["parser/err", "parser/inline/err"], |text, path| { | ||
39 | let file = SourceFileNode::parse(text); | ||
40 | let errors = file.errors(); | ||
41 | assert_ne!( | ||
42 | &*errors, | ||
43 | &[] as &[ra_syntax::SyntaxError], | ||
44 | "There should be errors in the file {:?}", | ||
45 | path.display() | ||
46 | ); | ||
47 | dump_tree(file.syntax()) | ||
48 | }); | ||
31 | } | 49 | } |
32 | 50 | ||
33 | #[test] | 51 | #[test] |
@@ -42,20 +60,15 @@ fn parser_fuzz_tests() { | |||
42 | #[test] | 60 | #[test] |
43 | fn self_hosting_parsing() { | 61 | fn self_hosting_parsing() { |
44 | use std::ffi::OsStr; | 62 | use std::ffi::OsStr; |
45 | let empty_vec = vec![]; | ||
46 | let dir = project_dir().join("crates"); | 63 | let dir = project_dir().join("crates"); |
47 | let mut count = 0; | 64 | let mut count = 0; |
48 | for entry in walkdir::WalkDir::new(dir) | 65 | for entry in walkdir::WalkDir::new(dir) |
49 | .into_iter() | 66 | .into_iter() |
50 | .filter_entry(|entry| { | 67 | .filter_entry(|entry| { |
51 | !entry | 68 | !entry.path().components().any(|component| { |
52 | .path() | 69 | // Get all files which are not in the crates/ra_syntax/tests/data folder |
53 | .components() | 70 | component == Component::Normal(OsStr::new("data")) |
54 | // TODO: this more neatly | 71 | }) |
55 | .any(|component| { | ||
56 | // Get all files which are not in the crates/ra_syntax/tests/data folder | ||
57 | component == Component::Normal(OsStr::new("data")) | ||
58 | }) | ||
59 | }) | 72 | }) |
60 | .map(|e| e.unwrap()) | 73 | .map(|e| e.unwrap()) |
61 | .filter(|entry| { | 74 | .filter(|entry| { |
@@ -68,7 +81,8 @@ fn self_hosting_parsing() { | |||
68 | let node = SourceFileNode::parse(&text); | 81 | let node = SourceFileNode::parse(&text); |
69 | let errors = node.errors(); | 82 | let errors = node.errors(); |
70 | assert_eq!( | 83 | assert_eq!( |
71 | errors, empty_vec, | 84 | &*errors, |
85 | &[], | ||
72 | "There should be no errors in the file {:?}", | 86 | "There should be no errors in the file {:?}", |
73 | entry | 87 | entry |
74 | ); | 88 | ); |
@@ -95,18 +109,18 @@ fn read_text(path: &Path) -> String { | |||
95 | .replace("\r\n", "\n") | 109 | .replace("\r\n", "\n") |
96 | } | 110 | } |
97 | 111 | ||
98 | pub fn dir_tests<F>(paths: &[&str], f: F) | 112 | fn dir_tests<F>(paths: &[&str], f: F) |
99 | where | 113 | where |
100 | F: Fn(&str) -> String, | 114 | F: Fn(&str, &Path) -> String, |
101 | { | 115 | { |
102 | for (path, input_code) in collect_tests(paths) { | 116 | for (path, input_code) in collect_tests(paths) { |
103 | let parse_tree = f(&input_code); | 117 | let parse_tree = f(&input_code, &path); |
104 | let path = path.with_extension("txt"); | 118 | let path = path.with_extension("txt"); |
105 | if !path.exists() { | 119 | if !path.exists() { |
106 | println!("\nfile: {}", path.display()); | 120 | println!("\nfile: {}", path.display()); |
107 | println!("No .txt file with expected result, creating...\n"); | 121 | println!("No .txt file with expected result, creating...\n"); |
108 | println!("{}\n{}", input_code, parse_tree); | 122 | println!("{}\n{}", input_code, parse_tree); |
109 | fs::write(&path, parse_tree).unwrap(); | 123 | fs::write(&path, &parse_tree).unwrap(); |
110 | panic!("No expected result") | 124 | panic!("No expected result") |
111 | } | 125 | } |
112 | let expected = read_text(&path); | 126 | let expected = read_text(&path); |