Rust: Add a test for StmtList.

This commit is contained in:
Geoffrey White
2025-09-24 16:32:03 +01:00
parent 9bdac9d1cf
commit 93a0198326
4 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "test"
version = "0.0.1"

View File

@@ -0,0 +1,9 @@
| StmtList.rs:4:19:9:1 | StmtList | 2 | hasTailExpr | 0:let ... = 1, 1:let ... = 2, 2:... + ... |
| StmtList.rs:11:18:15:1 | StmtList | 2 | | 0:let ... = 1, 1:let ... = 2 |
| StmtList.rs:17:19:20:1 | StmtList | 0 | hasTailExpr | |
| StmtList.rs:22:18:25:1 | StmtList | 1 | | 0:ExprStmt |
| StmtList.rs:27:18:29:1 | StmtList | 0 | | |
| StmtList.rs:31:18:34:1 | StmtList | 0 | | |
| StmtList.rs:36:29:43:1 | StmtList | 0 | hasTailExpr | |
| StmtList.rs:38:10:40:2 | StmtList | 0 | hasTailExpr | |
| StmtList.rs:40:9:42:2 | StmtList | 0 | hasTailExpr | |

View File

@@ -0,0 +1,13 @@
import rust
import TestUtils
from StmtList sl, string tail
where
toBeTested(sl) and
if sl.hasTailExpr() then tail = "hasTailExpr" else tail = ""
select sl, sl.getNumberOfStatements(), tail,
concat(int i, AstNode n |
n = sl.getStmtOrExpr(i)
|
i.toString() + ":" + n.toString(), ", " order by i
)

View File

@@ -0,0 +1,43 @@
// --- tests ---
fn test1() -> i32 {
// two statements + tail expression
let a = 1;
let b = 2;
a + b
}
fn test2() -> () {
// two statements only
let a = 1;
let b = 2;
}
fn test3() -> i32 {
// tail expression only
1 + 2
}
fn test4() -> () {
// one statement only
1 + 2;
}
fn test5() -> () {
// neither
}
fn test6() -> () {
// neither
;
}
fn test7(cond: bool) -> i32 {
// nested blocks
if cond {
1
} else {
2
}
}