Skip to content

Commit 88c8ece

Browse files
committed
C#: Add list pattern test and expected results.
1 parent e6b4055 commit 88c8ece

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
listPattern
2+
| ListPattern.cs:7:18:7:19 | [ ... ] | |
3+
| ListPattern.cs:8:18:8:20 | [ ... ] | 1 |
4+
| ListPattern.cs:9:18:9:23 | [ ... ] | _, 2 |
5+
| ListPattern.cs:10:18:10:30 | [ ... ] | Int32 y, 3, 4 |
6+
| ListPattern.cs:11:18:11:31 | [ ... ] | ... or ..., _, 7 |
7+
| ListPattern.cs:12:18:12:31 | [ ... ] | Int32 a, .., 2 |
8+
| ListPattern.cs:13:18:13:50 | [ ... ] | Int32 b, .., 2 |
9+
| ListPattern.cs:20:18:20:19 | [ ... ] | |
10+
| ListPattern.cs:22:18:22:22 | [ ... ] | "A" |
11+
| ListPattern.cs:24:18:24:25 | [ ... ] | _, "B" |
12+
| ListPattern.cs:26:18:26:34 | [ ... ] | String y, "C", "D" |
13+
| ListPattern.cs:28:18:28:37 | [ ... ] | ... or ..., _, "G" |
14+
| ListPattern.cs:30:18:30:33 | [ ... ] | String a, .., "H" |
15+
| ListPattern.cs:32:18:32:39 | [ ... ] | String b, .., "I" |
16+
slicePattern
17+
| ListPattern.cs:12:26:12:27 | .. | ..: |
18+
| ListPattern.cs:13:26:13:46 | .. | ..:{ ... } |
19+
| ListPattern.cs:30:26:30:27 | .. | ..: |
20+
| ListPattern.cs:32:26:32:33 | .. | ..:String[] c |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import csharp
2+
3+
private string childPatterns(ListPatternExpr e) {
4+
result = concat(string child, int n | child = e.getPattern(n).toString() | child, ", " order by n)
5+
}
6+
7+
query predicate listPattern(ListPatternExpr pattern, string children) {
8+
pattern.getFile().getStem() = "ListPattern" and
9+
children = childPatterns(pattern)
10+
}
11+
12+
query predicate slicePattern(SlicePatternExpr pattern, string s) {
13+
pattern.getFile().getStem() = "ListPattern" and
14+
exists(string child |
15+
if exists(pattern.getPattern()) then child = pattern.getPattern().toString() else child = ""
16+
|
17+
s = pattern.toString() + ":" + child
18+
)
19+
}

0 commit comments

Comments
 (0)