mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Tests for partial parse
This commit is contained in:
parent
f797c81155
commit
efcfaae34a
10 changed files with 42 additions and 4 deletions
|
@ -74,7 +74,12 @@ fn many<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) {
|
|||
fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) {
|
||||
many(p, |p| {
|
||||
f(p);
|
||||
p.is_eof() || p.expect(COMMA)
|
||||
if p.is_eof() {
|
||||
false
|
||||
} else {
|
||||
p.expect(COMMA);
|
||||
true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
4
tests/data/parser/err/0000_struct_field_missing_comma.rs
Normal file
4
tests/data/parser/err/0000_struct_field_missing_comma.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
struct S {
|
||||
a: u32
|
||||
b: u32
|
||||
}
|
20
tests/data/parser/err/0000_struct_field_missing_comma.txt
Normal file
20
tests/data/parser/err/0000_struct_field_missing_comma.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
FILE@[0; 34)
|
||||
STRUCT_ITEM@[0; 34) err: `expected COMMA`
|
||||
STRUCT_KW@[0; 6)
|
||||
WHITESPACE@[6; 7)
|
||||
IDENT@[7; 8)
|
||||
WHITESPACE@[8; 9)
|
||||
L_CURLY@[9; 10)
|
||||
STRUCT_FIELD@[10; 26)
|
||||
WHITESPACE@[10; 15)
|
||||
IDENT@[15; 16)
|
||||
COLON@[16; 17)
|
||||
WHITESPACE@[17; 18)
|
||||
IDENT@[18; 21)
|
||||
WHITESPACE@[21; 26)
|
||||
STRUCT_FIELD@[26; 33)
|
||||
IDENT@[26; 27)
|
||||
COLON@[27; 28)
|
||||
WHITESPACE@[28; 29)
|
||||
IDENT@[29; 32)
|
||||
WHITESPACE@[32;
|
|
@ -21,9 +21,8 @@ fn parser_test_dir() -> PathBuf {
|
|||
PathBuf::from(dir).join("tests/data/parser")
|
||||
}
|
||||
|
||||
fn parser_test_cases() -> Vec<PathBuf> {
|
||||
fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
|
||||
let mut acc = Vec::new();
|
||||
let dir = parser_test_dir();
|
||||
for file in read_dir(&dir).unwrap() {
|
||||
let file = file.unwrap();
|
||||
let path = file.path();
|
||||
|
@ -35,6 +34,13 @@ fn parser_test_cases() -> Vec<PathBuf> {
|
|||
acc
|
||||
}
|
||||
|
||||
fn parser_test_cases() -> Vec<PathBuf> {
|
||||
let mut acc = Vec::new();
|
||||
acc.extend(test_from_dir(&parser_test_dir().join("ok")));
|
||||
acc.extend(test_from_dir(&parser_test_dir().join("err")));
|
||||
acc
|
||||
}
|
||||
|
||||
fn parser_test_case(path: &Path) {
|
||||
let actual = {
|
||||
let text = file::get_text(path).unwrap();
|
||||
|
@ -42,7 +48,10 @@ fn parser_test_case(path: &Path) {
|
|||
let file = parse(text, &tokens);
|
||||
dump_tree(&file)
|
||||
};
|
||||
let expected = file::get_text(&path.with_extension("txt")).unwrap();
|
||||
let expected = path.with_extension("txt");
|
||||
let expected = file::get_text(&expected).expect(
|
||||
&format!("Can't read {}", expected.display())
|
||||
);
|
||||
let expected = expected.as_str();
|
||||
let actual = actual.as_str();
|
||||
if expected == actual {
|
||||
|
|
Loading…
Reference in a new issue