Unnamed repository; edit this file 'description' to name the repository.
minor: more focusted tests
Aleksey Kladov 2021-09-25
parent a6f17f7 · commit 1567bbb
-rw-r--r--crates/parser/src/grammar/expressions.rs35
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rast158
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rs10
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rast28
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rast30
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rs1
7 files changed, 107 insertions, 156 deletions
diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs
index a627ca70d9..9f3e11819f 100644
--- a/crates/parser/src/grammar/expressions.rs
+++ b/crates/parser/src/grammar/expressions.rs
@@ -115,6 +115,10 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) {
// }
match with_semi {
+ StmtWithSemi::No => (),
+ StmtWithSemi::Optional => {
+ p.eat(T![;]);
+ }
StmtWithSemi::Yes => {
if blocklike.is_block() {
p.eat(T![;]);
@@ -122,48 +126,35 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) {
p.expect(T![;]);
}
}
- StmtWithSemi::No => {}
- StmtWithSemi::Optional => {
- if p.at(T![;]) {
- p.eat(T![;]);
- }
- }
}
m.complete(p, EXPR_STMT);
}
// test let_stmt
- // fn foo() {
- // let a;
- // let b: i32;
- // let c = 92;
- // let d: i32 = 92;
- // let e: !;
- // let _: ! = {};
- // let f = #[attr]||{};
- // }
+ // fn f() { let x: i32 = 92; }
fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) {
- assert!(p.at(T![let]));
p.bump(T![let]);
patterns::pattern(p);
if p.at(T![:]) {
+ // test let_stmt_ascription
+ // fn f() { let x: i32; }
types::ascription(p);
}
if p.eat(T![=]) {
+ // test let_stmt_init
+ // fn f() { let x = 92; }
expressions::expr_with_attrs(p);
}
match with_semi {
+ StmtWithSemi::No => (),
+ StmtWithSemi::Optional => {
+ p.eat(T![;]);
+ }
StmtWithSemi::Yes => {
p.expect(T![;]);
}
- StmtWithSemi::No => {}
- StmtWithSemi::Optional => {
- if p.at(T![;]) {
- p.eat(T![;]);
- }
- }
}
m.complete(p, LET_STMT);
}
diff --git a/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rast b/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rast
index c3a79836aa..af3b11376b 100644
--- a/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rast
+++ b/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rast
@@ -1,127 +1,35 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rs b/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rs
index fa8ee49a23..8003999fd0 100644
--- a/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rs
+++ b/crates/syntax/test_data/parser/inline/ok/0130_let_stmt.rs
@@ -1,9 +1 @@
-fn foo() {
- let a;
- let b: i32;
- let c = 92;
- let d: i32 = 92;
- let e: !;
- let _: ! = {};
- let f = #[attr]||{};
-}
+fn f() { let x: i32 = 92; }
diff --git a/crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rast b/crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rast
new file mode 100644
index 0000000000..cc5d72ff74
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rast
@@ -0,0 +1,28 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rs b/crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rs
new file mode 100644
index 0000000000..232c0db411
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0193_let_stmt_init.rs
@@ -0,0 +1 @@
+fn f() { let x = 92; }
diff --git a/crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rast b/crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rast
new file mode 100644
index 0000000000..41acb0dd98
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rast
@@ -0,0 +1,30 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rs b/crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rs
new file mode 100644
index 0000000000..a94161dffa
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0194_let_stmt_ascription.rs
@@ -0,0 +1 @@
+fn f() { let x: i32; }