/NRefactory/ICSharpCode.NRefactory.VB.Tests/Parser/TypeLevel/PropertyDeclarationTests.cs

http://github.com/icsharpcode/ILSpy · C# · 107 lines · 95 code · 10 blank · 2 comment · 2 complexity · 34b2350ae725506a9e3373f09642f1df MD5 · raw file

  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)
  3. using System;
  4. using System.IO;
  5. using ICSharpCode.NRefactory.VB.Ast;
  6. using NUnit.Framework;
  7. namespace ICSharpCode.NRefactory.VB.Tests.Ast
  8. {
  9. [TestFixture]
  10. public class PropertyDeclarationTests
  11. {
  12. #region VB.NET
  13. [Test]
  14. public void VBNetSimpleGetSetPropertyDeclarationTest()
  15. {
  16. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer \n Get \n End Get \n Set \n End Set\nEnd Property");
  17. Assert.AreEqual("MyProperty", pd.Name);
  18. Assert.IsTrue(pd.HasGetRegion);
  19. Assert.IsTrue(pd.HasSetRegion);
  20. }
  21. [Test]
  22. public void VBNetSimpleGetPropertyDeclarationTest()
  23. {
  24. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty \nGet\nEnd Get\nEnd Property");
  25. Assert.AreEqual("MyProperty", pd.Name);
  26. Assert.IsTrue(pd.HasGetRegion);
  27. Assert.IsFalse(pd.HasSetRegion);
  28. Assert.IsTrue((pd.Modifier & Modifiers.ReadOnly) == Modifiers.ReadOnly);
  29. }
  30. [Test]
  31. public void VBNetSimpleSetPropertyDeclarationTest()
  32. {
  33. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty \n Set\nEnd Set\nEnd Property ");
  34. Assert.AreEqual("MyProperty", pd.Name);
  35. Assert.IsFalse(pd.HasGetRegion);
  36. Assert.IsTrue(pd.HasSetRegion);
  37. Assert.IsTrue((pd.Modifier & Modifiers.WriteOnly) == Modifiers.WriteOnly);
  38. }
  39. [Test]
  40. public void VBNetAutoPropertyTest()
  41. {
  42. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty");
  43. Assert.AreEqual("MyProperty", pd.Name);
  44. Assert.IsTrue(pd.HasGetRegion);
  45. Assert.IsTrue(pd.HasSetRegion);
  46. Assert.AreEqual(pd.Initializer, Expression.Null);
  47. }
  48. [Test]
  49. public void VBNetReadOnlyAutoPropertyTest()
  50. {
  51. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty");
  52. Assert.AreEqual("MyProperty", pd.Name);
  53. Assert.IsTrue(pd.HasGetRegion);
  54. Assert.IsFalse(pd.HasSetRegion);
  55. Assert.AreEqual(pd.Initializer, Expression.Null);
  56. }
  57. [Test]
  58. public void VBNetWriteOnlyAutoPropertyTest()
  59. {
  60. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty");
  61. Assert.AreEqual("MyProperty", pd.Name);
  62. Assert.IsFalse(pd.HasGetRegion);
  63. Assert.IsTrue(pd.HasSetRegion);
  64. Assert.AreEqual(pd.Initializer, Expression.Null);
  65. }
  66. [Test]
  67. public void VBNetSimpleInitializerAutoPropertyTest()
  68. {
  69. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty = 5");
  70. Assert.AreEqual("MyProperty", pd.Name);
  71. Assert.IsTrue(pd.HasGetRegion);
  72. Assert.IsTrue(pd.HasSetRegion);
  73. Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
  74. }
  75. [Test]
  76. public void VBNetSimpleInitializerAutoPropertyWithTypeTest()
  77. {
  78. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer = 5");
  79. Assert.AreEqual("MyProperty", pd.Name);
  80. Assert.AreEqual("System.Int32", pd.TypeReference.Type);
  81. Assert.IsTrue(pd.HasGetRegion);
  82. Assert.IsTrue(pd.HasSetRegion);
  83. Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString());
  84. }
  85. [Test]
  86. public void VBNetSimpleObjectInitializerAutoPropertyTest()
  87. {
  88. PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As New List");
  89. Assert.AreEqual("MyProperty", pd.Name);
  90. Assert.AreEqual("List", pd.TypeReference.Type);
  91. Assert.IsTrue(pd.HasGetRegion);
  92. Assert.IsTrue(pd.HasSetRegion);
  93. Assert.AreEqual(pd.Initializer.ToString(), new ObjectCreateExpression(new TypeReference("List"), null).ToString());
  94. }
  95. #endregion
  96. }
  97. }