aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorDJMcNab <[email protected]>2018-12-20 10:50:40 +0000
committerDJMcNab <[email protected]>2018-12-20 13:33:00 +0000
commite2a7e9451881d3b9d1eba7336c657d56558f812e (patch)
tree471a6d5d816c447444460ef2251078010838e43c /crates/ra_syntax
parent346456f59ff5eaa653cf8a4b7e0c6672ef1f0566 (diff)
Ensure that the parser tests pass or fail correctly
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/tests/test.rs34
1 files changed, 26 insertions, 8 deletions
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs
index c17b6ffa6..539c4435b 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]
18fn lexer_tests() { 18fn 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]
26fn parser_tests() { 26fn parser_tests() {
27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { 27 dir_tests(&["parser/inline", "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"], |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,7 +60,6 @@ fn parser_fuzz_tests() {
42#[test] 60#[test]
43fn self_hosting_parsing() { 61fn 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)
@@ -68,7 +85,8 @@ fn self_hosting_parsing() {
68 let node = SourceFileNode::parse(&text); 85 let node = SourceFileNode::parse(&text);
69 let errors = node.errors(); 86 let errors = node.errors();
70 assert_eq!( 87 assert_eq!(
71 errors, empty_vec, 88 &*errors,
89 &[],
72 "There should be no errors in the file {:?}", 90 "There should be no errors in the file {:?}",
73 entry 91 entry
74 ); 92 );
@@ -95,12 +113,12 @@ fn read_text(path: &Path) -> String {
95 .replace("\r\n", "\n") 113 .replace("\r\n", "\n")
96} 114}
97 115
98pub fn dir_tests<F>(paths: &[&str], f: F) 116fn dir_tests<F>(paths: &[&str], f: F)
99where 117where
100 F: Fn(&str) -> String, 118 F: Fn(&str, &Path) -> String,
101{ 119{
102 for (path, input_code) in collect_tests(paths) { 120 for (path, input_code) in collect_tests(paths) {
103 let parse_tree = f(&input_code); 121 let parse_tree = f(&input_code, &path);
104 let path = path.with_extension("txt"); 122 let path = path.with_extension("txt");
105 if !path.exists() { 123 if !path.exists() {
106 println!("\nfile: {}", path.display()); 124 println!("\nfile: {}", path.display());