diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index 7425526ef6..79ef8b31c1 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs @@ -74,7 +74,12 @@ fn many bool>(p: &mut Parser, f: F) { fn comma_list 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 + } }) } diff --git a/tests/data/parser/err/0000_struct_field_missing_comma.rs b/tests/data/parser/err/0000_struct_field_missing_comma.rs new file mode 100644 index 0000000000..fe5030d893 --- /dev/null +++ b/tests/data/parser/err/0000_struct_field_missing_comma.rs @@ -0,0 +1,4 @@ +struct S { + a: u32 + b: u32 +} \ No newline at end of file diff --git a/tests/data/parser/err/0000_struct_field_missing_comma.txt b/tests/data/parser/err/0000_struct_field_missing_comma.txt new file mode 100644 index 0000000000..e2e99bb635 --- /dev/null +++ b/tests/data/parser/err/0000_struct_field_missing_comma.txt @@ -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; \ No newline at end of file diff --git a/tests/data/parser/0000_empty.rs b/tests/data/parser/ok/0000_empty.rs similarity index 100% rename from tests/data/parser/0000_empty.rs rename to tests/data/parser/ok/0000_empty.rs diff --git a/tests/data/parser/0000_empty.txt b/tests/data/parser/ok/0000_empty.txt similarity index 100% rename from tests/data/parser/0000_empty.txt rename to tests/data/parser/ok/0000_empty.txt diff --git a/tests/data/parser/0001_struct_item.rs b/tests/data/parser/ok/0001_struct_item.rs similarity index 100% rename from tests/data/parser/0001_struct_item.rs rename to tests/data/parser/ok/0001_struct_item.rs diff --git a/tests/data/parser/0001_struct_item.txt b/tests/data/parser/ok/0001_struct_item.txt similarity index 100% rename from tests/data/parser/0001_struct_item.txt rename to tests/data/parser/ok/0001_struct_item.txt diff --git a/tests/data/parser/0002_struct_item_field.rs b/tests/data/parser/ok/0002_struct_item_field.rs similarity index 100% rename from tests/data/parser/0002_struct_item_field.rs rename to tests/data/parser/ok/0002_struct_item_field.rs diff --git a/tests/data/parser/0002_struct_item_field.txt b/tests/data/parser/ok/0002_struct_item_field.txt similarity index 100% rename from tests/data/parser/0002_struct_item_field.txt rename to tests/data/parser/ok/0002_struct_item_field.txt diff --git a/tests/parser.rs b/tests/parser.rs index 7fde365c97..206da2a647 100644 --- a/tests/parser.rs +++ b/tests/parser.rs @@ -21,9 +21,8 @@ fn parser_test_dir() -> PathBuf { PathBuf::from(dir).join("tests/data/parser") } -fn parser_test_cases() -> Vec { +fn test_from_dir(dir: &Path) -> Vec { 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 { acc } +fn parser_test_cases() -> Vec { + 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 {