Skip to content

Commit 745ece6

Browse files
authored
Merge pull request #6613 from Marcono1234/marcono1234/literals-test-split
Java: Split literals tests
2 parents 70e41b1 + e3fed55 commit 745ece6

39 files changed

+652
-250
lines changed

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,15 @@ class CharacterLiteral extends Literal, @characterliteral {
719719
override string getAPrimaryQlClass() { result = "CharacterLiteral" }
720720
}
721721

722-
/** A string literal. For example, `"hello world"`. */
722+
/**
723+
* A string literal or text block (Java 15 feature). For example, `"hello world"`
724+
* or
725+
* ```java
726+
* """
727+
* Text with "quotes"
728+
* """
729+
* ```
730+
*/
723731
class StringLiteral extends Literal, @stringliteral {
724732
/**
725733
* Gets the literal string without the quotes.
@@ -734,6 +742,7 @@ class StringLiteral extends Literal, @stringliteral {
734742

735743
/** The null literal, written `null`. */
736744
class NullLiteral extends Literal, @nullliteral {
745+
// Override these predicates because the inherited ones have no result
737746
override string getLiteral() { result = "null" }
738747

739748
override string getValue() { result = "null" }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package booleanLiterals;
2+
3+
public class BooleanLiterals {
4+
boolean[] booleans = {
5+
true,
6+
false,
7+
// Using Unicode escapes (which are handled during pre-processing)
8+
\u0074\u0072\u0075\u0065, // true
9+
};
10+
11+
// The operation expression (e.g. `&&`) is not a literal
12+
boolean[] logicOperations = {
13+
true && true,
14+
false && false,
15+
true && false,
16+
true || true,
17+
false || false,
18+
true || false,
19+
};
20+
21+
Object[] nonBooleanLiterals = {
22+
"true",
23+
"false",
24+
1,
25+
0,
26+
Boolean.TRUE,
27+
Boolean.FALSE,
28+
};
29+
30+
boolean nonLiteral;
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| BooleanLiterals.java:5:3:5:6 | true | true | true |
2+
| BooleanLiterals.java:6:3:6:7 | false | false | false |
3+
| BooleanLiterals.java:8:8:8:26 | 4\\u0072\\u0075\\u0065 | true | true |
4+
| BooleanLiterals.java:13:3:13:6 | true | true | true |
5+
| BooleanLiterals.java:13:11:13:14 | true | true | true |
6+
| BooleanLiterals.java:14:3:14:7 | false | false | false |
7+
| BooleanLiterals.java:14:12:14:16 | false | false | false |
8+
| BooleanLiterals.java:15:3:15:6 | true | true | true |
9+
| BooleanLiterals.java:15:11:15:15 | false | false | false |
10+
| BooleanLiterals.java:16:3:16:6 | true | true | true |
11+
| BooleanLiterals.java:16:11:16:14 | true | true | true |
12+
| BooleanLiterals.java:17:3:17:7 | false | false | false |
13+
| BooleanLiterals.java:17:12:17:16 | false | false | false |
14+
| BooleanLiterals.java:18:3:18:6 | true | true | true |
15+
| BooleanLiterals.java:18:11:18:15 | false | false | false |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package charLiterals;
2+
3+
public class CharLiterals {
4+
char[] chars = {
5+
'a',
6+
'\u0061', // 'a'
7+
'\u0000',
8+
'\uFFFF',
9+
'\ufFfF',
10+
'\0',
11+
'\n',
12+
'"',
13+
'\\',
14+
'\'',
15+
'\123', // octal escape sequence for 'S'
16+
'\uD800', // high surrogate
17+
'\uDC00', // low surrogate
18+
// Using Unicode escapes (which are handled during pre-processing)
19+
'\u005C\u005C', // escaped backslash
20+
'\u005C\u0027', // escaped single quote
21+
\u0027a\u0027, // 'a'
22+
};
23+
24+
// + and - are not part of the literal
25+
int[] charsWithSign = {
26+
+'a',
27+
-'a',
28+
};
29+
30+
// The operation expression (e.g. `+`) is not a literal
31+
int[] numericOperations = {
32+
'a' + 'b',
33+
};
34+
35+
Object[] nonCharLiterals = {
36+
"a",
37+
"",
38+
"\uD800\uDC00", // surrogate pair
39+
0,
40+
Character.MIN_VALUE,
41+
};
42+
43+
char nonLiteral;
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| CharLiterals.java:5:3:5:5 | 'a' | a |
2+
| CharLiterals.java:6:3:6:10 | '\\u0061' | a |
3+
| CharLiterals.java:7:3:7:10 | '\\u0000' | \u0000 |
4+
| CharLiterals.java:8:3:8:10 | '\\uFFFF' | \uffff |
5+
| CharLiterals.java:9:3:9:10 | '\\ufFfF' | \uffff |
6+
| CharLiterals.java:10:3:10:6 | '\\0' | \u0000 |
7+
| CharLiterals.java:11:3:11:6 | '\\n' | \n |
8+
| CharLiterals.java:12:3:12:5 | '"' | " |
9+
| CharLiterals.java:13:3:13:6 | '\\\\' | \\ |
10+
| CharLiterals.java:14:3:14:6 | '\\'' | ' |
11+
| CharLiterals.java:15:3:15:8 | '\\123' | S |
12+
| CharLiterals.java:16:3:16:10 | '\\uD800' | \ufffd |
13+
| CharLiterals.java:17:3:17:10 | '\\uDC00' | \ufffd |
14+
| CharLiterals.java:19:3:19:16 | '\\u005C\\u005C' | \\ |
15+
| CharLiterals.java:20:3:20:16 | '\\u005C\\u0027' | ' |
16+
| CharLiterals.java:21:8:21:15 | 7a\\u0027 | a |
17+
| CharLiterals.java:26:4:26:6 | 'a' | a |
18+
| CharLiterals.java:27:4:27:6 | 'a' | a |
19+
| CharLiterals.java:32:3:32:5 | 'a' | a |
20+
| CharLiterals.java:32:9:32:11 | 'b' | b |
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package doubleLiterals;
2+
3+
public class DoubleLiterals {
4+
double[] doubles = {
5+
0.0,
6+
0d,
7+
0D,
8+
.0d,
9+
.0,
10+
0.,
11+
1.234567890123456789,
12+
1.55555555555555555555,
13+
// From the JLS
14+
1e1,
15+
1.7976931348623157E308,
16+
0x1.f_ffff_ffff_ffffP+1023,
17+
4.9e-324,
18+
0x0.0_0000_0000_0001P-1022,
19+
0x1.0P-1074,
20+
// Using Unicode escapes (which are handled during pre-processing)
21+
\u0030\u002E\u0030, // 0.0
22+
};
23+
24+
// + and - are not part of the literal
25+
double[] doublesWithSign = {
26+
+0.0,
27+
-0.0,
28+
+1.0,
29+
-1.0,
30+
+1.7976931348623157E308,
31+
-1.7976931348623157E308,
32+
};
33+
34+
// The operation expression (e.g. `+`) is not a literal
35+
double[] numericOperations = {
36+
0.0 + 0.0,
37+
0.0 / 0.0,
38+
};
39+
40+
Object[] nonDoubleLiterals = {
41+
"0",
42+
'0',
43+
0,
44+
0.0f,
45+
(double) 0.0f,
46+
Double.MIN_VALUE,
47+
};
48+
49+
double nonLiteral;
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
| DoubleLiterals.java:5:3:5:5 | 0.0 | 0.0 | 0.0 |
2+
| DoubleLiterals.java:6:3:6:4 | 0d | 0.0 | 0.0 |
3+
| DoubleLiterals.java:7:3:7:4 | 0D | 0.0 | 0.0 |
4+
| DoubleLiterals.java:8:3:8:5 | .0d | 0.0 | 0.0 |
5+
| DoubleLiterals.java:9:3:9:4 | .0 | 0.0 | 0.0 |
6+
| DoubleLiterals.java:10:3:10:4 | 0. | 0.0 | 0.0 |
7+
| DoubleLiterals.java:11:3:11:22 | 1.234567890123456789 | 1.2345678901234567 | 1.2345678901234567 |
8+
| DoubleLiterals.java:12:3:12:24 | 1.55555555555555555555 | 1.5555555555555556 | 1.5555555555555556 |
9+
| DoubleLiterals.java:14:3:14:5 | 1e1 | 10.0 | 10.0 |
10+
| DoubleLiterals.java:15:3:15:24 | 1.7976931348623157E308 | 1.7976931348623157E308 | 1.7976931348623157E308 |
11+
| DoubleLiterals.java:16:3:16:28 | 0x1.f_ffff_ffff_ffffP+1023 | 1.7976931348623157E308 | 1.7976931348623157E308 |
12+
| DoubleLiterals.java:17:3:17:10 | 4.9e-324 | 4.9E-324 | 4.9E-324 |
13+
| DoubleLiterals.java:18:3:18:28 | 0x0.0_0000_0000_0001P-1022 | 4.9E-324 | 4.9E-324 |
14+
| DoubleLiterals.java:19:3:19:13 | 0x1.0P-1074 | 4.9E-324 | 4.9E-324 |
15+
| DoubleLiterals.java:21:8:21:20 | 0\\u002E\\u0030 | 0.0 | 0.0 |
16+
| DoubleLiterals.java:26:4:26:6 | 0.0 | 0.0 | 0.0 |
17+
| DoubleLiterals.java:27:4:27:6 | 0.0 | 0.0 | 0.0 |
18+
| DoubleLiterals.java:28:4:28:6 | 1.0 | 1.0 | 1.0 |
19+
| DoubleLiterals.java:29:4:29:6 | 1.0 | 1.0 | 1.0 |
20+
| DoubleLiterals.java:30:4:30:25 | 1.7976931348623157E308 | 1.7976931348623157E308 | 1.7976931348623157E308 |
21+
| DoubleLiterals.java:31:4:31:25 | 1.7976931348623157E308 | 1.7976931348623157E308 | 1.7976931348623157E308 |
22+
| DoubleLiterals.java:36:3:36:5 | 0.0 | 0.0 | 0.0 |
23+
| DoubleLiterals.java:36:9:36:11 | 0.0 | 0.0 | 0.0 |
24+
| DoubleLiterals.java:37:3:37:5 | 0.0 | 0.0 | 0.0 |
25+
| DoubleLiterals.java:37:9:37:11 | 0.0 | 0.0 | 0.0 |

0 commit comments

Comments
 (0)