PageRenderTime 17ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/TypeOfExpressionTests.cs

http://github.com/icsharpcode/ILSpy
C# | 87 lines | 75 code | 10 blank | 2 comment | 0 complexity | b4665cbcfbc7d07fc4e329acd4d75ba2 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 NUnit.Framework;
 7using ICSharpCode.NRefactory.VB.Parser;
 8using ICSharpCode.NRefactory.VB.Ast;
 9
10namespace ICSharpCode.NRefactory.VB.Tests.Ast
11{
12	[TestFixture]
13	public class TypeOfExpressionTests
14	{
15		#region VB.NET
16		[Test]
17		public void VBSimpleTypeOfExpressionTest()
18		{
19			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyNamespace.N1.MyType)");
20			Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
21		}
22		
23		
24		[Test]
25		public void VBGlobalTypeOfExpressionTest()
26		{
27			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(Global.System.Console)");
28			Assert.AreEqual("System.Console", toe.TypeReference.Type);
29		}
30		
31		[Test]
32		public void VBPrimitiveTypeOfExpressionTest()
33		{
34			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(integer)");
35			Assert.AreEqual("System.Int32", toe.TypeReference.Type);
36		}
37		
38		[Test]
39		public void VBVoidTypeOfExpressionTest()
40		{
41			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(void)");
42			Assert.AreEqual("void", toe.TypeReference.Type);
43		}
44		
45		[Test]
46		public void VBArrayTypeOfExpressionTest()
47		{
48			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyType())");
49			Assert.AreEqual("MyType", toe.TypeReference.Type);
50			Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier);
51		}
52		
53		[Test]
54		public void VBGenericTypeOfExpressionTest()
55		{
56			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyNamespace.N1.MyType(Of string))");
57			Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
58			Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type);
59		}
60		
61		[Test]
62		public void VBUnboundTypeOfExpressionTest()
63		{
64			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyType(Of ,))");
65			Assert.AreEqual("MyType", toe.TypeReference.Type);
66			Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull);
67			Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull);
68		}
69		
70		[Test]
71		public void VBNestedGenericTypeOfExpressionTest()
72		{
73			TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyType(Of string).InnerClass(of integer).InnerInnerClass)");
74			InnerClassTypeReference ic = (InnerClassTypeReference)toe.TypeReference;
75			Assert.AreEqual("InnerInnerClass", ic.Type);
76			Assert.AreEqual(0, ic.GenericTypes.Count);
77			ic = (InnerClassTypeReference)ic.BaseType;
78			Assert.AreEqual("InnerClass", ic.Type);
79			Assert.AreEqual(1, ic.GenericTypes.Count);
80			Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type);
81			Assert.AreEqual("MyType", ic.BaseType.Type);
82			Assert.AreEqual(1, ic.BaseType.GenericTypes.Count);
83			Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type);
84		}
85		#endregion
86	}
87}