-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest.ql
More file actions
37 lines (32 loc) · 1.17 KB
/
test.ql
File metadata and controls
37 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cpp
import utils.test.InlineExpectationsTest
import semmle.code.cpp.dataflow.new.DataFlow::DataFlow
bindingset[s]
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
string formatNumberOfNodesForExpr(Expr e) {
exists(int n | n = strictcount(Node node | node.asExpr() = e) | n > 1 and result = ": " + n)
}
module AsExprTest implements TestSig {
string getARelevantTag() { result = ["asExpr", "numberOfNodes"] }
predicate hasActualResult(Location location, string element, string tag, string value) {
exists(Node n, Expr e, string exprString |
e = n.asExpr() and
location = e.getLocation() and
element = n.toString() and
exprString = e.toString()
|
tag = "asExpr" and
(
// If the `toString` on the node is identical to the `toString` of the
// expression then we don't show it in the expected output.
if exprString = element
then value = quote(exprString)
else value = quote(exprString + "(" + element + ")")
)
or
tag = "numberOfNodes" and
value = quote(exprString + formatNumberOfNodesForExpr(e))
)
}
}
import MakeTest<AsExprTest>