PageRenderTime 22ms CodeModel.GetById 6ms app.highlight 9ms RepoModel.GetById 5ms app.codeStats 0ms

/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
  4using System;
  5using System.IO;
  6using ICSharpCode.NRefactory.VB.Ast;
  7using NUnit.Framework;
  8
  9namespace ICSharpCode.NRefactory.VB.Tests.Ast
 10{
 11	[TestFixture]
 12	public class PropertyDeclarationTests
 13	{
 14		#region VB.NET
 15		[Test]
 16		public void VBNetSimpleGetSetPropertyDeclarationTest()
 17		{
 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);
 22		}
 23		
 24		[Test]
 25		public void VBNetSimpleGetPropertyDeclarationTest()
 26		{
 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);
 32		}
 33		
 34		[Test]
 35		public void VBNetSimpleSetPropertyDeclarationTest()
 36		{
 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);
 42		}
 43		
 44		[Test]
 45		public void VBNetAutoPropertyTest()
 46		{
 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);
 52		}
 53		
 54		[Test]
 55		public void VBNetReadOnlyAutoPropertyTest()
 56		{
 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);
 62		}
 63		
 64		[Test]
 65		public void VBNetWriteOnlyAutoPropertyTest()
 66		{
 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);
 72		}
 73		
 74		[Test]
 75		public void VBNetSimpleInitializerAutoPropertyTest()
 76		{
 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());
 82		}
 83		
 84		[Test]
 85		public void VBNetSimpleInitializerAutoPropertyWithTypeTest()
 86		{
 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());
 93		}
 94		
 95		[Test]
 96		public void VBNetSimpleObjectInitializerAutoPropertyTest()
 97		{
 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());
104		}
105		#endregion
106	}
107}