mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C#: Add some testcases to cover mixed assignment and declarations in tuples.
This commit is contained in:
27
csharp/ql/test/library-tests/csharp10/Tuples.cs
Normal file
27
csharp/ql/test/library-tests/csharp10/Tuples.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
public class Deconstruction
|
||||
{
|
||||
public void M1()
|
||||
{
|
||||
// Declaration and Assignment
|
||||
(int x1, int y1) = (10, 11);
|
||||
|
||||
// Assignment
|
||||
int x2 = 0;
|
||||
int y2 = 0;
|
||||
(x2, y2) = (20, 21);
|
||||
|
||||
// Mixed
|
||||
int y3 = 0;
|
||||
(int x3, y3) = (30, 31);
|
||||
|
||||
int x4 = 0;
|
||||
(x4, int y4) = (40, 41);
|
||||
|
||||
// Nested, Mixed
|
||||
int x5 = 0;
|
||||
int y51 = 0;
|
||||
(x5, (int y50, y51)) = (50, (51, 52));
|
||||
}
|
||||
}
|
||||
18
csharp/ql/test/library-tests/csharp10/tuples.expected
Normal file
18
csharp/ql/test/library-tests/csharp10/tuples.expected
Normal file
@@ -0,0 +1,18 @@
|
||||
declarations
|
||||
| Tuples.cs:8:14:8:15 | Int32 x1 |
|
||||
| Tuples.cs:8:22:8:23 | Int32 y1 |
|
||||
| Tuples.cs:17:14:17:15 | Int32 x3 |
|
||||
| Tuples.cs:20:18:20:19 | Int32 y4 |
|
||||
| Tuples.cs:25:19:25:21 | Int32 y50 |
|
||||
assignments
|
||||
| Tuples.cs:8:9:8:35 | ... = ... | Tuples.cs:8:14:8:15 | x1 | 0 |
|
||||
| Tuples.cs:8:9:8:35 | ... = ... | Tuples.cs:8:22:8:23 | y1 | 1 |
|
||||
| Tuples.cs:13:9:13:27 | ... = ... | Tuples.cs:11:13:11:14 | x2 | 0 |
|
||||
| Tuples.cs:13:9:13:27 | ... = ... | Tuples.cs:12:13:12:14 | y2 | 1 |
|
||||
| Tuples.cs:17:9:17:31 | ... = ... | Tuples.cs:16:13:16:14 | y3 | 1 |
|
||||
| Tuples.cs:17:9:17:31 | ... = ... | Tuples.cs:17:14:17:15 | x3 | 0 |
|
||||
| Tuples.cs:20:9:20:31 | ... = ... | Tuples.cs:19:13:19:14 | x4 | 0 |
|
||||
| Tuples.cs:20:9:20:31 | ... = ... | Tuples.cs:20:18:20:19 | y4 | 1 |
|
||||
| Tuples.cs:25:9:25:45 | ... = ... | Tuples.cs:23:13:23:14 | x5 | 0 |
|
||||
| Tuples.cs:25:9:25:45 | ... = ... | Tuples.cs:24:13:24:15 | y51 | 2 |
|
||||
| Tuples.cs:25:9:25:45 | ... = ... | Tuples.cs:25:19:25:21 | y50 | 1 |
|
||||
14
csharp/ql/test/library-tests/csharp10/tuples.ql
Normal file
14
csharp/ql/test/library-tests/csharp10/tuples.ql
Normal file
@@ -0,0 +1,14 @@
|
||||
import csharp
|
||||
|
||||
private predicate relevant(Element e) { e.getFile().getBaseName() = "Tuples.cs" }
|
||||
|
||||
query predicate declarations(LocalVariableDeclExpr d) {
|
||||
relevant(d) and
|
||||
d.getParent*() instanceof TupleExpr
|
||||
}
|
||||
|
||||
query predicate assignments(AssignableDefinitions::TupleAssignmentDefinition t, Assignable a, int o) {
|
||||
relevant(t.getAssignment()) and
|
||||
a = t.getTarget() and
|
||||
o = t.getEvaluationOrder()
|
||||
}
|
||||
Reference in New Issue
Block a user