Skip to content

Commit 9a269fe

Browse files
committed
C#: Add some more properties test examples and update expected test output.
1 parent 9df7a2f commit 9a269fe

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,69 @@ properties.cs:
246246
# 133| 0: [FieldAccess] access to field Prop.field
247247
# 133| 1: [ParameterAccess] access to parameter value
248248
# 130| 7: [Field] Prop.field
249+
# 137| 11: [Class] BaseClass
250+
# 139| 6: [Property] Value
251+
# 139| -1: [TypeMention] int
252+
# 141| 3: [Getter] get_Value
253+
# 141| 4: [BlockStmt] {...}
254+
# 141| 0: [ReturnStmt] return ...;
255+
# 141| 0: [FieldAccess] access to field Value.field
256+
# 142| 4: [Setter] set_Value
257+
#-----| 2: (Parameters)
258+
# 142| 0: [Parameter] value
259+
# 142| 4: [BlockStmt] {...}
260+
# 142| 0: [ExprStmt] ...;
261+
# 142| 0: [AssignExpr] ... = ...
262+
# 142| 0: [FieldAccess] access to field Value.field
263+
# 142| 1: [ParameterAccess] access to parameter value
264+
# 139| 7: [Field] Value.field
265+
# 146| 12: [Class] DerivedClass1
266+
#-----| 3: (Base types)
267+
# 146| 0: [TypeMention] BaseClass
268+
# 148| 6: [Property] Value
269+
# 148| -1: [TypeMention] int
270+
# 150| 3: [Getter] get_Value
271+
# 150| 4: [BlockStmt] {...}
272+
# 150| 0: [ReturnStmt] return ...;
273+
# 150| 0: [IntLiteral] 20
274+
# 154| 13: [Class] DerivedClass2
275+
#-----| 3: (Base types)
276+
# 154| 0: [TypeMention] BaseClass
277+
# 155| 14: [Class] Test2
278+
# 157| 6: [Method] M
279+
# 157| -1: [TypeMention] Void
280+
# 158| 4: [BlockStmt] {...}
281+
# 159| 0: [LocalVariableDeclStmt] ... ...;
282+
# 159| 0: [LocalVariableDeclAndInitExpr] DerivedClass1 d1 = ...
283+
# 159| -1: [TypeMention] DerivedClass1
284+
# 159| 0: [LocalVariableAccess] access to local variable d1
285+
# 159| 1: [ObjectCreation] object creation of type DerivedClass1
286+
# 159| 0: [TypeMention] DerivedClass1
287+
# 160| 1: [ExprStmt] ...;
288+
# 160| 0: [AssignExpr] ... = ...
289+
# 160| 0: [PropertyCall] access to property Value
290+
# 160| -1: [LocalVariableAccess] access to local variable d1
291+
# 160| 1: [IntLiteral] 11
292+
# 161| 2: [LocalVariableDeclStmt] ... ...;
293+
# 161| 0: [LocalVariableDeclAndInitExpr] Int32 test1 = ...
294+
# 161| -1: [TypeMention] int
295+
# 161| 0: [LocalVariableAccess] access to local variable test1
296+
# 161| 1: [PropertyCall] access to property Value
297+
# 161| -1: [LocalVariableAccess] access to local variable d1
298+
# 163| 3: [LocalVariableDeclStmt] ... ...;
299+
# 163| 0: [LocalVariableDeclAndInitExpr] DerivedClass2 d2 = ...
300+
# 163| -1: [TypeMention] DerivedClass2
301+
# 163| 0: [LocalVariableAccess] access to local variable d2
302+
# 163| 1: [ObjectCreation] object creation of type DerivedClass2
303+
# 163| 0: [TypeMention] DerivedClass2
304+
# 164| 4: [ExprStmt] ...;
305+
# 164| 0: [AssignExpr] ... = ...
306+
# 164| 0: [PropertyCall] access to property Value
307+
# 164| -1: [LocalVariableAccess] access to local variable d2
308+
# 164| 1: [IntLiteral] 12
309+
# 165| 5: [LocalVariableDeclStmt] ... ...;
310+
# 165| 0: [LocalVariableDeclAndInitExpr] Int32 test2 = ...
311+
# 165| -1: [TypeMention] int
312+
# 165| 0: [LocalVariableAccess] access to local variable test2
313+
# 165| 1: [PropertyCall] access to property Value
314+
# 165| -1: [LocalVariableAccess] access to local variable d2

csharp/ql/test/library-tests/properties/Properties17.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| Prop.field |
2+
| Value.field |
23
| caption |
34
| next |
45
| y |

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,36 @@ public object Prop
133133
set { field = value; }
134134
}
135135
}
136+
137+
public class BaseClass
138+
{
139+
public virtual int Value
140+
{
141+
get { return field; }
142+
set { field = value; }
143+
}
144+
}
145+
146+
public class DerivedClass1 : BaseClass
147+
{
148+
public override int Value
149+
{
150+
get { return 20; }
151+
}
152+
}
153+
154+
public class DerivedClass2 : BaseClass { }
155+
public class Test2
156+
{
157+
public void M()
158+
{
159+
var d1 = new DerivedClass1();
160+
d1.Value = 11;
161+
var test1 = d1.Value;
162+
163+
var d2 = new DerivedClass2();
164+
d2.Value = 12;
165+
var test2 = d2.Value;
166+
}
167+
}
136168
}

0 commit comments

Comments
 (0)