aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/tests/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/tests/test.rs')
-rw-r--r--crates/ra_syntax/tests/test.rs36
1 files changed, 27 insertions, 9 deletions
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs
index c17b6ffa6..14ad836b5 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/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,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,18 +113,18 @@ 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());
107 println!("No .txt file with expected result, creating...\n"); 125 println!("No .txt file with expected result, creating...\n");
108 println!("{}\n{}", input_code, parse_tree); 126 println!("{}\n{}", input_code, parse_tree);
109 fs::write(&path, parse_tree).unwrap(); 127 fs::write(&path, &parse_tree).unwrap();
110 panic!("No expected result") 128 panic!("No expected result")
111 } 129 }
112 let expected = read_text(&path); 130 let expected = read_text(&path);