Skip to content

Commit 8d0575c

Browse files
committed
C#: Add test case and expected output.
1 parent 4231ffc commit 8d0575c

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
public class C
4+
{
5+
public void M(int a)
6+
{
7+
var s = "hello world";
8+
var sub1 = s[1..a];
9+
var sub2 = s[..2];
10+
var sub3 = s[3..];
11+
var sub4 = s[..^4];
12+
13+
Span<int> sp = null;
14+
var slice1 = sp[5..a];
15+
var slice2 = sp[..6];
16+
var slice3 = sp[7..];
17+
var slice4 = sp[..^8];
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
methodCalls
2+
| Slice.cs:8:20:8:26 | call to method Substring | Substring(int, int) | 0 | 1 |
3+
| Slice.cs:8:20:8:26 | call to method Substring | Substring(int, int) | 1 | access to parameter a - 1 |
4+
| Slice.cs:9:20:9:25 | call to method Substring | Substring(int, int) | 0 | 0 |
5+
| Slice.cs:9:20:9:25 | call to method Substring | Substring(int, int) | 1 | 2 |
6+
| Slice.cs:10:20:10:25 | call to method Substring | Substring(int, int) | 0 | 3 |
7+
| Slice.cs:10:20:10:25 | call to method Substring | Substring(int, int) | 1 | access to property Length - 3 |
8+
| Slice.cs:11:20:11:26 | call to method Substring | Substring(int, int) | 0 | 0 |
9+
| Slice.cs:11:20:11:26 | call to method Substring | Substring(int, int) | 1 | access to property Length - 4 |
10+
| Slice.cs:14:22:14:29 | call to method Slice | Slice(int, int) | 0 | 5 |
11+
| Slice.cs:14:22:14:29 | call to method Slice | Slice(int, int) | 1 | access to parameter a - 5 |
12+
| Slice.cs:15:22:15:28 | call to method Slice | Slice(int, int) | 0 | 0 |
13+
| Slice.cs:15:22:15:28 | call to method Slice | Slice(int, int) | 1 | 6 |
14+
| Slice.cs:16:22:16:28 | call to method Slice | Slice(int, int) | 0 | 7 |
15+
| Slice.cs:16:22:16:28 | call to method Slice | Slice(int, int) | 1 | access to property Length - 7 |
16+
| Slice.cs:17:22:17:29 | call to method Slice | Slice(int, int) | 0 | 0 |
17+
| Slice.cs:17:22:17:29 | call to method Slice | Slice(int, int) | 1 | access to property Length - 8 |
18+
propertyCalls
19+
| Slice.cs:10:20:10:25 | access to property Length | Slice.cs:10:20:10:20 | access to local variable s |
20+
| Slice.cs:11:20:11:26 | access to property Length | Slice.cs:11:20:11:20 | access to local variable s |
21+
| Slice.cs:16:22:16:28 | access to property Length | Slice.cs:16:22:16:23 | access to local variable sp |
22+
| Slice.cs:17:22:17:29 | access to property Length | Slice.cs:17:22:17:23 | access to local variable sp |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import csharp
2+
3+
private string printExpr(Expr e) {
4+
e =
5+
any(SubExpr sub |
6+
result = sub.getLeftOperand().toString() + " - " + sub.getRightOperand().toString()
7+
)
8+
or
9+
not e instanceof SubExpr and
10+
result = e.toString()
11+
}
12+
13+
query predicate methodCalls(MethodCall mc, string m, int i, string arg) {
14+
m = mc.getTarget().toStringWithTypes() and
15+
arg = printExpr(mc.getArgument(i))
16+
}
17+
18+
query predicate propertyCalls(PropertyCall p, Expr qualifier) { qualifier = p.getQualifier() }

0 commit comments

Comments
 (0)