1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using ICSharpCode.NRefactory.VB.Ast;
9
namespace ICSharpCode.NRefactory.VB.Tests.Ast
12
public class PropertyDeclarationTests
16
public void VBNetSimpleGetSetPropertyDeclarationTest()
18
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer \n Get \n End Get \n Set \n End Set\nEnd Property");
19
Assert.AreEqual("MyProperty", pd.Name);
20
Assert.IsTrue(pd.HasGetRegion);
21
Assert.IsTrue(pd.HasSetRegion);
25
public void VBNetSimpleGetPropertyDeclarationTest()
27
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty \nGet\nEnd Get\nEnd Property");
28
Assert.AreEqual("MyProperty", pd.Name);
29
Assert.IsTrue(pd.HasGetRegion);
30
Assert.IsFalse(pd.HasSetRegion);
31
Assert.IsTrue((pd.Modifier & Modifiers.ReadOnly) == Modifiers.ReadOnly);
35
public void VBNetSimpleSetPropertyDeclarationTest()
37
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty \n Set\nEnd Set\nEnd Property ");
38
Assert.AreEqual("MyProperty", pd.Name);
39
Assert.IsFalse(pd.HasGetRegion);
40
Assert.IsTrue(pd.HasSetRegion);
41
Assert.IsTrue((pd.Modifier & Modifiers.WriteOnly) == Modifiers.WriteOnly);
45
public void VBNetAutoPropertyTest()
47
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty");
48
Assert.AreEqual("MyProperty", pd.Name);
49
Assert.IsTrue(pd.HasGetRegion);
50
Assert.IsTrue(pd.HasSetRegion);
51
Assert.AreEqual(pd.Initializer, Expression.Null);
55
public void VBNetReadOnlyAutoPropertyTest()
57
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty");
58
Assert.AreEqual("MyProperty", pd.Name);
59
Assert.IsTrue(pd.HasGetRegion);
60
Assert.IsFalse(pd.HasSetRegion);
61
Assert.AreEqual(pd.Initializer, Expression.Null);
65
public void VBNetWriteOnlyAutoPropertyTest()
67
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty");
68
Assert.AreEqual("MyProperty", pd.Name);
69
Assert.IsFalse(pd.HasGetRegion);
70
Assert.IsTrue(pd.HasSetRegion);
71
Assert.AreEqual(pd.Initializer, Expression.Null);
75
public void VBNetSimpleInitializerAutoPropertyTest()
77
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty = 5");
78
Assert.AreEqual("MyProperty", pd.Name);
79
Assert.IsTrue(pd.HasGetRegion);
80
Assert.IsTrue(pd.HasSetRegion);
81
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
85
public void VBNetSimpleInitializerAutoPropertyWithTypeTest()
87
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer = 5");
88
Assert.AreEqual("MyProperty", pd.Name);
89
Assert.AreEqual("System.Int32", pd.TypeReference.Type);
90
Assert.IsTrue(pd.HasGetRegion);
91
Assert.IsTrue(pd.HasSetRegion);
92
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
96
public void VBNetSimpleObjectInitializerAutoPropertyTest()
98
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As New List");
99
Assert.AreEqual("MyProperty", pd.Name);
100
Assert.AreEqual("List", pd.TypeReference.Type);
101
Assert.IsTrue(pd.HasGetRegion);
102
Assert.IsTrue(pd.HasSetRegion);
103
Assert.AreEqual(pd.Initializer.ToString(), new ObjectCreateExpression(new TypeReference("List"), null).ToString());