Skip to content

Commit b360ea9

Browse files
committed
internal: move inline parser tests to parser crate
1 parent 0f74758 commit b360ea9

File tree

636 files changed

+11161
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

636 files changed

+11161
-101
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/parser/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ limit = { path = "../limit", version = "0.0.0" }
1616

1717
[dev-dependencies]
1818
expect-test = "1.2"
19+
sourcegen = { path = "../sourcegen" }
20+

crates/parser/src/grammar/expressions.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,6 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
463463
// x.0.bar;
464464
// x.0();
465465
// }
466-
467-
// test_err bad_tuple_index_expr
468-
// fn foo() {
469-
// x.0.;
470-
// x.1i32;
471-
// x.0x01;
472-
// }
473466
fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
474467
assert!(p.at(T![.]));
475468
let m = lhs.precede(p);

crates/parser/src/tests.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod sourcegen_inline_tests;
2+
13
use std::{
24
fmt::Write,
35
fs,
@@ -9,15 +11,15 @@ use expect_test::expect_file;
911
use crate::LexedStr;
1012

1113
#[test]
12-
fn lex_valid() {
14+
fn lex_ok() {
1315
for case in TestCase::list("lexer/ok") {
1416
let actual = lex(&case.text);
1517
expect_file![case.txt].assert_eq(&actual)
1618
}
1719
}
1820

1921
#[test]
20-
fn lex_invalid() {
22+
fn lex_err() {
2123
for case in TestCase::list("lexer/err") {
2224
let actual = lex(&case.text);
2325
expect_file![case.txt].assert_eq(&actual)
@@ -40,7 +42,7 @@ fn lex(text: &str) -> String {
4042
}
4143

4244
#[test]
43-
fn parse_valid() {
45+
fn parse_ok() {
4446
for case in TestCase::list("parser/ok") {
4547
let (actual, errors) = parse(&case.text);
4648
assert!(!errors, "errors in an OK file {}:\n{}", case.rs.display(), actual);
@@ -49,14 +51,32 @@ fn parse_valid() {
4951
}
5052

5153
#[test]
52-
fn parse_invalid() {
54+
fn parse_inline_ok() {
55+
for case in TestCase::list("parser/inline/ok") {
56+
let (actual, errors) = parse(&case.text);
57+
assert!(!errors, "errors in an OK file {}:\n{}", case.rs.display(), actual);
58+
expect_file![case.txt].assert_eq(&actual);
59+
}
60+
}
61+
62+
#[test]
63+
fn parse_err() {
5364
for case in TestCase::list("parser/err") {
5465
let (actual, errors) = parse(&case.text);
5566
assert!(errors, "no errors in an ERR file {}:\n{}", case.rs.display(), actual);
5667
expect_file![case.txt].assert_eq(&actual)
5768
}
5869
}
5970

71+
#[test]
72+
fn parse_inline_err() {
73+
for case in TestCase::list("parser/inline/err") {
74+
let (actual, errors) = parse(&case.text);
75+
assert!(errors, "no errors in an ERR file {}:\n{}", case.rs.display(), actual);
76+
expect_file![case.txt].assert_eq(&actual)
77+
}
78+
}
79+
6080
fn parse(text: &str) -> (String, bool) {
6181
let lexed = LexedStr::new(text);
6282
let input = lexed.to_input();

crates/syntax/src/tests/sourcegen_tests.rs renamed to crates/parser/src/tests/sourcegen_inline_tests.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
//! them into tests.
33
44
use std::{
5+
collections::HashMap,
56
fs, iter,
67
path::{Path, PathBuf},
78
};
89

9-
use rustc_hash::FxHashMap;
10-
1110
#[test]
1211
fn sourcegen_parser_tests() {
1312
let grammar_dir = sourcegen::project_root().join(Path::new("crates/parser/src/grammar"));
1413
let tests = tests_from_dir(&grammar_dir);
1514

16-
install_tests(&tests.ok, "crates/syntax/test_data/parser/inline/ok");
17-
install_tests(&tests.err, "crates/syntax/test_data/parser/inline/err");
15+
install_tests(&tests.ok, "crates/parser/test_data/parser/inline/ok");
16+
install_tests(&tests.err, "crates/parser/test_data/parser/inline/err");
1817

19-
fn install_tests(tests: &FxHashMap<String, Test>, into: &str) {
18+
fn install_tests(tests: &HashMap<String, Test>, into: &str) {
2019
let tests_dir = sourcegen::project_root().join(into);
2120
if !tests_dir.is_dir() {
2221
fs::create_dir_all(&tests_dir).unwrap();
@@ -51,8 +50,8 @@ struct Test {
5150

5251
#[derive(Default, Debug)]
5352
struct Tests {
54-
ok: FxHashMap<String, Test>,
55-
err: FxHashMap<String, Test>,
53+
ok: HashMap<String, Test>,
54+
err: HashMap<String, Test>,
5655
}
5756

5857
fn collect_tests(s: &str) -> Vec<Test> {
@@ -102,8 +101,8 @@ fn tests_from_dir(dir: &Path) -> Tests {
102101
}
103102
}
104103

105-
fn existing_tests(dir: &Path, ok: bool) -> FxHashMap<String, (PathBuf, Test)> {
106-
let mut res = FxHashMap::default();
104+
fn existing_tests(dir: &Path, ok: bool) -> HashMap<String, (PathBuf, Test)> {
105+
let mut res = HashMap::default();
107106
for file in fs::read_dir(dir).unwrap() {
108107
let file = file.unwrap();
109108
let path = file.path();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
SOURCE_FILE
2+
TYPE_ALIAS
3+
TYPE_KW "type"
4+
WHITESPACE " "
5+
NAME
6+
IDENT "T"
7+
WHITESPACE " "
8+
EQ "="
9+
WHITESPACE " "
10+
SLICE_TYPE
11+
L_BRACK "["
12+
TUPLE_TYPE
13+
L_PAREN "("
14+
R_PAREN ")"
15+
WHITESPACE " "
16+
ERROR
17+
INT_NUMBER "92"
18+
ERROR
19+
R_BRACK "]"
20+
ERROR
21+
SEMICOLON ";"
22+
WHITESPACE "\n"
23+
error 12: expected `;` or `]`
24+
error 12: expected SEMICOLON
25+
error 13: expected an item
26+
error 15: expected an item
27+
error 16: expected an item

0 commit comments

Comments
 (0)