Skip to content

Commit 93a0198

Browse files
committed
Rust: Add a test for StmtList.
1 parent 9bdac9d commit 93a0198

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

rust/ql/test/library-tests/elements/stmtlist/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| StmtList.rs:4:19:9:1 | StmtList | 2 | hasTailExpr | 0:let ... = 1, 1:let ... = 2, 2:... + ... |
2+
| StmtList.rs:11:18:15:1 | StmtList | 2 | | 0:let ... = 1, 1:let ... = 2 |
3+
| StmtList.rs:17:19:20:1 | StmtList | 0 | hasTailExpr | |
4+
| StmtList.rs:22:18:25:1 | StmtList | 1 | | 0:ExprStmt |
5+
| StmtList.rs:27:18:29:1 | StmtList | 0 | | |
6+
| StmtList.rs:31:18:34:1 | StmtList | 0 | | |
7+
| StmtList.rs:36:29:43:1 | StmtList | 0 | hasTailExpr | |
8+
| StmtList.rs:38:10:40:2 | StmtList | 0 | hasTailExpr | |
9+
| StmtList.rs:40:9:42:2 | StmtList | 0 | hasTailExpr | |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import rust
2+
import TestUtils
3+
4+
from StmtList sl, string tail
5+
where
6+
toBeTested(sl) and
7+
if sl.hasTailExpr() then tail = "hasTailExpr" else tail = ""
8+
select sl, sl.getNumberOfStatements(), tail,
9+
concat(int i, AstNode n |
10+
n = sl.getStmtOrExpr(i)
11+
|
12+
i.toString() + ":" + n.toString(), ", " order by i
13+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
// --- tests ---
3+
4+
fn test1() -> i32 {
5+
// two statements + tail expression
6+
let a = 1;
7+
let b = 2;
8+
a + b
9+
}
10+
11+
fn test2() -> () {
12+
// two statements only
13+
let a = 1;
14+
let b = 2;
15+
}
16+
17+
fn test3() -> i32 {
18+
// tail expression only
19+
1 + 2
20+
}
21+
22+
fn test4() -> () {
23+
// one statement only
24+
1 + 2;
25+
}
26+
27+
fn test5() -> () {
28+
// neither
29+
}
30+
31+
fn test6() -> () {
32+
// neither
33+
;
34+
}
35+
36+
fn test7(cond: bool) -> i32 {
37+
// nested blocks
38+
if cond {
39+
1
40+
} else {
41+
2
42+
}
43+
}

0 commit comments

Comments
 (0)