Skip to content

Commit 2c6e35f

Browse files
committed
C#: Add more attribute testcases.
1 parent 31a70a1 commit 2c6e35f

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed

csharp/ql/test/library-tests/attributes/AttributeArguments.expected

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ arguments
8080
| attributes.cs:97:10:97:21 | [My3(...)] | 0 | attributes.cs:97:23:97:23 | 2 |
8181
| attributes.cs:100:10:100:21 | [My3(...)] | 0 | attributes.cs:100:23:100:23 | 3 |
8282
| attributes.cs:101:8:101:19 | [My3(...)] | 0 | attributes.cs:101:21:101:21 | 4 |
83+
| attributes.cs:106:6:106:17 | [My3(...)] | 0 | attributes.cs:106:19:106:19 | 5 |
84+
| attributes.cs:107:14:107:25 | [My3(...)] | 0 | attributes.cs:107:27:107:27 | 6 |
85+
| attributes.cs:112:10:112:21 | [My3(...)] | 0 | attributes.cs:112:23:112:23 | 7 |
86+
| attributes.cs:113:18:113:29 | [My3(...)] | 0 | attributes.cs:113:31:113:31 | 8 |
87+
| attributes.cs:116:18:116:29 | [My3(...)] | 0 | attributes.cs:116:31:116:31 | 9 |
88+
| attributes.cs:117:17:117:28 | [My3(...)] | 0 | attributes.cs:117:30:117:31 | 10 |
89+
| attributes.cs:124:18:124:29 | [My3(...)] | 0 | attributes.cs:124:31:124:32 | 11 |
90+
| attributes.cs:125:18:125:29 | [My3(...)] | 0 | attributes.cs:125:31:125:32 | 12 |
91+
| attributes.cs:128:10:128:21 | [My3(...)] | 0 | attributes.cs:128:23:128:24 | 13 |
92+
| attributes.cs:129:17:129:28 | [My3(...)] | 0 | attributes.cs:129:30:129:31 | 14 |
8393
constructorArguments
8494
| Assembly1.dll:0:0:0:0 | [Custom(...)] | 0 | Assembly1.dll:0:0:0:0 | 1 |
8595
| Assembly1.dll:0:0:0:0 | [Custom(...)] | 0 | Assembly1.dll:0:0:0:0 | 3 |
@@ -150,6 +160,16 @@ constructorArguments
150160
| attributes.cs:97:10:97:21 | [My3(...)] | 0 | attributes.cs:97:23:97:23 | 2 |
151161
| attributes.cs:100:10:100:21 | [My3(...)] | 0 | attributes.cs:100:23:100:23 | 3 |
152162
| attributes.cs:101:8:101:19 | [My3(...)] | 0 | attributes.cs:101:21:101:21 | 4 |
163+
| attributes.cs:106:6:106:17 | [My3(...)] | 0 | attributes.cs:106:19:106:19 | 5 |
164+
| attributes.cs:107:14:107:25 | [My3(...)] | 0 | attributes.cs:107:27:107:27 | 6 |
165+
| attributes.cs:112:10:112:21 | [My3(...)] | 0 | attributes.cs:112:23:112:23 | 7 |
166+
| attributes.cs:113:18:113:29 | [My3(...)] | 0 | attributes.cs:113:31:113:31 | 8 |
167+
| attributes.cs:116:18:116:29 | [My3(...)] | 0 | attributes.cs:116:31:116:31 | 9 |
168+
| attributes.cs:117:17:117:28 | [My3(...)] | 0 | attributes.cs:117:30:117:31 | 10 |
169+
| attributes.cs:124:18:124:29 | [My3(...)] | 0 | attributes.cs:124:31:124:32 | 11 |
170+
| attributes.cs:125:18:125:29 | [My3(...)] | 0 | attributes.cs:125:31:125:32 | 12 |
171+
| attributes.cs:128:10:128:21 | [My3(...)] | 0 | attributes.cs:128:23:128:24 | 13 |
172+
| attributes.cs:129:17:129:28 | [My3(...)] | 0 | attributes.cs:129:30:129:31 | 14 |
153173
namedArguments
154174
| Assembly1.dll:0:0:0:0 | [Custom(...)] | Prop2 | Assembly1.dll:0:0:0:0 | array creation of type Object[] |
155175
| Assembly1.dll:0:0:0:0 | [Custom(...)] | Prop2 | Assembly1.dll:0:0:0:0 | array creation of type Object[] |

