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);
        }
Esempio n. 2
0
        public void VBNetJuggedNamespaceTest()
        {
            string program = "Namespace N1 'TestNamespace\n" +
                             "    Namespace N2   ' Declares a namespace named N2 within N1.\n" +
                             "    End Namespace\n" +
                             "End Namespace\n";

            NamespaceDeclaration ns = ParseUtilVBNet.ParseGlobal <NamespaceDeclaration>(program);

            Assert.AreEqual("N1", ns.Name);

            Assert.IsTrue(ns.Children[0] is NamespaceDeclaration);

            ns = (NamespaceDeclaration)ns.Children[0];

            Assert.AreEqual("N2", ns.Name);
        }
Esempio n. 3
0
        public void VBNetInvalidTypeArgumentListObjectCreateExpressionTest()
        {
            // this test was written because this bug caused the AbstractASTVisitor to crash

            InvocationExpression expr = ParseUtilVBNet.ParseExpression <InvocationExpression>("WriteLine(New SomeGenericType(Of Integer, )())", true);

            Assert.IsTrue(expr.TargetObject is IdentifierExpression);
            Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.TargetObject).Identifier);
            Assert.AreEqual(1, expr.Arguments.Count);             // here a second null parameter was added incorrectly

            Assert.IsTrue(expr.Arguments[0] is ObjectCreateExpression);
            TypeReference typeRef = ((ObjectCreateExpression)expr.Arguments[0]).CreateType;

            Assert.AreEqual("SomeGenericType", typeRef.Type);
            Assert.AreEqual(1, typeRef.GenericTypes.Count);
            Assert.AreEqual("System.Int32", typeRef.GenericTypes[0].Type);
        }
Esempio n. 4
0
        public void VBNetBigReDimStatementTest()
        {
            string          program         = @"
Class X
	Sub x
		ReDim sU(m - 1, n - 1)
		ReDim sW(n - 1)
		ReDim sV(n - 1, n - 1)
		ReDim rv1(n - 1)
		ReDim sMt(iNrCols - 1, 0)
		ReDim Preserve sMt(iNrCols - 1, iRowNr)
		ReDim sM(iRowNr - 1, iNrCols - 1)
		If (IsNothing(ColLengths)) Then ReDim ColLengths(0)
		If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1)
		ReDim sTransform(2, iTransformType - 1)
		ReDim Preserve _Items(_Count)
		ReDim Preserve _Items(nCapacity)
		ReDim Preserve _Items(0 To _Count)
		ReDim Preserve _Items(0 To nCapacity)
		ReDim sU(m - 1, n - 1)
		ReDim sW(n - 1)
		ReDim sV(n - 1, n - 1)
		ReDim rv1(n - 1)
		ReDim sMt(iNrCols - 1, 0)
		ReDim Preserve sMt(iNrCols - 1, iRowNr)
		ReDim sM(iRowNr - 1, iNrCols - 1)
		If (IsNothing(ColLengths)) Then ReDim ColLengths(0)
		If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1)
		ReDim sTransform(2, iTransformType - 1)
		ReDim Preserve Samples(Samples.GetUpperBound(0) + 1)
		ReDim Samples(0)
		ReDim BaseCssContent(BaseCssContentRows - 1)
		ReDim mabtRxBuf(Bytes2Read - 1)
		ReDim Preserve primarykey(primarykey.Length)
		ReDim Preserve IntArray(10, 10, 15)
		ReDim X(10, 10)
		ReDim Preserve IntArray(0 To 10, 10, 0 To 20)
		ReDim Preserve IntArray(10, 10, 15)
		ReDim X(0 To 10, 0 To 10)
		ReDim GetMe().IntArray(0 To 10, 10, 0 To 20)
		ReDim GetMe(ExplicitParameter := 3).IntArray(0 To 10, 10, 0 To 20)
		ReDim SomeType(Of Integer).IntArray(0 To 10, 10, 0 To 20)
	End Sub
