C#: Add more testcases and update expected output.

This commit is contained in:
Michael Nebel
2026-06-03 12:21:53 +02:00
parent edc1c150a0
commit 2f473572fa
3 changed files with 20 additions and 12 deletions

View File

@@ -2,18 +2,20 @@ using System;
public class C
{
public void M(int a)
public void M(int a, int b)
{
var s = "hello world";
var sub1 = s[1..a];
var sub2 = s[..2];
var sub3 = s[3..];
var sub4 = s[..^4];
var sub5 = s[a..^b];
Span<int> sp = null;
var slice1 = sp[5..a];
var slice2 = sp[..6];
var slice3 = sp[7..];
var slice4 = sp[..^8];
var slice5 = sp[a..^b];
}
}

View File

@@ -7,16 +7,22 @@ methodCalls
| Slice.cs:10:20:10:25 | call to method Substring | Substring(int, int) | 1 | access to property Length - 3 |
| Slice.cs:11:20:11:26 | call to method Substring | Substring(int, int) | 0 | 0 |
| Slice.cs:11:20:11:26 | call to method Substring | Substring(int, int) | 1 | access to property Length - 4 |
| Slice.cs:14:22:14:29 | call to method Slice | Slice(int, int) | 0 | 5 |
| Slice.cs:14:22:14:29 | call to method Slice | Slice(int, int) | 1 | access to parameter a - 5 |
| Slice.cs:15:22:15:28 | call to method Slice | Slice(int, int) | 0 | 0 |
| Slice.cs:15:22:15:28 | call to method Slice | Slice(int, int) | 1 | 6 |
| Slice.cs:16:22:16:28 | call to method Slice | Slice(int, int) | 0 | 7 |
| Slice.cs:16:22:16:28 | call to method Slice | Slice(int, int) | 1 | access to property Length - 7 |
| Slice.cs:17:22:17:29 | call to method Slice | Slice(int, int) | 0 | 0 |
| Slice.cs:17:22:17:29 | call to method Slice | Slice(int, int) | 1 | access to property Length - 8 |
| Slice.cs:12:20:12:27 | call to method Substring | Substring(int, int) | 0 | access to parameter a |
| Slice.cs:12:20:12:27 | call to method Substring | Substring(int, int) | 1 | access to property Length - access to parameter b - access to parameter a |
| Slice.cs:15:22:15:29 | call to method Slice | Slice(int, int) | 0 | 5 |
| Slice.cs:15:22:15:29 | call to method Slice | Slice(int, int) | 1 | access to parameter a - 5 |
| Slice.cs:16:22:16:28 | call to method Slice | Slice(int, int) | 0 | 0 |
| Slice.cs:16:22:16:28 | call to method Slice | Slice(int, int) | 1 | 6 |
| Slice.cs:17:22:17:28 | call to method Slice | Slice(int, int) | 0 | 7 |
| Slice.cs:17:22:17:28 | call to method Slice | Slice(int, int) | 1 | access to property Length - 7 |
| Slice.cs:18:22:18:29 | call to method Slice | Slice(int, int) | 0 | 0 |
| Slice.cs:18:22:18:29 | call to method Slice | Slice(int, int) | 1 | access to property Length - 8 |
| Slice.cs:19:22:19:30 | call to method Slice | Slice(int, int) | 0 | access to parameter a |
| Slice.cs:19:22:19:30 | call to method Slice | Slice(int, int) | 1 | access to property Length - access to parameter b - access to parameter a |
propertyCalls
| Slice.cs:10:20:10:25 | access to property Length | Slice.cs:10:20:10:20 | access to local variable s |
| Slice.cs:11:20:11:26 | access to property Length | Slice.cs:11:20:11:20 | access to local variable s |
| Slice.cs:16:22:16:28 | access to property Length | Slice.cs:16:22:16:23 | access to local variable sp |
| Slice.cs:17:22:17:29 | access to property Length | Slice.cs:17:22:17:23 | access to local variable sp |
| Slice.cs:12:20:12:27 | access to property Length | Slice.cs:12:20:12:20 | access to local variable s |
| Slice.cs:17:22:17:28 | access to property Length | Slice.cs:17:22:17:23 | access to local variable sp |
| Slice.cs:18:22:18:29 | access to property Length | Slice.cs:18:22:18:23 | access to local variable sp |
| Slice.cs:19:22:19:30 | access to property Length | Slice.cs:19:22:19:23 | access to local variable sp |

View File

@@ -3,7 +3,7 @@ import csharp
private string printExpr(Expr e) {
e =
any(SubExpr sub |
result = sub.getLeftOperand().toString() + " - " + sub.getRightOperand().toString()
result = printExpr(sub.getLeftOperand()) + " - " + printExpr(sub.getRightOperand())
)
or
not e instanceof SubExpr and