aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/tests.rs')
-rw-r--r--crates/ra_syntax/src/tests.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/tests.rs b/crates/ra_syntax/src/tests.rs
index aee57db62..959967b79 100644
--- a/crates/ra_syntax/src/tests.rs
+++ b/crates/ra_syntax/src/tests.rs
@@ -55,6 +55,51 @@ fn parser_tests() {
55} 55}
56 56
57#[test] 57#[test]
58fn expr_parser_tests() {
59 fragment_parser_dir_test(
60 &["parser/fragments/expr/ok"],
61 &["parser/fragments/expr/err"],
62 crate::ast::Expr::parse,
63 );
64}
65
66#[test]
67fn path_parser_tests() {
68 fragment_parser_dir_test(
69 &["parser/fragments/path/ok"],
70 &["parser/fragments/path/err"],
71 crate::ast::Path::parse,
72 );
73}
74
75#[test]
76fn pattern_parser_tests() {
77 fragment_parser_dir_test(
78 &["parser/fragments/pattern/ok"],
79 &["parser/fragments/pattern/err"],
80 crate::ast::Pat::parse,
81 );
82}
83
84#[test]
85fn item_parser_tests() {
86 fragment_parser_dir_test(
87 &["parser/fragments/item/ok"],
88 &["parser/fragments/item/err"],
89 crate::ast::ModuleItem::parse,
90 );
91}
92
93#[test]
94fn type_parser_tests() {
95 fragment_parser_dir_test(
96 &["parser/fragments/type/ok"],
97 &["parser/fragments/type/err"],
98 crate::ast::TypeRef::parse,
99 );
100}
101
102#[test]
58fn parser_fuzz_tests() { 103fn parser_fuzz_tests() {
59 for (_, text) in collect_rust_files(&test_data_dir(), &["parser/fuzz-failures"]) { 104 for (_, text) in collect_rust_files(&test_data_dir(), &["parser/fuzz-failures"]) {
60 fuzz::check_parser(&text) 105 fuzz::check_parser(&text)
@@ -134,3 +179,24 @@ fn dump_tokens_and_errors(tokens: &[Token], errors: &[SyntaxError], text: &str)
134 } 179 }
135 acc 180 acc
136} 181}
182
183fn fragment_parser_dir_test<T, F>(ok_paths: &[&str], err_paths: &[&str], f: F)
184where
185 T: crate::AstNode,
186 F: Fn(&str) -> Result<T, ()>,
187{
188 dir_tests(&test_data_dir(), ok_paths, "rast", |text, path| {
189 if let Ok(node) = f(text) {
190 format!("{:#?}", crate::ast::AstNode::syntax(&node))
191 } else {
192 panic!("Failed to parse '{:?}'", path);
193 }
194 });
195 dir_tests(&test_data_dir(), err_paths, "rast", |text, path| {
196 if let Ok(_) = f(text) {
197 panic!("'{:?}' successfully parsed when it should have errored", path);
198 } else {
199 "ERROR\n".to_owned()
200 }
201 });
202}