csharp/ql/test/library-tests/attributes/AttributeElements.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
| attributes.cs:98:14:98:24 | My1Delegate | attributes.cs:96:2:96:13 | [My3(...)] | My3Attribute |
2323
| attributes.cs:102:17:102:27 | Invoke | attributes.cs:100:10:100:21 | [My3(...)] | My3Attribute |
2424
| attributes.cs:102:17:102:27 | My2Delegate | attributes.cs:101:8:101:19 | [My3(...)] | My3Attribute |
25+
| attributes.cs:108:32:108:32 | + | attributes.cs:106:6:106:17 | [My3(...)] | My3Attribute |
26+
| attributes.cs:108:32:108:32 | + | attributes.cs:107:14:107:25 | [My3(...)] | My3Attribute |
27+
| attributes.cs:114:9:114:11 | get_Item | attributes.cs:112:10:112:21 | [My3(...)] | My3Attribute |
28+
| attributes.cs:114:9:114:11 | get_Item | attributes.cs:113:18:113:29 | [My3(...)] | My3Attribute |
29+
| attributes.cs:118:9:118:11 | set_Item | attributes.cs:116:18:116:29 | [My3(...)] | My3Attribute |
30+
| attributes.cs:118:9:118:11 | value | attributes.cs:117:17:117:28 | [My3(...)] | My3Attribute |
31+
| attributes.cs:126:9:126:11 | get_Prop1 | attributes.cs:124:18:124:29 | [My3(...)] | My3Attribute |
32+
| attributes.cs:126:9:126:11 | get_Prop1 | attributes.cs:125:18:125:29 | [My3(...)] | My3Attribute |
33+
| attributes.cs:130:9:130:11 | set_Prop1 | attributes.cs:128:10:128:21 | [My3(...)] | My3Attribute |
34+
| attributes.cs:130:9:130:11 | value | attributes.cs:129:17:129:28 | [My3(...)] | My3Attribute |
2535
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:10:12:10:24 | [AssemblyTitle(...)] | System.Reflection.AssemblyTitleAttribute |
2636
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:11:12:11:30 | [AssemblyDescription(...)] | System.Reflection.AssemblyDescriptionAttribute |
2737
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:12:12:12:32 | [AssemblyConfiguration(...)] | System.Reflection.AssemblyConfigurationAttribute |

