Skip to content

Commit f64e86f

Browse files
committed
Rust: Add a library test for Operations.
1 parent 93f8cea commit f64e86f

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

rust/ql/test/library-tests/operations/Operations.expected

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import rust
2+
import utils.test.InlineExpectationsTest
3+
4+
string describe(Expr op) {
5+
op instanceof PrefixExpr and result = "PrefixExpr"
6+
or
7+
op instanceof BinaryExpr and result = "BinaryExpr"
8+
or
9+
op instanceof AssignmentOperation and result = "AssignmentOperation"
10+
or
11+
op instanceof LogicalOperation and result = "LogicalOperation"
12+
or
13+
op instanceof RefExpr and result = "RefExpr"
14+
}
15+
16+
module OperationsTest implements TestSig {
17+
string getARelevantTag() { result = describe(_) }
18+
19+
predicate hasActualResult(Location location, string element, string tag, string value) {
20+
exists(Expr op |
21+
location = op.getLocation() and
22+
location.getFile().getBaseName() != "" and
23+
element = op.toString() and
24+
tag = describe(op) and
25+
value = ""
26+
)
27+
}
28+
}
29+
30+
import MakeTest<OperationsTest>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
// --- tests ---
3+
4+
fn test_operations(
5+
y: i32, a: bool, b: bool,
6+
ptr: &i32, res: Result<i32, ()>) -> Result<(), ()>
7+
{
8+
let mut x: i32;
9+
10+
// simple assignment
11+
x = y; // $ AssignmentOperation BinaryExpr
12+
13+
// comparison operations
14+
x == y; // $ BinaryExpr
15+
x != y; // $ BinaryExpr
16+
x < y; // $ BinaryExpr
17+
x <= y; // $ BinaryExpr
18+
x > y; // $ BinaryExpr
19+
x >= y; // $ BinaryExpr
20+
21+
// arithmetic operations
22+
x + y; // $ BinaryExpr
23+
x - y; // $ BinaryExpr
24+
x * y; // $ BinaryExpr
25+
x / y; // $ BinaryExpr
26+
x % y; // $ BinaryExpr
27+
x += y; // $ AssignmentOperation BinaryExpr
28+
x -= y; // $ AssignmentOperation BinaryExpr
29+
x *= y; // $ AssignmentOperation BinaryExpr
30+
x /= y; // $ AssignmentOperation BinaryExpr
31+
x %= y; // $ AssignmentOperation BinaryExpr
32+
-x; // $ PrefixExpr
33+
34+
// logical operations
35+
a && b; // $ BinaryExpr LogicalOperation
36+
a || b; // $ BinaryExpr LogicalOperation
37+
!a; // $ PrefixExpr LogicalOperation
38+
39+
// bitwise operations
40+
x & y; // $ BinaryExpr
41+
x | y; // $ BinaryExpr
42+
x ^ y; // $ BinaryExpr
43+
x << y; // $ BinaryExpr
44+
x >> y; // $ BinaryExpr
45+
x &= y; // $ AssignmentOperation BinaryExpr
46+
x |= y; // $ AssignmentOperation BinaryExpr
47+
x ^= y; // $ AssignmentOperation BinaryExpr
48+
x <<= y; // $ AssignmentOperation BinaryExpr
49+
x >>= y; // $ AssignmentOperation BinaryExpr
50+
51+
// miscellaneous expressions that might be operations
52+
*ptr; // $ PrefixExpr
53+
&x; // $ RefExpr
54+
res?;
55+
56+
return Ok(());
57+
}

0 commit comments

Comments
 (0)