End Class";
            TypeDeclaration typeDeclaration = ParseUtilVBNet.ParseGlobal <TypeDeclaration>(program);
        }
        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 VBNetGenericMethodInInterface()
        {
            const string      program = @"Interface MyInterface
				Function MyMethod(Of T As {ISomeInterface})(a As T) As T
				End Interface"                ;
            TypeDeclaration   td      = ParseUtilVBNet.ParseGlobal <TypeDeclaration>(program);
            MethodDeclaration md      = (MethodDeclaration)td.Children[0];

            Assert.AreEqual("T", md.TypeReference.Type);
            Assert.AreEqual(1, md.Parameters.Count);
            Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
            Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);

            Assert.AreEqual(1, md.Templates.Count);
            Assert.AreEqual("T", md.Templates[0].Name);
            Assert.AreEqual(1, md.Templates[0].Bases.Count);
            Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
        }
        public void VBNetMethodWithHandlesClause()
        {
            MethodDeclaration md = ParseUtilVBNet.ParseTypeMember <MethodDeclaration>(
                @"Public Sub MyMethod(sender As Object, e As EventArgs) Handles x.y
			End Sub"            );

            Assert.AreEqual(new string[] { "x.y" }, md.HandlesClause.ToArray());

            md = ParseUtilVBNet.ParseTypeMember <MethodDeclaration>(
                @"Public Sub MyMethod() Handles Me.FormClosing
			End Sub"            );
            Assert.AreEqual(new string[] { "Me.FormClosing" }, md.HandlesClause.ToArray());

            md = ParseUtilVBNet.ParseTypeMember <MethodDeclaration>(
                @"Public Sub MyMethod() Handles MyBase.Event, Button1.Click
			End Sub"            );
            Assert.AreEqual(new string[] { "MyBase.Event", "Button1.Click" }, md.HandlesClause.ToArray());
        }
Esempio n. 8
0
        public void VBNetElementWithMixedContentTest()
        {
            XmlElementExpression element = ParseUtilVBNet.ParseExpression <XmlElementExpression>("<Test id='0'>\n" +
                                                                                                 "	<!-- test -->\n"+
                                                                                                 "	<Item />\n"+
                                                                                                 "	<Item />\n"+
                                                                                                 "	<![CDATA[<cdata> section]]>\n"+
                                                                                                 "</Test>");

            Assert.IsFalse(element.NameIsExpression);
            Assert.AreEqual("Test", element.XmlName);

            Assert.IsNotEmpty(element.Attributes);
            Assert.AreEqual(1, element.Attributes.Count);
            Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression);
            XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression;

            Assert.AreEqual("id", attribute.Name);
            Assert.IsTrue(attribute.IsLiteralValue);
            Assert.IsTrue(attribute.ExpressionValue.IsNull);
            Assert.AreEqual("0", attribute.LiteralValue);
            Assert.AreEqual(new Location(7, 1), attribute.StartLocation);
            Assert.AreEqual(new Location(13, 1), attribute.EndLocation);

            Assert.IsNotEmpty(element.Children);
            Assert.AreEqual(9, element.Children.Count);

            CheckContent(element.Children[0], "\n\t", XmlContentType.Text, new Location(14, 1), new Location(2, 2));
            CheckContent(element.Children[2], "\n\t", XmlContentType.Text, new Location(15, 2), new Location(2, 3));
            CheckContent(element.Children[4], "\n\t", XmlContentType.Text, new Location(10, 3), new Location(2, 4));
            CheckContent(element.Children[6], "\n\t", XmlContentType.Text, new Location(10, 4), new Location(2, 5));
            CheckContent(element.Children[7], "<cdata> section", XmlContentType.CData, new Location(2, 5), new Location(29, 5));
            CheckContent(element.Children[8], "\n", XmlContentType.Text, new Location(29, 5), new Location(1, 6));

            CheckContent(element.Children[1], " test ", XmlContentType.Comment, new Location(2, 2), new Location(15, 2));
            CheckElement(element.Children[3], "Item", new Location(2, 3), new Location(10, 3));
            CheckElement(element.Children[5], "Item", new Location(2, 4), new Location(10, 4));

            Assert.AreEqual(new Location(1, 1), element.StartLocation);
            Assert.AreEqual(new Location(8, 6), element.EndLocation);
        }
Esempio n. 9
0
        public void VBNetSimpleEmptyElementWithAttributeTest()
        {
            XmlElementExpression element = ParseUtilVBNet.ParseExpression <XmlElementExpression>("<Test id='0' />");

            Assert.IsFalse(element.NameIsExpression);
            Assert.AreEqual("Test", element.XmlName);
            Assert.IsNotEmpty(element.Attributes);
            Assert.AreEqual(1, element.Attributes.Count);
            Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression);
            XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression;

            Assert.AreEqual("id", attribute.Name);
            Assert.IsTrue(attribute.IsLiteralValue);
            Assert.IsTrue(attribute.ExpressionValue.IsNull);
            Assert.AreEqual("0", attribute.LiteralValue);
            Assert.AreEqual(new Location(7, 1), attribute.StartLocation);
            Assert.AreEqual(new Location(13, 1), attribute.EndLocation);
            Assert.IsEmpty(element.Children);
            Assert.AreEqual(new Location(1, 1), element.StartLocation);
            Assert.AreEqual(new Location(16, 1), element.EndLocation);
        }
        public void VBInvocationOnGenericInnerClassInGenericType()
        {
            InvocationExpression      expr = ParseUtilVBNet.ParseExpression <InvocationExpression>("A(Of T).B.C(Of U).Foo()");
            MemberReferenceExpression mre  = (MemberReferenceExpression)expr.TargetObject;

            Assert.AreEqual("Foo", mre.MemberName);

            MemberReferenceExpression mre2 = (MemberReferenceExpression)mre.TargetObject;

            Assert.AreEqual("C", mre2.MemberName);
            Assert.AreEqual("U", mre2.TypeArguments[0].Type);

            MemberReferenceExpression mre3 = (MemberReferenceExpression)mre2.TargetObject;

            Assert.AreEqual("B", mre3.MemberName);

            IdentifierExpression tre = (IdentifierExpression)mre3.TargetObject;

            Assert.AreEqual("A", tre.Identifier);
            Assert.AreEqual("T", tre.TypeArguments[0].Type);
        }
        void SameOperatorPrecedenceTest(string firstOperator, BinaryOperatorType firstOperatorType,
                                        string secondOperator, BinaryOperatorType secondOperatorType, bool vb)
        {
            string program = "a " + secondOperator + " b " + firstOperator + " c";
            BinaryOperatorExpression boe;

            if (vb)
            {
                boe = ParseUtilVBNet.ParseExpression <BinaryOperatorExpression>(program);
            }
            else
            {
                boe = ParseUtilCSharp.ParseExpression <BinaryOperatorExpression>(program);
            }
            Assert.AreEqual(firstOperatorType, boe.Op);
            Assert.IsTrue(boe.Right is IdentifierExpression);
            boe = (BinaryOperatorExpression)boe.Left;
            Assert.AreEqual(secondOperatorType, boe.Op);
            Assert.IsTrue(boe.Left is IdentifierExpression);
            Assert.IsTrue(boe.Right is IdentifierExpression);

            program = "a " + firstOperator + " b " + secondOperator + " c";
            if (vb)
            {
                boe = ParseUtilVBNet.ParseExpression <BinaryOperatorExpression>(program);
            }
            else
            {
                boe = ParseUtilCSharp.ParseExpression <BinaryOperatorExpression>(program);
            }
            Assert.AreEqual(secondOperatorType, boe.Op);
            Assert.IsTrue(boe.Right is IdentifierExpression);
            boe = (BinaryOperatorExpression)boe.Left;
            Assert.AreEqual(firstOperatorType, boe.Op);
            Assert.IsTrue(boe.Left is IdentifierExpression);
            Assert.IsTrue(boe.Right is IdentifierExpression);
        }
        public void VBStandaloneIntReferenceExpression()
        {
            TypeReferenceExpression tre = ParseUtilVBNet.ParseExpression <TypeReferenceExpression>("inTeGer");

            Assert.AreEqual("System.Int32", tre.TypeReference.Type);
        }
Esempio n. 13
0
 public void VBNetForeachStatementTest()
 {
     ForeachStatement foreachStmt = ParseUtilVBNet.ParseStatement <ForeachStatement>("For Each i As Integer In myColl : Next");
     // TODO : Extend test.
 }
Esempio n. 14
0
 static LambdaExpression ParseVBNet(string program)
 {
     return(ParseUtilVBNet.ParseExpression <LambdaExpression>(program));
 }
Esempio n. 15
0
        public void VBPrimitiveTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(integer)");

            Assert.AreEqual("System.Int32", toe.TypeReference.Type);
        }
