aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-07 09:32:29 +0000
committerAleksey Kladov <[email protected]>2018-01-07 09:32:29 +0000
commitefcfaae34ac7a54e858aad82e6503a7c69d6c550 (patch)
tree611b74d833d3e852f0fe271db3faebd4e865c097
parentf797c81155e9b7371b24801efac3fcbd236fc9ab (diff)
Tests for partial parse
-rw-r--r--src/parser/event_parser/grammar.rs7
-rw-r--r--tests/data/parser/err/0000_struct_field_missing_comma.rs4
-rw-r--r--tests/data/parser/err/0000_struct_field_missing_comma.txt20
-rw-r--r--tests/data/parser/ok/0000_empty.rs (renamed from tests/data/parser/0000_empty.rs)0
-rw-r--r--tests/data/parser/ok/0000_empty.txt (renamed from tests/data/parser/0000_empty.txt)0
-rw-r--r--tests/data/parser/ok/0001_struct_item.rs (renamed from tests/data/parser/0001_struct_item.rs)0
-rw-r--r--tests/data/parser/ok/0001_struct_item.txt (renamed from tests/data/parser/0001_struct_item.txt)0
-rw-r--r--tests/data/parser/ok/0002_struct_item_field.rs (renamed from tests/data/parser/0002_struct_item_field.rs)0
-rw-r--r--tests/data/parser/ok/0002_struct_item_field.txt (renamed from tests/data/parser/0002_struct_item_field.txt)0
-rw-r--r--tests/parser.rs15
10 files changed, 42 insertions, 4 deletions
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs
index 7425526ef..79ef8b31c 100644
--- a/src/parser/event_parser/grammar.rs
+++ b/src/parser/event_parser/grammar.rs
@@ -74,7 +74,12 @@ fn many<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) {
74fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { 74fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) {
75 many(p, |p| { 75 many(p, |p| {
76 f(p); 76 f(p);
77 p.is_eof() || p.expect(COMMA) 77 if p.is_eof() {
78 false
79 } else {
80 p.expect(COMMA);
81 true
82 }
78 }) 83 })
79} 84}
80 85
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 000000000..fe5030d89
--- /dev/null
+++ b/tests/data/parser/err/0000_struct_field_missing_comma.rs
@@ -0,0 +1,4 @@
1struct S {
2 a: u32
3 b: u32
4} \ 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 000000000..e2e99bb63
--- /dev/null
+++ b/tests/data/parser/err/0000_struct_field_missing_comma.txt
@@ -0,0 +1,20 @@
1FILE@[0; 34)
2 STRUCT_ITEM@[0; 34) err: `expected COMMA`
3 STRUCT_KW@[0; 6)
4 WHITESPACE@[6; 7)
5 IDENT@[7; 8)
6 WHITESPACE@[8; 9)
7 L_CURLY@[9; 10)
8 STRUCT_FIELD@[10; 26)
9 WHITESPACE@[10; 15)
10 IDENT@[15; 16)
11 COLON@[16; 17)
12 WHITESPACE@[17; 18)
13 IDENT@[18; 21)
14 WHITESPACE@[21; 26)
15 STRUCT_FIELD@[26; 33)
16 IDENT@[26; 27)
17 COLON@[27; 28)
18 WHITESPACE@[28; 29)
19 IDENT@[29; 32)
20 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
index e69de29bb..e69de29bb 100644
--- a/tests/data/parser/0000_empty.rs
+++ b/tests/data/parser/ok/0000_empty.rs
diff --git a/tests/data/parser/0000_empty.txt b/tests/data/parser/ok/0000_empty.txt
index 54be3e7bc..54be3e7bc 100644
--- a/tests/data/parser/0000_empty.txt
+++ b/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
index d3a8c1d23..d3a8c1d23 100644
--- a/tests/data/parser/0001_struct_item.rs
+++ b/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
index f599e9d2c..f599e9d2c 100644
--- a/tests/data/parser/0001_struct_item.txt
+++ b/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
index cc3866d25..cc3866d25 100644
--- a/tests/data/parser/0002_struct_item_field.rs
+++ b/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
index 87ab3f7a9..87ab3f7a9 100644
--- a/tests/data/parser/0002_struct_item_field.txt
+++ b/tests/data/parser/ok/0002_struct_item_field.txt
diff --git a/tests/parser.rs b/tests/parser.rs
index 7fde365c9..206da2a64 100644
--- a/tests/parser.rs
+++ b/tests/parser.rs
@@ -21,9 +21,8 @@ fn parser_test_dir() -> PathBuf {
21 PathBuf::from(dir).join("tests/data/parser") 21 PathBuf::from(dir).join("tests/data/parser")
22} 22}
23 23
24fn parser_test_cases() -> Vec<PathBuf> { 24fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
25 let mut acc = Vec::new(); 25 let mut acc = Vec::new();
26 let dir = parser_test_dir();
27 for file in read_dir(&dir).unwrap() { 26 for file in read_dir(&dir).unwrap() {
28 let file = file.unwrap(); 27 let file = file.unwrap();
29 let path = file.path(); 28 let path = file.path();
@@ -35,6 +34,13 @@ fn parser_test_cases() -> Vec<PathBuf> {
35 acc 34 acc
36} 35}
37 36
37fn parser_test_cases() -> Vec<PathBuf> {
38 let mut acc = Vec::new();
39 acc.extend(test_from_dir(&parser_test_dir().join("ok")));
40 acc.extend(test_from_dir(&parser_test_dir().join("err")));
41 acc
42}
43
38fn parser_test_case(path: &Path) { 44fn parser_test_case(path: &Path) {
39 let actual = { 45 let actual = {
40 let text = file::get_text(path).unwrap(); 46 let text = file::get_text(path).unwrap();
@@ -42,7 +48,10 @@ fn parser_test_case(path: &Path) {
42 let file = parse(text, &tokens); 48 let file = parse(text, &tokens);
43 dump_tree(&file) 49 dump_tree(&file)
44 }; 50 };
45 let expected = file::get_text(&path.with_extension("txt")).unwrap(); 51 let expected = path.with_extension("txt");
52 let expected = file::get_text(&expected).expect(
53 &format!("Can't read {}", expected.display())
54 );
46 let expected = expected.as_str(); 55 let expected = expected.as_str();
47 let actual = actual.as_str(); 56 let actual = actual.as_str();
48 if expected == actual { 57 if expected == actual {