mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Rust: Add a test for StmtList.
This commit is contained in:
7
rust/ql/test/library-tests/elements/stmtlist/Cargo.lock
generated
Normal file
7
rust/ql/test/library-tests/elements/stmtlist/Cargo.lock
generated
Normal 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"
|
||||
@@ -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 | |
|
||||
13
rust/ql/test/library-tests/elements/stmtlist/StmtList.ql
Normal file
13
rust/ql/test/library-tests/elements/stmtlist/StmtList.ql
Normal 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
|
||||
)
|
||||
43
rust/ql/test/library-tests/elements/stmtlist/StmtList.rs
Normal file
43
rust/ql/test/library-tests/elements/stmtlist/StmtList.rs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user