Skip to content

Commit 7c02b6a

Browse files
committed
QL: Add tests.
1 parent 161461e commit 7c02b6a

3 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| test.qll:4:2:7:6 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
2+
| test.qll:29:2:32:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
3+
| test.qll:43:2:46:11 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
4+
| test.qll:62:4:65:11 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
5+
| test.qll:67:4:70:10 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
6+
| test.qll:72:4:75:10 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
7+
| test.qll:89:2:92:8 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
8+
| test.qll:126:2:126:37 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/style/UseSetLiteral.ql
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import ql
2+
3+
predicate test1(int a) {
4+
a = 1 or // BAD
5+
a = 2 or
6+
a = 3 or
7+
a = 4
8+
}
9+
10+
predicate test2(int a) {
11+
a = [1, 2, 3, 4] // GOOD
12+
}
13+
14+
predicate test3(int a) {
15+
a = 1 and // GOOD (for the purposes of this query)
16+
a = 2 and
17+
a = 3 and
18+
a = 4
19+
}
20+
21+
bindingset[a] predicate test4(int a) {
22+
a < 1 or // GOOD (for the purposes of this query)
23+
a = 2 or
24+
a >= 3 or
25+
a > 4
26+
}
27+
28+
predicate test5() {
29+
test1(1) or // BAD
30+
test1(2) or
31+
test1(3) or
32+
test1(4)
33+
}
34+
35+
predicate test6() {
36+
test1(1) or // GOOD
37+
test2(2) or
38+
test3(3) or
39+
test4(4)
40+
}
41+
42+
int test7() {
43+
1 = result or // BAD
44+
2 = result or
45+
3 = result or
46+
4 = result
47+
}
48+
49+
predicate test8() {
50+
test7() = 1 or // BAD [NOT DETECTED]
51+
test7() = 2 or
52+
test7() = 3 or
53+
test7() = 4
54+
}
55+
56+
class MyTest8Class extends int
57+
{
58+
string s;
59+
60+
MyTest8Class() {
61+
(
62+
this = 1 or // BAD
63+
this = 2 or
64+
this = 3 or
65+
this = 4
66+
) and (
67+
s = "1" or // BAD
68+
s = "2" or
69+
s = "3" or
70+
s = "4"
71+
) and exists(float f |
72+
f = 1.0 or // BAD
73+
f = 1.5 or
74+
f = 2.0 or
75+
f = 2.5
76+
)
77+
}
78+
79+
predicate is(int x) {
80+
x = this
81+
}
82+
83+
int get() {
84+
result = this
85+
}
86+
}
87+
88+
predicate test9(MyTest8Class c) {
89+
c.is(1) or // BAD
90+
c.is(2) or
91+
c.is(3) or
92+
c.is(4)
93+
}
94+
95+
predicate test10(MyTest8Class c) {
96+
c.get() = 1 or // BAD [NOT DETECTED]
97+
c.get() = 2 or
98+
c.get() = 3 or
99+
c.get() = 4
100+
}
101+
102+
bindingset[a, b, c, d] predicate test11(int a, int b, int c, int d) {
103+
a = 1 or // GOOD
104+
b = 2 or
105+
c = 3 or
106+
d = 4
107+
}
108+
109+
bindingset[a, b] predicate test12(int a, int b) {
110+
a = 1 or // BAD [NOT DETECTED]
111+
a = 2 or
112+
a = 3 or
113+
a = 4 or
114+
b = 0
115+
}
116+
117+
predicate test13(int a, int b) {
118+
(a = 1 and b = 1) or // GOOD
119+
(a = 2 and b = 4) or
120+
(a = 3 and b = 9) or
121+
(a = 4 and b = 16)
122+
}
123+
124+
from int a
125+
where
126+
a = 1 or ((a = 2 or a = 3) or a = 4) // BAD
127+
select a

0 commit comments

Comments
 (0)