Skip to content

Commit e730815

Browse files
committed
C#: Add test case for params arguments in attributes
1 parent b1ad61e commit e730815

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ arguments
9090
| attributes.cs:125:18:125:29 | [return: My3(...)] | 0 | attributes.cs:125:31:125:32 | 12 |
9191
| attributes.cs:128:10:128:21 | [My3(...)] | 0 | attributes.cs:128:23:128:24 | 13 |
9292
| attributes.cs:129:17:129:28 | [My3(...)] | 0 | attributes.cs:129:30:129:31 | 14 |
93+
| attributes.cs:141:6:141:11 | [Params(...)] | 0 | attributes.cs:141:13:141:15 | "a" |
94+
| attributes.cs:141:6:141:11 | [Params(...)] | 1 | attributes.cs:141:18:141:20 | "b" |
95+
| attributes.cs:141:6:141:11 | [Params(...)] | 2 | attributes.cs:141:23:141:23 | 1 |
96+
| attributes.cs:144:6:144:11 | [Params(...)] | 0 | attributes.cs:144:17:144:19 | "a" |
97+
| attributes.cs:144:6:144:11 | [Params(...)] | 1 | attributes.cs:144:26:144:28 | "b" |
98+
| attributes.cs:144:6:144:11 | [Params(...)] | 2 | attributes.cs:144:31:144:31 | 1 |
99+
| attributes.cs:147:6:147:11 | [Params(...)] | 0 | attributes.cs:147:35:147:37 | "a" |
100+
| attributes.cs:147:6:147:11 | [Params(...)] | 1 | attributes.cs:147:26:147:28 | "b" |
101+
| attributes.cs:147:6:147:11 | [Params(...)] | 2 | attributes.cs:147:19:147:19 | 1 |
102+
| attributes.cs:150:6:150:11 | [Params(...)] | 0 | attributes.cs:150:45:150:47 | "a" |
103+
| attributes.cs:150:6:150:11 | [Params(...)] | 1 | attributes.cs:150:36:150:38 | "b" |
104+
| attributes.cs:150:6:150:11 | [Params(...)] | 2 | attributes.cs:150:19:150:29 | array creation of type Int32[] |
93105
constructorArguments
94106
| Assembly1.dll:0:0:0:0 | [Custom(...)] | 0 | Assembly1.dll:0:0:0:0 | 1 |
95107
| Assembly1.dll:0:0:0:0 | [Custom(...)] | 0 | Assembly1.dll:0:0:0:0 | 3 |
@@ -170,6 +182,18 @@ constructorArguments
170182
| attributes.cs:125:18:125:29 | [return: My3(...)] | 0 | attributes.cs:125:31:125:32 | 12 |
171183
| attributes.cs:128:10:128:21 | [My3(...)] | 0 | attributes.cs:128:23:128:24 | 13 |
172184
| attributes.cs:129:17:129:28 | [My3(...)] | 0 | attributes.cs:129:30:129:31 | 14 |
185+
| attributes.cs:141:6:141:11 | [Params(...)] | 0 | attributes.cs:141:13:141:15 | "a" |
186+
| attributes.cs:141:6:141:11 | [Params(...)] | 1 | attributes.cs:141:18:141:20 | "b" |
187+
| attributes.cs:141:6:141:11 | [Params(...)] | 2 | attributes.cs:141:23:141:23 | 1 |
188+
| attributes.cs:144:6:144:11 | [Params(...)] | 0 | attributes.cs:144:17:144:19 | "a" |
189+
| attributes.cs:144:6:144:11 | [Params(...)] | 1 | attributes.cs:144:26:144:28 | "b" |
190+
| attributes.cs:144:6:144:11 | [Params(...)] | 2 | attributes.cs:144:31:144:31 | 1 |
191+
| attributes.cs:147:6:147:11 | [Params(...)] | 0 | attributes.cs:147:35:147:37 | "a" |
192+
| attributes.cs:147:6:147:11 | [Params(...)] | 1 | attributes.cs:147:26:147:28 | "b" |
193+
| attributes.cs:147:6:147:11 | [Params(...)] | 2 | attributes.cs:147:19:147:19 | 1 |
194+
| attributes.cs:150:6:150:11 | [Params(...)] | 0 | attributes.cs:150:45:150:47 | "a" |
195+
| attributes.cs:150:6:150:11 | [Params(...)] | 1 | attributes.cs:150:36:150:38 | "b" |
196+
| attributes.cs:150:6:150:11 | [Params(...)] | 2 | attributes.cs:150:19:150:29 | array creation of type Int32[] |
173197
namedArguments
174198
| Assembly1.dll:0:0:0:0 | [Custom(...)] | Prop2 | Assembly1.dll:0:0:0:0 | array creation of type Object[] |
175199
| 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
| attributes.cs:126:9:126:11 | get_Prop1 | attributes.cs:125:18:125:29 | [return: My3(...)] | My3Attribute |
3333
| attributes.cs:130:9:130:11 | set_Prop1 | attributes.cs:128:10:128:21 | [My3(...)] | My3Attribute |
3434
| attributes.cs:130:9:130:11 | value | attributes.cs:129:17:129:28 | [My3(...)] | My3Attribute |
35+
| attributes.cs:142:17:142:18 | M1 | attributes.cs:141:6:141:11 | [Params(...)] | Class1+ParamsAttribute |
36+
| attributes.cs:145:17:145:18 | M2 | attributes.cs:144:6:144:11 | [Params(...)] | Class1+ParamsAttribute |
37+
| attributes.cs:148:17:148:18 | M3 | attributes.cs:147:6:147:11 | [Params(...)] | Class1+ParamsAttribute |
38+
| attributes.cs:151:17:151:18 | M4 | attributes.cs:150:6:150:11 | [Params(...)] | Class1+ParamsAttribute |
3539
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:10:12:10:24 | [assembly: AssemblyTitle(...)] | System.Reflection.AssemblyTitleAttribute |
3640
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:11:12:11:30 | [assembly: AssemblyDescription(...)] | System.Reflection.AssemblyDescriptionAttribute |
3741
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:12:12:12:32 | [assembly: AssemblyConfiguration(...)] | System.Reflection.AssemblyConfigurationAttribute |

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,55 @@ attributes.cs:
405405
# 130| 0: [AssignExpr] ... = ...
406406
# 130| 0: [FieldAccess] access to field p
407407
# 130| 1: [ParameterAccess] access to parameter value
408+
# 134| [Class] Class1
409+
# 136| 5: [Class] ParamsAttribute
410+
#-----| 3: (Base types)
411+
# 136| 0: [TypeMention] Attribute
412+
# 138| 4: [InstanceConstructor] ParamsAttribute
413+
#-----| 2: (Parameters)
414+
# 138| 0: [Parameter] s1
415+
# 138| -1: [TypeMention] string
416+
# 138| 1: [Parameter] s2
417+
# 138| -1: [TypeMention] string
418+
# 138| 2: [Parameter] args
419+
# 138| -1: [TypeMention] Int32[]
420+
# 138| 1: [TypeMention] int
421+
# 138| 4: [BlockStmt] {...}
422+
# 142| 6: [Method] M1
423+
# 142| -1: [TypeMention] Void
424+
#-----| 0: (Attributes)
425+
# 141| 1: [DefaultAttribute] [Params(...)]
426+
# 141| -1: [TypeMention] ParamsAttribute
427+
# 141| 0: [StringLiteralUtf16] "a"
428+
# 141| 1: [StringLiteralUtf16] "b"
429+
# 141| 2: [IntLiteral] 1
430+
# 142| 4: [BlockStmt] {...}
431+
# 145| 7: [Method] M2
432+
# 145| -1: [TypeMention] Void
433+
#-----| 0: (Attributes)
434+
# 144| 1: [DefaultAttribute] [Params(...)]
435+
# 144| -1: [TypeMention] ParamsAttribute
436+
# 144| 0: [StringLiteralUtf16] "a"
437+
# 144| 1: [StringLiteralUtf16] "b"
438+
# 144| 2: [IntLiteral] 1
439+
# 145| 4: [BlockStmt] {...}
440+
# 148| 8: [Method] M3
441+
# 148| -1: [TypeMention] Void
442+
#-----| 0: (Attributes)
443+
# 147| 1: [DefaultAttribute] [Params(...)]
444+
# 147| -1: [TypeMention] ParamsAttribute
445+
# 147| 0: [StringLiteralUtf16] "a"
446+
# 147| 1: [StringLiteralUtf16] "b"
447+
# 147| 2: [IntLiteral] 1
448+
# 148| 4: [BlockStmt] {...}
449+
# 151| 9: [Method] M4
450+
# 151| -1: [TypeMention] Void
451+
#-----| 0: (Attributes)
452+
# 150| 1: [DefaultAttribute] [Params(...)]
453+
# 150| -1: [TypeMention] ParamsAttribute
454+
# 150| 0: [StringLiteralUtf16] "a"
455+
# 150| 1: [StringLiteralUtf16] "b"
456+
# 150| 2: [ArrayCreation] array creation of type Int32[]
457+
# 150| -1: [ArrayInitializer] { ..., ... }
458+
# 150| 0: [IntLiteral] 1
459+
# 151| 4: [BlockStmt] {...}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,24 @@ public int Prop1
129129
[param: My3Attribute(14)]
130130
set { p = value; }
131131
}
132+
}
133+
134+
class Class1
135+
{
136+
public class ParamsAttribute : Attribute
137+
{
138+
public ParamsAttribute(string s1, string s2, params int[] args) { }
139+
}
140+
141+
[Params("a", "b", 1, 2, 3)]
142+
public void M1() { }
143+
144+
[Params(s1: "a", s2: "b", 1, 2, 3)]
145+
public void M2() { }
146+
147+
[Params(args: 1, s2: "b", s1: "a")]
148+
public void M3() { }
149+
150+
[Params(args: new[] { 1 }, s2: "b", s1: "a")]
151+
public void M4() { }
132152
}

0 commit comments

Comments
 (0)