csharp/ql/test/library-tests/attributes/PrintAst.expected

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,84 @@ attributes.cs:
324324
#-----| 2: (Parameters)
325325
# 102| 0: [Parameter] message
326326
# 102| -1: [TypeMention] string
327+
# 104| [Class] MyAttributeUsage
328+
# 108| 5: [AddOperator] +
329+
# 108| -1: [TypeMention] int
330+
#-----| 0: (Attributes)
331+
# 106| 1: [DefaultAttribute] [My3(...)]
332+
# 106| -1: [TypeMention] My3Attribute
333+
# 106| 0: [IntLiteral] 5
334+
# 107| 2: [ReturnAttribute] [My3(...)]
335+
# 107| -1: [TypeMention] My3Attribute
336+
# 107| 0: [IntLiteral] 6
337+
#-----| 2: (Parameters)
338+
# 108| 0: [Parameter] a
339+
# 108| -1: [TypeMention] MyAttributeUsage
340+
# 108| 1: [Parameter] b
341+
# 108| -1: [TypeMention] MyAttributeUsage
342+
# 108| 4: [IntLiteral] 0
343+
# 110| 6: [Indexer] Item
344+
# 110| -1: [TypeMention] int
345+
#-----| 1: (Parameters)
346+
# 110| 0: [Parameter] x
347+
# 110| -1: [TypeMention] int
348+
# 114| 3: [Getter] get_Item
349+
#-----| 0: (Attributes)
350+
# 112| 1: [DefaultAttribute] [My3(...)]
351+
# 112| -1: [TypeMention] My3Attribute
352+
# 112| 0: [IntLiteral] 7
353+
# 113| 2: [ReturnAttribute] [My3(...)]
354+
# 113| -1: [TypeMention] My3Attribute
355+
# 113| 0: [IntLiteral] 8
356+
#-----| 2: (Parameters)
357+
# 110| 0: [Parameter] x
358+
# 114| 4: [BlockStmt] {...}
359+
# 114| 0: [ReturnStmt] return ...;
360+
# 114| 0: [AddExpr] ... + ...
361+
# 114| 0: [ParameterAccess] access to parameter x
362+
# 114| 1: [IntLiteral] 1
363+
# 118| 4: [Setter] set_Item
364+
#-----| 0: (Attributes)
365+
# 116| 1: [DefaultAttribute] [My3(...)]
366+
# 116| -1: [TypeMention] My3Attribute
367+
# 116| 0: [IntLiteral] 9
368+
#-----| 2: (Parameters)
369+
# 110| 0: [Parameter] x
370+
# 118| 1: [Parameter] value
371+
#-----| 0: (Attributes)
372+
# 117| 1: [DefaultAttribute] [My3(...)]
373+
# 117| -1: [TypeMention] My3Attribute
374+
# 117| 0: [IntLiteral] 10
375+
# 118| 4: [BlockStmt] {...}
376+
# 118| 0: [ReturnStmt] return ...;
377+
# 121| 7: [Field] p
378+
# 121| -1: [TypeMention] int
379+
# 122| 8: [Property] Prop1
380+
# 122| -1: [TypeMention] int
381+
# 126| 3: [Getter] get_Prop1
382+
#-----| 0: (Attributes)
383+
# 124| 1: [DefaultAttribute] [My3(...)]
384+
# 124| -1: [TypeMention] My3Attribute
385+
# 124| 0: [IntLiteral] 11
386+
# 125| 2: [ReturnAttribute] [My3(...)]
387+
# 125| -1: [TypeMention] My3Attribute
388+
# 125| 0: [IntLiteral] 12
389+
# 126| 4: [BlockStmt] {...}
390+
# 126| 0: [ReturnStmt] return ...;
391+
# 126| 0: [FieldAccess] access to field p
392+
# 130| 4: [Setter] set_Prop1
393+
#-----| 0: (Attributes)
394+
# 128| 1: [DefaultAttribute] [My3(...)]
395+
# 128| -1: [TypeMention] My3Attribute
396+
# 128| 0: [IntLiteral] 13
397+
#-----| 2: (Parameters)
398+
# 130| 0: [Parameter] value
399+
#-----| 0: (Attributes)
400+
# 129| 1: [DefaultAttribute] [My3(...)]
401+
# 129| -1: [TypeMention] My3Attribute
402+
# 129| 0: [IntLiteral] 14
403+
# 130| 4: [BlockStmt] {...}
404+
# 130| 0: [ExprStmt] ...;
405+
# 130| 0: [AssignExpr] ... = ...
406+
# 130| 0: [FieldAccess] access to field p
407+
# 130| 1: [ParameterAccess] access to parameter value

csharp/ql/test/library-tests/attributes/attributes.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,34 @@ public My3Attribute(int x) { }
9999

100100
[return: My3Attribute(3)]
101101
[type: My3Attribute(4)]
102-
delegate string My2Delegate(string message);
102+
delegate string My2Delegate(string message);
103+
104+
public class MyAttributeUsage
105+
{
106+
[My3Attribute(5)]
107+
[return: My3Attribute(6)]
108+
public static int operator +(MyAttributeUsage a, MyAttributeUsage b) => 0;
109+
110+
public int this[int x]
111+
{
112+
[My3Attribute(7)]
113+
[return: My3Attribute(8)]
114+
get { return x + 1; }
115+
116+
[method: My3Attribute(9)]
117+
[param: My3Attribute(10)]
118+
set { return; }
119+
}
120+
121+
private int p;
122+
public int Prop1
123+
{
124+
[method: My3Attribute(11)]
125+
[return: My3Attribute(12)]
126+
get { return p; }
127+
128+
[My3Attribute(13)]
129+
[param: My3Attribute(14)]
130+
set { p = value; }
131+
}
132+
}

0 commit comments

Comments
 (0)