PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/icsharpcode/ILSpy
C# | 74 lines | 61 code | 11 blank | 2 comment | 0 complexity | f11a82d73ea0b8482d86919fe40ef2a8 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 ICSharpCode.NRefactory.VB.Ast;
 6using NUnit.Framework;
 7
 8namespace ICSharpCode.NRefactory.VB.Tests.Ast
 9{
10	[TestFixture]
11	public class FieldDeclarationTests
12	{
13		#region VB.NET
14		[Test]
15		public void VBNetSimpleFieldDeclarationTest()
16		{
17			FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("myField As Integer(,,,)");
18			Assert.AreEqual(1, fd.Fields.Count);
19			
20			Assert.AreEqual("System.Int32", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
21			Assert.AreEqual("System.Int32", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
22			Assert.AreEqual("myField", ((VariableDeclaration)fd.Fields[0]).Name);
23			Assert.AreEqual(new int[] { 3 } , ((VariableDeclaration)fd.Fields[0]).TypeReference.RankSpecifier);
24		}
25		
26		[Test]
27		public void VBNetMultiFieldDeclarationTest()
28		{
29			FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("a, b As String");
30			Assert.AreEqual(2, fd.Fields.Count);
31			
32			Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
33			Assert.IsFalse(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType);
34			Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type);
35			Assert.IsFalse(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType);
36		}
37		
38		[Test]
39		public void VBNetMultiFieldsOnSingleLineTest()
40		{
41			string program = "Class TestClass : Dim a : Dim b : End Class";
42			TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
43			
44			Assert.AreEqual(2, td.Children.Count);
45			Assert.IsTrue(td.Children[0] is FieldDeclaration);
46			Assert.IsTrue(td.Children[1] is FieldDeclaration);
47		}
48		
49		[Test]
50		public void VBNetMultiFieldDeclarationTest2()
51		{
52			FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("Dim a, b() As String");
53			Assert.AreEqual(2, fd.Fields.Count);
54			
55			Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
56			Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type);
57			Assert.IsFalse(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType);
58			Assert.IsTrue(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType);
59		}
60		
61		[Test]
62		public void VBNetMultiFieldDeclarationTest3()
63		{
64			FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("Dim a(), b As String");
65			Assert.AreEqual(2, fd.Fields.Count);
66			
67			Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
68			Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type);
69			Assert.IsTrue(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType);
70			Assert.IsFalse(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType);
71		}
72		#endregion
73	}
74}