diff options
author | DJMcNab <[email protected]> | 2018-12-19 21:19:32 +0000 |
---|---|---|
committer | DJMcNab <[email protected]> | 2018-12-19 21:19:32 +0000 |
commit | a3b842fb8b7b5503b1c4fc49355edd4f2fe0d28d (patch) | |
tree | 8a6044df2e589d1dab26f9551b13360fac0e974f | |
parent | db677414304bec41a5eae57eea4eb0b546619415 (diff) |
Add tests and only traverse in the crates directory
7 files changed, 185 insertions, 94 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index 5f5a3077d..4f8c46ab3 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs | |||
@@ -73,6 +73,10 @@ pub(crate) fn block(p: &mut Parser) { | |||
73 | // for _ in () {} | 73 | // for _ in () {} |
74 | // {} | 74 | // {} |
75 | // {} | 75 | // {} |
76 | // macro_rules! test { | ||
77 | // () => {} | ||
78 | // } | ||
79 | // test!{} | ||
76 | // } | 80 | // } |
77 | if is_blocklike { | 81 | if is_blocklike { |
78 | p.eat(SEMI); | 82 | p.eat(SEMI); |
@@ -168,13 +172,13 @@ fn current_op(p: &Parser) -> (u8, Op) { | |||
168 | // Parses expression with binding power of at least bp. | 172 | // Parses expression with binding power of at least bp. |
169 | fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike { | 173 | fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike { |
170 | let mut lhs = match lhs(p, r) { | 174 | let mut lhs = match lhs(p, r) { |
171 | Some((lhs, macro_blocklike)) => { | 175 | Some((lhs, blocklike)) => { |
172 | // test stmt_bin_expr_ambiguity | 176 | // test stmt_bin_expr_ambiguity |
173 | // fn foo() { | 177 | // fn foo() { |
174 | // let _ = {1} & 2; | 178 | // let _ = {1} & 2; |
175 | // {1} &2; | 179 | // {1} &2; |
176 | // } | 180 | // } |
177 | if r.prefer_stmt && macro_blocklike.is_block() { | 181 | if r.prefer_stmt && blocklike.is_block() { |
178 | return BlockLike::Block; | 182 | return BlockLike::Block; |
179 | } | 183 | } |
180 | lhs | 184 | lhs |
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index a976799e7..cd7d62aff 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs | |||
@@ -353,6 +353,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) { | |||
353 | // fn foo() { | 353 | // fn foo() { |
354 | // match () { | 354 | // match () { |
355 | // _ => (), | 355 | // _ => (), |
356 | // _ if Test>{field: 0} => (), | ||
356 | // X | Y if Z => (), | 357 | // X | Y if Z => (), |
357 | // | X | Y if Z => (), | 358 | // | X | Y if Z => (), |
358 | // | X => (), | 359 | // | X => (), |
diff --git a/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.rs b/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.rs index b23a12500..3380fa4ca 100644 --- a/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.rs +++ b/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | fn foo() { | 1 | fn foo() { |
2 | match () { | 2 | match () { |
3 | _ => (), | 3 | _ => (), |
4 | _ if Test>{field: 0} => (), | ||
4 | X | Y if Z => (), | 5 | X | Y if Z => (), |
5 | | X | Y if Z => (), | 6 | | X | Y if Z => (), |
6 | | X => (), | 7 | | X => (), |
diff --git a/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.txt b/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.txt index 044faec04..e5647765c 100644 --- a/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.txt +++ b/crates/ra_syntax/tests/data/parser/inline/0069_match_arm.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 125) | 1 | SOURCE_FILE@[0; 161) |
2 | FN_DEF@[0; 124) | 2 | FN_DEF@[0; 160) |
3 | FN_KW@[0; 2) | 3 | FN_KW@[0; 2) |
4 | WHITESPACE@[2; 3) | 4 | WHITESPACE@[2; 3) |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,18 +8,18 @@ SOURCE_FILE@[0; 125) | |||
8 | L_PAREN@[6; 7) | 8 | L_PAREN@[6; 7) |
9 | R_PAREN@[7; 8) | 9 | R_PAREN@[7; 8) |
10 | WHITESPACE@[8; 9) | 10 | WHITESPACE@[8; 9) |
11 | BLOCK@[9; 124) | 11 | BLOCK@[9; 160) |
12 | L_CURLY@[9; 10) | 12 | L_CURLY@[9; 10) |
13 | WHITESPACE@[10; 15) | 13 | WHITESPACE@[10; 15) |
14 | EXPR_STMT@[15; 122) | 14 | EXPR_STMT@[15; 158) |
15 | MATCH_EXPR@[15; 121) | 15 | MATCH_EXPR@[15; 157) |
16 | MATCH_KW@[15; 20) | 16 | MATCH_KW@[15; 20) |
17 | WHITESPACE@[20; 21) | 17 | WHITESPACE@[20; 21) |
18 | TUPLE_EXPR@[21; 23) | 18 | TUPLE_EXPR@[21; 23) |
19 | L_PAREN@[21; 22) | 19 | L_PAREN@[21; 22) |
20 | R_PAREN@[22; 23) | 20 | R_PAREN@[22; 23) |
21 | WHITESPACE@[23; 24) | 21 | WHITESPACE@[23; 24) |
22 | MATCH_ARM_LIST@[24; 121) | 22 | MATCH_ARM_LIST@[24; 157) |
23 | L_CURLY@[24; 25) | 23 | L_CURLY@[24; 25) |
24 | WHITESPACE@[25; 34) | 24 | WHITESPACE@[25; 34) |
25 | MATCH_ARM@[34; 41) | 25 | MATCH_ARM@[34; 41) |
@@ -33,76 +33,116 @@ SOURCE_FILE@[0; 125) | |||
33 | R_PAREN@[40; 41) | 33 | R_PAREN@[40; 41) |
34 | COMMA@[41; 42) | 34 | COMMA@[41; 42) |
35 | WHITESPACE@[42; 51) | 35 | WHITESPACE@[42; 51) |
36 | MATCH_ARM@[51; 67) | 36 | MATCH_ARM@[51; 77) |
37 | BIND_PAT@[51; 52) | 37 | PLACEHOLDER_PAT@[51; 52) |
38 | NAME@[51; 52) | 38 | UNDERSCORE@[51; 52) |
39 | IDENT@[51; 52) "X" | ||
40 | WHITESPACE@[52; 53) | 39 | WHITESPACE@[52; 53) |
41 | PIPE@[53; 54) | 40 | IF_KW@[53; 55) |
42 | WHITESPACE@[54; 55) | 41 | WHITESPACE@[55; 56) |
43 | BIND_PAT@[55; 56) | 42 | BIN_EXPR@[56; 71) |
44 | NAME@[55; 56) | 43 | PATH_EXPR@[56; 60) |
45 | IDENT@[55; 56) "Y" | 44 | PATH@[56; 60) |
46 | WHITESPACE@[56; 57) | 45 | PATH_SEGMENT@[56; 60) |
47 | IF_KW@[57; 59) | 46 | NAME_REF@[56; 60) |
48 | WHITESPACE@[59; 60) | 47 | IDENT@[56; 60) "Test" |
49 | PATH_EXPR@[60; 61) | 48 | R_ANGLE@[60; 61) |
50 | PATH@[60; 61) | 49 | BLOCK_EXPR@[61; 71) |
51 | PATH_SEGMENT@[60; 61) | 50 | BLOCK@[61; 71) |
52 | NAME_REF@[60; 61) | 51 | L_CURLY@[61; 62) |
53 | IDENT@[60; 61) "Z" | 52 | EXPR_STMT@[62; 67) |
54 | WHITESPACE@[61; 62) | 53 | PATH_EXPR@[62; 67) |
55 | FAT_ARROW@[62; 64) | 54 | PATH@[62; 67) |
56 | WHITESPACE@[64; 65) | 55 | PATH_SEGMENT@[62; 67) |
57 | TUPLE_EXPR@[65; 67) | 56 | NAME_REF@[62; 67) |
58 | L_PAREN@[65; 66) | 57 | IDENT@[62; 67) "field" |
59 | R_PAREN@[66; 67) | 58 | err: `expected SEMI` |
60 | COMMA@[67; 68) | 59 | err: `expected expression` |
61 | WHITESPACE@[68; 77) | 60 | EXPR_STMT@[67; 68) |
62 | MATCH_ARM@[77; 95) | 61 | ERROR@[67; 68) |
63 | PIPE@[77; 78) | 62 | COLON@[67; 68) |
64 | WHITESPACE@[78; 79) | 63 | err: `expected SEMI` |
65 | BIND_PAT@[79; 80) | 64 | WHITESPACE@[68; 69) |
66 | NAME@[79; 80) | 65 | LITERAL@[69; 70) |
67 | IDENT@[79; 80) "X" | 66 | INT_NUMBER@[69; 70) "0" |
68 | WHITESPACE@[80; 81) | 67 | R_CURLY@[70; 71) |
69 | PIPE@[81; 82) | 68 | WHITESPACE@[71; 72) |
70 | WHITESPACE@[82; 83) | 69 | FAT_ARROW@[72; 74) |
71 | BIND_PAT@[83; 84) | 70 | WHITESPACE@[74; 75) |
72 | NAME@[83; 84) | 71 | TUPLE_EXPR@[75; 77) |
73 | IDENT@[83; 84) "Y" | 72 | L_PAREN@[75; 76) |
74 | WHITESPACE@[84; 85) | 73 | R_PAREN@[76; 77) |
75 | IF_KW@[85; 87) | 74 | COMMA@[77; 78) |
76 | WHITESPACE@[87; 88) | 75 | WHITESPACE@[78; 87) |
77 | PATH_EXPR@[88; 89) | 76 | MATCH_ARM@[87; 103) |
78 | PATH@[88; 89) | 77 | BIND_PAT@[87; 88) |
79 | PATH_SEGMENT@[88; 89) | 78 | NAME@[87; 88) |
80 | NAME_REF@[88; 89) | 79 | IDENT@[87; 88) "X" |
81 | IDENT@[88; 89) "Z" | 80 | WHITESPACE@[88; 89) |
82 | WHITESPACE@[89; 90) | 81 | PIPE@[89; 90) |
83 | FAT_ARROW@[90; 92) | 82 | WHITESPACE@[90; 91) |
83 | BIND_PAT@[91; 92) | ||
84 | NAME@[91; 92) | ||
85 | IDENT@[91; 92) "Y" | ||
84 | WHITESPACE@[92; 93) | 86 | WHITESPACE@[92; 93) |
85 | TUPLE_EXPR@[93; 95) | 87 | IF_KW@[93; 95) |
86 | L_PAREN@[93; 94) | 88 | WHITESPACE@[95; 96) |
87 | R_PAREN@[94; 95) | 89 | PATH_EXPR@[96; 97) |
88 | COMMA@[95; 96) | 90 | PATH@[96; 97) |
89 | WHITESPACE@[96; 105) | 91 | PATH_SEGMENT@[96; 97) |
90 | MATCH_ARM@[105; 114) | 92 | NAME_REF@[96; 97) |
91 | PIPE@[105; 106) | 93 | IDENT@[96; 97) "Z" |
92 | WHITESPACE@[106; 107) | 94 | WHITESPACE@[97; 98) |
93 | BIND_PAT@[107; 108) | 95 | FAT_ARROW@[98; 100) |
94 | NAME@[107; 108) | 96 | WHITESPACE@[100; 101) |
95 | IDENT@[107; 108) "X" | 97 | TUPLE_EXPR@[101; 103) |
96 | WHITESPACE@[108; 109) | 98 | L_PAREN@[101; 102) |
97 | FAT_ARROW@[109; 111) | 99 | R_PAREN@[102; 103) |
98 | WHITESPACE@[111; 112) | 100 | COMMA@[103; 104) |
99 | TUPLE_EXPR@[112; 114) | 101 | WHITESPACE@[104; 113) |
100 | L_PAREN@[112; 113) | 102 | MATCH_ARM@[113; 131) |
101 | R_PAREN@[113; 114) | 103 | PIPE@[113; 114) |
102 | COMMA@[114; 115) | 104 | WHITESPACE@[114; 115) |
103 | WHITESPACE@[115; 120) | 105 | BIND_PAT@[115; 116) |
104 | R_CURLY@[120; 121) | 106 | NAME@[115; 116) |
105 | SEMI@[121; 122) | 107 | IDENT@[115; 116) "X" |
106 | WHITESPACE@[122; 123) | 108 | WHITESPACE@[116; 117) |
107 | R_CURLY@[123; 124) | 109 | PIPE@[117; 118) |
108 | WHITESPACE@[124; 125) | 110 | WHITESPACE@[118; 119) |
111 | BIND_PAT@[119; 120) | ||
112 | NAME@[119; 120) | ||
113 | IDENT@[119; 120) "Y" | ||
114 | WHITESPACE@[120; 121) | ||
115 | IF_KW@[121; 123) | ||
116 | WHITESPACE@[123; 124) | ||
117 | PATH_EXPR@[124; 125) | ||
118 | PATH@[124; 125) | ||
119 | PATH_SEGMENT@[124; 125) | ||
120 | NAME_REF@[124; 125) | ||
121 | IDENT@[124; 125) "Z" | ||
122 | WHITESPACE@[125; 126) | ||
123 | FAT_ARROW@[126; 128) | ||
124 | WHITESPACE@[128; 129) | ||
125 | TUPLE_EXPR@[129; 131) | ||
126 | L_PAREN@[129; 130) | ||
127 | R_PAREN@[130; 131) | ||
128 | COMMA@[131; 132) | ||
129 | WHITESPACE@[132; 141) | ||
130 | MATCH_ARM@[141; 150) | ||
131 | PIPE@[141; 142) | ||
132 | WHITESPACE@[142; 143) | ||
133 | BIND_PAT@[143; 144) | ||
134 | NAME@[143; 144) | ||
135 | IDENT@[143; 144) "X" | ||
136 | WHITESPACE@[144; 145) | ||
137 | FAT_ARROW@[145; 147) | ||
138 | WHITESPACE@[147; 148) | ||
139 | TUPLE_EXPR@[148; 150) | ||
140 | L_PAREN@[148; 149) | ||
141 | R_PAREN@[149; 150) | ||
142 | COMMA@[150; 151) | ||
143 | WHITESPACE@[151; 156) | ||
144 | R_CURLY@[156; 157) | ||
145 | SEMI@[157; 158) | ||
146 | WHITESPACE@[158; 159) | ||
147 | R_CURLY@[159; 160) | ||
148 | WHITESPACE@[160; 161) | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.rs b/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.rs index d769da43d..4919665cb 100644 --- a/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.rs +++ b/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.rs | |||
@@ -6,4 +6,8 @@ fn foo() { | |||
6 | for _ in () {} | 6 | for _ in () {} |
7 | {} | 7 | {} |
8 | {} | 8 | {} |
9 | macro_rules! test { | ||
10 | () => {} | ||
11 | } | ||
12 | test!{} | ||
9 | } | 13 | } |
diff --git a/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.txt b/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.txt index 69f0a48ce..63b230091 100644 --- a/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.txt +++ b/crates/ra_syntax/tests/data/parser/inline/0086_no_semi_after_block.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 107) | 1 | SOURCE_FILE@[0; 167) |
2 | FN_DEF@[0; 106) | 2 | FN_DEF@[0; 166) |
3 | FN_KW@[0; 2) | 3 | FN_KW@[0; 2) |
4 | WHITESPACE@[2; 3) | 4 | WHITESPACE@[2; 3) |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,7 +8,7 @@ SOURCE_FILE@[0; 107) | |||
8 | L_PAREN@[6; 7) | 8 | L_PAREN@[6; 7) |
9 | R_PAREN@[7; 8) | 9 | R_PAREN@[7; 8) |
10 | WHITESPACE@[8; 9) | 10 | WHITESPACE@[8; 9) |
11 | BLOCK@[9; 106) | 11 | BLOCK@[9; 166) |
12 | L_CURLY@[9; 10) | 12 | L_CURLY@[9; 10) |
13 | WHITESPACE@[10; 15) | 13 | WHITESPACE@[10; 15) |
14 | EXPR_STMT@[15; 25) | 14 | EXPR_STMT@[15; 25) |
@@ -78,10 +78,46 @@ SOURCE_FILE@[0; 107) | |||
78 | L_CURLY@[95; 96) | 78 | L_CURLY@[95; 96) |
79 | R_CURLY@[96; 97) | 79 | R_CURLY@[96; 97) |
80 | WHITESPACE@[97; 102) | 80 | WHITESPACE@[97; 102) |
81 | BLOCK_EXPR@[102; 104) | 81 | EXPR_STMT@[102; 104) |
82 | BLOCK@[102; 104) | 82 | BLOCK_EXPR@[102; 104) |
83 | L_CURLY@[102; 103) | 83 | BLOCK@[102; 104) |
84 | R_CURLY@[103; 104) | 84 | L_CURLY@[102; 103) |
85 | WHITESPACE@[104; 105) | 85 | R_CURLY@[103; 104) |
86 | R_CURLY@[105; 106) | 86 | WHITESPACE@[104; 109) |
87 | WHITESPACE@[106; 107) | 87 | EXPR_STMT@[109; 152) |
88 | MACRO_CALL@[109; 152) | ||
89 | PATH@[109; 120) | ||
90 | PATH_SEGMENT@[109; 120) | ||
91 | NAME_REF@[109; 120) | ||
92 | IDENT@[109; 120) "macro_rules" | ||
93 | EXCL@[120; 121) | ||
94 | WHITESPACE@[121; 122) | ||
95 | IDENT@[122; 126) "test" | ||
96 | WHITESPACE@[126; 127) | ||
97 | TOKEN_TREE@[127; 152) | ||
98 | L_CURLY@[127; 128) | ||
99 | WHITESPACE@[128; 138) | ||
100 | TOKEN_TREE@[138; 140) | ||
101 | L_PAREN@[138; 139) | ||
102 | R_PAREN@[139; 140) | ||
103 | WHITESPACE@[140; 141) | ||
104 | FAT_ARROW@[141; 143) | ||
105 | WHITESPACE@[143; 144) | ||
106 | TOKEN_TREE@[144; 146) | ||
107 | L_CURLY@[144; 145) | ||
108 | R_CURLY@[145; 146) | ||
109 | WHITESPACE@[146; 151) | ||
110 | R_CURLY@[151; 152) | ||
111 | WHITESPACE@[152; 157) | ||
112 | MACRO_CALL@[157; 164) | ||
113 | PATH@[157; 161) | ||
114 | PATH_SEGMENT@[157; 161) | ||
115 | NAME_REF@[157; 161) | ||
116 | IDENT@[157; 161) "test" | ||
117 | EXCL@[161; 162) | ||
118 | TOKEN_TREE@[162; 164) | ||
119 | L_CURLY@[162; 163) | ||
120 | R_CURLY@[163; 164) | ||
121 | WHITESPACE@[164; 165) | ||
122 | R_CURLY@[165; 166) | ||
123 | WHITESPACE@[166; 167) | ||
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index a07855768..c17b6ffa6 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs | |||
@@ -41,8 +41,10 @@ fn parser_fuzz_tests() { | |||
41 | /// TODO: Use this as a benchmark | 41 | /// TODO: Use this as a benchmark |
42 | #[test] | 42 | #[test] |
43 | fn self_hosting_parsing() { | 43 | fn self_hosting_parsing() { |
44 | use std::ffi::OsStr; | ||
44 | let empty_vec = vec![]; | 45 | let empty_vec = vec![]; |
45 | let dir = project_dir(); | 46 | let dir = project_dir().join("crates"); |
47 | let mut count = 0; | ||
46 | for entry in walkdir::WalkDir::new(dir) | 48 | for entry in walkdir::WalkDir::new(dir) |
47 | .into_iter() | 49 | .into_iter() |
48 | .filter_entry(|entry| { | 50 | .filter_entry(|entry| { |
@@ -52,17 +54,16 @@ fn self_hosting_parsing() { | |||
52 | // TODO: this more neatly | 54 | // TODO: this more neatly |
53 | .any(|component| { | 55 | .any(|component| { |
54 | // Get all files which are not in the crates/ra_syntax/tests/data folder | 56 | // Get all files which are not in the crates/ra_syntax/tests/data folder |
55 | (component == Component::Normal(std::ffi::OsStr::new("data")) | 57 | component == Component::Normal(OsStr::new("data")) |
56 | // or the .git folder | ||
57 | || component == Component::Normal(std::ffi::OsStr::new(".git"))) | ||
58 | }) | 58 | }) |
59 | }) | 59 | }) |
60 | .map(|e| e.unwrap()) | 60 | .map(|e| e.unwrap()) |
61 | .filter(|entry| { | 61 | .filter(|entry| { |
62 | // Get all `.rs ` files | 62 | // Get all `.rs ` files |
63 | !entry.path().is_dir() && (entry.path().extension() == Some(std::ffi::OsStr::new("rs"))) | 63 | !entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs"))) |
64 | }) | 64 | }) |
65 | { | 65 | { |
66 | count += 1; | ||
66 | let text = read_text(entry.path()); | 67 | let text = read_text(entry.path()); |
67 | let node = SourceFileNode::parse(&text); | 68 | let node = SourceFileNode::parse(&text); |
68 | let errors = node.errors(); | 69 | let errors = node.errors(); |
@@ -72,6 +73,10 @@ fn self_hosting_parsing() { | |||
72 | entry | 73 | entry |
73 | ); | 74 | ); |
74 | } | 75 | } |
76 | assert!( | ||
77 | count > 30, | ||
78 | "self_hosting_parsing found too few files - is it running in the right directory?" | ||
79 | ) | ||
75 | } | 80 | } |
76 | /// Read file and normalize newlines. | 81 | /// Read file and normalize newlines. |
77 | /// | 82 | /// |