Skip to content

Commit c66673b

Browse files
committed
C#: Add test cases for raw string literals.
1 parent 409f5c9 commit c66673b

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

csharp/ql/test/library-tests/csharp11/Strings.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,28 @@ public string M1(int x)
1111
_ => "something else"
1212
}}.";
1313
}
14+
15+
public void M2()
16+
{
17+
// Raw string literal.
18+
var message1 = """
19+
This is my very long
20+
text message that spans
21+
accross multiple lines
22+
and is very useful.
23+
""";
24+
25+
// String interpolation using a raw string literal.
26+
var message2 = $"""
27+
The nested message
28+
is "{message1}" and everything
29+
spans multiple lines.
30+
""";
31+
32+
// String interpolation using a raw string literal that requires double curly braces.
33+
var message3 = $$"""
34+
Show no curly braces: {{message1}}
35+
Show matching set of curly braces: {{{message2}}}
36+
""";
37+
}
1438
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
interpolatedstrings
12
| Strings.cs:8:16:12:12 | $"..." | Strings.cs:8:18:8:32 | "This is my int " |
23
| Strings.cs:8:16:12:12 | $"..." | Strings.cs:8:34:12:9 | ... switch { ... } |
34
| Strings.cs:8:16:12:12 | $"..." | Strings.cs:12:11:12:11 | "." |
5+
| Strings.cs:26:24:30:11 | $"..." | Strings.cs:27:1:28:14 | "The nested message\n is \\"" |
6+
| Strings.cs:26:24:30:11 | $"..." | Strings.cs:28:16:28:23 | access to local variable message1 |
7+
| Strings.cs:26:24:30:11 | $"..." | Strings.cs:28:25:29:29 | "\\" and everything\nspans multiple lines." |
8+
| Strings.cs:33:24:36:11 | $"..." | Strings.cs:34:1:34:30 | "Show no curly braces: " |
9+
| Strings.cs:33:24:36:11 | $"..." | Strings.cs:34:33:34:40 | access to local variable message1 |
10+
| Strings.cs:33:24:36:11 | $"..." | Strings.cs:34:43:35:44 | "\nShow matching set of curly braces: {" |
11+
| Strings.cs:33:24:36:11 | $"..." | Strings.cs:35:47:35:54 | access to local variable message2 |
12+
| Strings.cs:33:24:36:11 | $"..." | Strings.cs:35:57:35:57 | "}" |
13+
stringliterals
14+
| Strings.cs:18:24:23:11 | "This is my very long\n text message that spans\n accross multiple lines\nand is very useful." |
15+
| Strings.cs:27:1:28:14 | "The nested message\n is \\"" |
16+
| Strings.cs:28:25:29:29 | "\\" and everything\nspans multiple lines." |
17+
| Strings.cs:34:1:34:30 | "Show no curly braces: " |
18+
| Strings.cs:34:43:35:44 | "\nShow matching set of curly braces: {" |
19+
| Strings.cs:35:57:35:57 | "}" |

csharp/ql/test/library-tests/csharp11/strings.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ query predicate interpolatedstrings(InterpolatedStringExpr se, Expr e) {
44
se.getFile().getStem() = "Strings" and
55
(e = se.getAText() or e = se.getAnInsert())
66
}
7+
8+
query predicate stringliterals(StringLiteral s) {
9+
s.getFile().getStem() = "Strings" and s.getEnclosingCallable().getName() = "M2"
10+
}

0 commit comments

Comments
 (0)