Skip to content

Commit 04325ab

Browse files
committed
Add test
1 parent c2d461b commit 04325ab

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class TestSwitchExprStmtConsistency {
2+
3+
static int f() { return 0; }
4+
5+
public static void test(int x) {
6+
7+
// Test that getRuleExpression() and getRuleStatement() behave alike for switch expressions and statements using arrow rules.
8+
9+
switch(x) {
10+
case 1 -> f();
11+
case 2 -> f();
12+
default -> f();
13+
}
14+
15+
int result = switch(x) {
16+
case 1 -> f();
17+
case 2 -> f();
18+
default -> f();
19+
};
20+
21+
}
22+
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
exprs
2+
| TestSwitchExpr.java:9:13:9:41 | case ... | TestSwitchExpr.java:9:43:9:46 | null |
3+
| TestSwitchExpr.java:10:13:10:22 | default | TestSwitchExpr.java:10:24:10:25 | x1 |
4+
| TestSwitchExprStmtConsistency.java:10:7:10:15 | case ... | TestSwitchExprStmtConsistency.java:10:17:10:19 | f(...) |
5+
| TestSwitchExprStmtConsistency.java:11:7:11:15 | case ... | TestSwitchExprStmtConsistency.java:11:17:11:19 | f(...) |
6+
| TestSwitchExprStmtConsistency.java:12:7:12:16 | default | TestSwitchExprStmtConsistency.java:12:18:12:20 | f(...) |
7+
| TestSwitchExprStmtConsistency.java:16:7:16:15 | case ... | TestSwitchExprStmtConsistency.java:16:17:16:19 | f(...) |
8+
| TestSwitchExprStmtConsistency.java:17:7:17:15 | case ... | TestSwitchExprStmtConsistency.java:17:17:17:19 | f(...) |
9+
| TestSwitchExprStmtConsistency.java:18:7:18:16 | default | TestSwitchExprStmtConsistency.java:18:18:18:20 | f(...) |
10+
stmts
11+
| TestSwitchExpr.java:13:13:13:28 | case ... | TestSwitchExpr.java:13:30:13:42 | { ... } |
12+
| TestSwitchExpr.java:14:13:14:22 | default | TestSwitchExpr.java:14:24:14:52 | throw ... |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
query predicate exprs(SwitchCase sc, Expr e) { e = sc.getRuleExpression() }
4+
5+
query predicate stmts(SwitchCase sc, Stmt s) { s = sc.getRuleStatement() }

0 commit comments

Comments
 (0)