Esempio n. 16
0
        public void VBSimpleTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(MyNamespace.N1.MyType)");

            Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
        }
 public void VBNetGenericInvocation2ExpressionTest()
 {
     CheckGenericInvoke2(ParseUtilVBNet.ParseExpression <InvocationExpression>("myMethod(Of T, Boolean)()"));
 }
 public void VBNetSimpleInvocationExpressionTest()
 {
     CheckSimpleInvoke(ParseUtilVBNet.ParseExpression <InvocationExpression>("myMethod()"));
 }
Esempio n. 19
0
 public void VBNetEndStatementInIfThenTest2()
 {
     IfElseStatement endStatement = ParseUtilVBNet.ParseStatement <IfElseStatement>("IF a THEN End");
 }
Esempio n. 20
0
 public void VBNetEraseStatementTest()
 {
     EraseStatement eraseStatement = ParseUtilVBNet.ParseStatement <EraseStatement>("Erase a, b, c");
 }
 public void VBNetGenericInvocationExpressionTest()
 {
     CheckGenericInvoke(ParseUtilVBNet.ParseExpression <InvocationExpression>("myMethod(Of Char)(\"a\"c)"));
 }
        public void VBStandaloneObjectReferenceExpression()
        {
            TypeReferenceExpression tre = ParseUtilVBNet.ParseExpression <TypeReferenceExpression>("obJect");

            Assert.AreEqual("System.Object", tre.TypeReference.Type);
        }
        public void PrimitiveExpression1Test()
        {
            InvocationExpression ie = ParseUtilVBNet.ParseExpression <InvocationExpression>("546.ToString()");

            Assert.AreEqual(0, ie.Arguments.Count);
        }
        public void VBNetIdentifierExpressionTest1()
        {
            IdentifierExpression ie = ParseUtilVBNet.ParseExpression <IdentifierExpression>("MyIdentifier");

            Assert.AreEqual("MyIdentifier", ie.Identifier);
        }
 public void VBNetStopStatementTest()
 {
     StopStatement stopStatement = ParseUtilVBNet.ParseStatement <StopStatement>("Stop");
 }
        public void VBNetIdentifierExpressionTest2()
        {
            IdentifierExpression ie = ParseUtilVBNet.ParseExpression <IdentifierExpression>("[Public]");

            Assert.AreEqual("Public", ie.Identifier);
        }
Esempio n. 27
0
        public void VBGlobalTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(Global.System.Console)");

            Assert.AreEqual("System.Console", toe.TypeReference.Type);
        }
Esempio n. 28
0
 public void VBNetResumeStatementTest()
 {
     ResumeStatement resumeStatement = ParseUtilVBNet.ParseStatement <ResumeStatement>("Resume");
 }
Esempio n. 29
0
        public void VBVoidTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(void)");

            Assert.AreEqual("void", toe.TypeReference.Type);
        }
Esempio n. 30
0
 public void VBNetAddHandlerTest()
 {
     AddHandlerStatement addHandlerStatement = ParseUtilVBNet.ParseStatement <AddHandlerStatement>("AddHandler Obj.Ev_Event, AddressOf EventHandler");
 }