public void VBSwitchStatementTest() { SwitchStatement switchStmt = ParseUtilVBNet.ParseStatement <SwitchStatement>("Select Case a\n Case 4, 5\n Case 6\n Case Else\n End Select"); Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier); // TODO: Extend test }
public void VBNetReDimStatementTest() { ReDimStatement reDimStatement = ParseUtilVBNet.ParseStatement <ReDimStatement>("ReDim Preserve MyArray(15)"); Assert.AreEqual(1, reDimStatement.ReDimClauses.Count); Assert.AreSame(reDimStatement, reDimStatement.ReDimClauses[0].Parent); }
public void VBNetReturnStatementTest() { ReturnStatement returnStatement = ParseUtilVBNet.ParseStatement <ReturnStatement>("Return 5"); Assert.IsFalse(returnStatement.Expression.IsNull); Assert.IsTrue(returnStatement.Expression is PrimitiveExpression); }
public void VBNetIfWithEmptyElseTest() { IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN a Else"); Assert.IsFalse(ifElseStatement.Condition.IsNull); Assert.AreEqual(1, ifElseStatement.TrueStatement.Count, "true count"); Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); }
public void VBNetGlobalTypeDeclaration() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a As Global.System.String"); TypeReference typeRef = lvd.GetTypeForVariable(0); Assert.IsTrue(typeRef.IsGlobal); Assert.AreEqual("System.String", typeRef.Type); }
public void VBNetIfWithMultipleColons() { IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN a : : b"); Assert.IsFalse(ifElseStatement.Condition.IsNull); Assert.AreEqual(2, ifElseStatement.TrueStatement.Count, "true count"); Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); }
public void VBNetUsingStatementTest2() { string usingText = @" Using nf As Font = New Font() Bla(nf) End Using"; UsingStatement usingStmt = ParseUtilVBNet.ParseStatement <UsingStatement>(usingText); // TODO : Extend test. }
public void VBNetUsingStatementTest3() { string usingText = @" Using nf As New Font(), nf2 As New List(Of Font)(), nf3 = Nothing Bla(nf) End Using"; UsingStatement usingStmt = ParseUtilVBNet.ParseStatement <UsingStatement>(usingText); // TODO : Extend test. }
public void InvalidVBSwitchStatementTest() { SwitchStatement switchStmt = ParseUtilVBNet.ParseStatement <SwitchStatement>("Select Case a\n Case \n End Select", true); Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier); SwitchSection sec = switchStmt.SwitchSections[0]; Assert.AreEqual(0, sec.SwitchLabels.Count); }
public void VBNetSimpleIfStatementTest2() { IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN\n END\n END IF"); Assert.IsFalse(ifElseStatement.Condition.IsNull); Assert.IsTrue(ifElseStatement.TrueStatement.Count == 1, "true count != 1:" + ifElseStatement.TrueStatement.Count); Assert.IsTrue(ifElseStatement.FalseStatement.Count == 0, "false count != 0:" + ifElseStatement.FalseStatement.Count); Assert.IsTrue(ifElseStatement.TrueStatement[0] is BlockStatement, "Statement was: " + ifElseStatement.TrueStatement[0]); }
void VBNetTestAssignmentExpression(string program, AssignmentOperatorType op) { ExpressionStatement se = ParseUtilVBNet.ParseStatement <ExpressionStatement>(program); AssignmentExpression ae = se.Expression as AssignmentExpression; Assert.AreEqual(op, ae.Op); Assert.IsTrue(ae.Left is IdentifierExpression); Assert.IsTrue(ae.Right is IdentifierExpression); }
public void VBNetUsingStatementTest() { string usingText = @" Using nf As New System.Drawing.Font(""Arial"", 12.0F, FontStyle.Bold) c.Font = nf c.Text = ""This is 12-point Arial bold"" End Using"; UsingStatement usingStmt = ParseUtilVBNet.ParseStatement <UsingStatement>(usingText); // TODO : Extend test. }
public void VBNetDimInSingleLineIf() { IfElseStatement ifes = ParseUtilVBNet.ParseStatement <IfElseStatement>("If a Then Dim b As String"); LocalVariableDeclaration lvd = (LocalVariableDeclaration)ifes.TrueStatement[0]; Assert.AreEqual(1, lvd.Variables.Count); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("System.String", type.Type); }
public void VBNetLocalVariableNamedOverrideDeclarationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim override As Integer = 5"); Assert.AreEqual(1, lvd.Variables.Count); Assert.AreEqual("override", lvd.Variables[0].Name); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("System.Int32", type.Type); Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables[0].Initializer).Value); }
public void VBNetLocalArrayDeclarationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a() As Integer"); Assert.AreEqual(1, lvd.Variables.Count); Assert.AreEqual("a", lvd.Variables[0].Name); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("System.Int32", type.Type); Assert.AreEqual(new int[] { 0 }, type.RankSpecifier); }
public void VBNetMultiStatementIfStatementTest() { IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN Stop : b"); Assert.IsFalse(ifElseStatement.Condition.IsNull); Assert.AreEqual(2, ifElseStatement.TrueStatement.Count, "true count"); Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); Assert.IsTrue(ifElseStatement.TrueStatement[0] is StopStatement); Assert.IsTrue(ifElseStatement.TrueStatement[1] is ExpressionStatement); }
public void VBNetGenericLocalVariableDeclarationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a As G(Of Integer)"); Assert.AreEqual(1, lvd.Variables.Count); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("G", type.Type); Assert.AreEqual(1, type.GenericTypes.Count); Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); }
public void VBNetGenericLocalVariableInitializationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a As New G(Of Integer)"); Assert.AreEqual(1, lvd.Variables.Count); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("G", type.Type); Assert.AreEqual(1, type.GenericTypes.Count); Assert.AreEqual("Integer", type.GenericTypes[0].Type); // TODO: Check initializer }
public void VBNetIfWithSingleLineElse() { // This isn't legal according to the VB spec, but the MS VB compiler seems to allow it. IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN\n" + " x()\n" + "Else y()\n" + "End If"); Assert.IsFalse(ifElseStatement.Condition.IsNull); Assert.AreEqual(1, ifElseStatement.TrueStatement.Count, "true count"); Assert.AreEqual(1, ifElseStatement.FalseStatement.Count, "false count"); }
public void VBNetGenericWithArrayLocalVariableDeclarationTest1() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a As G(Of Integer)()"); Assert.AreEqual(1, lvd.Variables.Count); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("G", type.Type); Assert.AreEqual(1, type.GenericTypes.Count); Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); Assert.IsFalse(type.GenericTypes[0].IsArrayType); Assert.AreEqual(new int[] { 0 }, type.RankSpecifier); }
public void VBNetIfStatementLocationTest() { IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN\n" + "DoIt()\n" + "ElseIf False Then\n" + "DoIt()\n" + "End If"); Assert.AreEqual(3, (ifElseStatement.StartLocation).Line); Assert.AreEqual(7, (ifElseStatement.EndLocation).Line); Assert.AreEqual(5, (ifElseStatement.ElseIfSections[0].StartLocation).Line); Assert.AreEqual(6, (ifElseStatement.ElseIfSections[0].EndLocation).Line); Assert.IsNotNull(ifElseStatement.ElseIfSections[0].Parent); }
public void VBNetGenericWithArrayLocalVariableDeclarationTest2() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a As G(Of Integer())"); Assert.AreEqual(1, lvd.Variables.Count); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("G", type.Type); Assert.AreEqual(1, type.GenericTypes.Count); Assert.AreEqual("Integer", type.GenericTypes[0].Type); Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); Assert.IsFalse(type.IsArrayType); Assert.AreEqual(1, type.GenericTypes[0].RankSpecifier.Length); Assert.AreEqual(0, type.GenericTypes[0].RankSpecifier[0]); }
public void VBNetLocalJaggedArrayDeclarationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a(10)() As Integer"); Assert.AreEqual(1, lvd.Variables.Count); Assert.AreEqual("a", lvd.Variables[0].Name); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("System.Int32", type.Type); Assert.AreEqual(new int[] { 0, 0 }, type.RankSpecifier); ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer; Assert.AreEqual(new int[] { 0, 0 }, ace.CreateType.RankSpecifier); Assert.AreEqual(1, ace.Arguments.Count); Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value); }
public void VBNetComplexGenericLocalVariableDeclarationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim where As Generic(Of Printable, G(Of Printable()))"); Assert.AreEqual(1, lvd.Variables.Count); Assert.AreEqual("where", lvd.Variables[0].Name); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("Generic", type.Type); Assert.AreEqual(2, type.GenericTypes.Count); Assert.AreEqual("Printable", type.GenericTypes[0].Type); Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); Assert.AreEqual("G", type.GenericTypes[1].Type); Assert.AreEqual(1, type.GenericTypes[1].GenericTypes.Count); Assert.AreEqual("Printable", type.GenericTypes[1].GenericTypes[0].Type); }
public void VBNetElse_IfStatementTest() { IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("If True THEN\n" + "END\n" + "Else If False Then\n" + "Stop\n" + "End If"); Assert.IsFalse(ifElseStatement.Condition.IsNull); Assert.IsTrue(ifElseStatement.TrueStatement.Count == 1, "true count != 1:" + ifElseStatement.TrueStatement.Count); Assert.IsTrue(ifElseStatement.FalseStatement.Count == 0, "false count != 0:" + ifElseStatement.FalseStatement.Count); Assert.IsFalse((bool)(ifElseStatement.ElseIfSections[0].Condition as PrimitiveExpression).Value); Assert.IsTrue(ifElseStatement.TrueStatement[0] is BlockStatement, "Statement was: " + ifElseStatement.TrueStatement[0]); Assert.IsTrue(ifElseStatement.ElseIfSections[0].EmbeddedStatement.Children[0] is StopStatement, "Statement was: " + ifElseStatement.ElseIfSections[0].EmbeddedStatement.Children[0]); }
public void VBNetLocalArrayDeclarationWithInitializationAndLowerBoundTest() { // VB.NET allows only "0" as lower bound LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a(0 To 10) As Integer"); Assert.AreEqual(1, lvd.Variables.Count); Assert.AreEqual("a", lvd.Variables[0].Name); TypeReference type = lvd.GetTypeForVariable(0); Assert.AreEqual("System.Int32", type.Type); Assert.AreEqual(new int[] { 0 }, type.RankSpecifier); ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer; Assert.AreEqual(new int[] { 0 }, ace.CreateType.RankSpecifier); Assert.AreEqual(1, ace.Arguments.Count); Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value); }
public void VBNetNestedGenericLocalVariableDeclarationTest() { LocalVariableDeclaration lvd = ParseUtilVBNet.ParseStatement <LocalVariableDeclaration>("Dim a as MyType(of string).InnerClass(of integer).InnerInnerClass"); Assert.AreEqual(1, lvd.Variables.Count); InnerClassTypeReference ic = (InnerClassTypeReference)lvd.GetTypeForVariable(0); Assert.AreEqual("InnerInnerClass", ic.Type); Assert.AreEqual(0, ic.GenericTypes.Count); ic = (InnerClassTypeReference)ic.BaseType; Assert.AreEqual("InnerClass", ic.Type); Assert.AreEqual(1, ic.GenericTypes.Count); Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type); Assert.AreEqual("MyType", ic.BaseType.Type); Assert.AreEqual(1, ic.BaseType.GenericTypes.Count); Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type); }
public void VBNetStopStatementTest() { StopStatement stopStatement = ParseUtilVBNet.ParseStatement <StopStatement>("Stop"); }
public void VBNetAddHandlerTest() { AddHandlerStatement addHandlerStatement = ParseUtilVBNet.ParseStatement <AddHandlerStatement>("AddHandler Obj.Ev_Event, AddressOf EventHandler"); }
public void VBNetForeachStatementTest() { ForeachStatement foreachStmt = ParseUtilVBNet.ParseStatement <ForeachStatement>("For Each i As Integer In myColl : Next"); // TODO : Extend test. }