public void VBIntReferenceExpression()
        {
            MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression <MemberReferenceExpression>("inTeGer.MaxValue");

            Assert.AreEqual("MaxValue", fre.MemberName);
            Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type);
        }
 public void VBNetContextKeywordsTest()
 {
     Assert.AreEqual("Assembly", ParseUtilVBNet.ParseExpression <IdentifierExpression>("Assembly").Identifier);
     Assert.AreEqual("Custom", ParseUtilVBNet.ParseExpression <IdentifierExpression>("Custom").Identifier);
     Assert.AreEqual("Off", ParseUtilVBNet.ParseExpression <IdentifierExpression>("Off").Identifier);
     Assert.AreEqual("Explicit", ParseUtilVBNet.ParseExpression <IdentifierExpression>("Explicit").Identifier);
 }
        public void VBObjectReferenceExpression()
        {
            MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression <MemberReferenceExpression>("Object.ReferenceEquals");

            Assert.AreEqual("ReferenceEquals", fre.MemberName);
            Assert.AreEqual("System.Object", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type);
        }
        public void VBNetGlobalReferenceExpressionTest()
        {
            TypeReferenceExpression tre = ParseUtilVBNet.ParseExpression <TypeReferenceExpression>("Global.System");

            Assert.IsTrue(tre.TypeReference.IsGlobal);
            Assert.AreEqual("System", tre.TypeReference.Type);
        }
Exemplo n.º 5
0
        public void VBNetFieldReferenceExpressionWithoutTargetTest()
        {
            FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression <FieldReferenceExpression>(".myField");

            Assert.AreEqual("myField", fre.FieldName);
            Assert.IsTrue(fre.TargetObject.IsNull);
        }
Exemplo n.º 6
0
        public void VBArrayTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(MyType())");

            Assert.AreEqual("MyType", toe.TypeReference.Type);
            Assert.AreEqual(new int[] { 0 }, toe.TypeReference.RankSpecifier);
        }
Exemplo n.º 7
0
        public void VBGenericTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(MyNamespace.N1.MyType(Of string))");

            Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
            Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type);
        }
        public void VBNetSimpleTypeOfIsExpression()
        {
            TypeOfIsExpression ce = ParseUtilVBNet.ParseExpression <TypeOfIsExpression>("TypeOf o Is MyObject");

            Assert.AreEqual("MyObject", ce.TypeReference.Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
        }
Exemplo n.º 9
0
        public void VBNetElementWithAttributeTest()
        {
            XmlElementExpression element = ParseUtilVBNet.ParseExpression <XmlElementExpression>("<Test id='0'>\n" +
                                                                                                 "	<Item />\n"+
                                                                                                 "	<Item />\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(5, 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(10, 2), new Location(2, 3));
            CheckContent(element.Children[4], "\n", XmlContentType.Text, new Location(10, 3), new Location(1, 4));

            CheckElement(element.Children[1], "Item", new Location(2, 2), new Location(10, 2));
            CheckElement(element.Children[3], "Item", new Location(2, 3), new Location(10, 3));

            Assert.AreEqual(new Location(1, 1), element.StartLocation);
            Assert.AreEqual(new Location(8, 4), element.EndLocation);
        }
Exemplo n.º 10
0
        void TestSpecializedCast(string castExpression, Type castType)
        {
            CastExpression ce = ParseUtilVBNet.ParseExpression <CastExpression>(castExpression);

            Assert.AreEqual(castType.FullName, ce.CastTo.Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
            Assert.AreEqual(CastType.PrimitiveConversion, ce.CastType);
        }
Exemplo n.º 11
0
        public void VBNetConditionalExpressionTest()
        {
            ConditionalExpression ce = ParseUtilVBNet.ParseExpression <ConditionalExpression>("If(x IsNot Nothing, x.Test, \"nothing\")");

            Assert.IsTrue(ce.Condition is BinaryOperatorExpression);
            Assert.IsTrue(ce.TrueExpression is MemberReferenceExpression);
            Assert.IsTrue(ce.FalseExpression is PrimitiveExpression);
        }
Exemplo n.º 12
0
        public void VBNetNullableObjectArrayCreateExpressionTest()
        {
            ObjectCreateExpression oce = ParseUtilVBNet.ParseExpression <ObjectCreateExpression>("New Integer?()");

            Assert.AreEqual("System.Nullable", oce.CreateType.Type);
            Assert.AreEqual(1, oce.CreateType.GenericTypes.Count);
            Assert.AreEqual("System.Int32", oce.CreateType.GenericTypes[0].Type);
        }
        public void VBNetPrimitiveParenthesizedExpression()
        {
            ParenthesizedExpression p = ParseUtilVBNet.ParseExpression <ParenthesizedExpression>("((1))");

            Assert.IsTrue(p.Expression is ParenthesizedExpression);
            p = p.Expression as ParenthesizedExpression;;
            Assert.IsTrue(p.Expression is PrimitiveExpression);
        }
Exemplo n.º 14
0
        public void VBNetArrayCreateExpressionTest1()
        {
            ArrayCreateExpression ace = ParseUtilVBNet.ParseExpression <ArrayCreateExpression>("new Integer() {1, 2, 3, 4}");

            Assert.AreEqual("System.Int32", ace.CreateType.Type);
            Assert.AreEqual(0, ace.Arguments.Count);
            Assert.AreEqual(new int[] { 0 }, ace.CreateType.RankSpecifier);
        }
Exemplo n.º 15
0
        public void SimpleAddressOfExpressionTest()
        {
            AddressOfExpression ae = ParseUtilVBNet.ParseExpression <AddressOfExpression>("AddressOf t");

            Assert.IsNotNull(ae);
            Assert.IsInstanceOf <IdentifierExpression>(ae.Expression);
            Assert.AreEqual("t", ((IdentifierExpression)ae.Expression).Identifier, "t");
        }
Exemplo n.º 16
0
        public void VBNetWithDictionaryAccess()
        {
            BinaryOperatorExpression boe = ParseUtilVBNet.ParseExpression <BinaryOperatorExpression>("!b");

            Assert.AreEqual(BinaryOperatorType.DictionaryAccess, boe.Op);
            Assert.IsTrue(boe.Left.IsNull);
            Assert.IsTrue(boe.Right is PrimitiveExpression);
        }
Exemplo n.º 17
0
        public void VBUnboundTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilVBNet.ParseExpression <TypeOfExpression>("GetType(MyType(Of ,))");

            Assert.AreEqual("MyType", toe.TypeReference.Type);
            Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull);
            Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull);
        }
Exemplo n.º 18
0
        public void VBNetSimpleFieldReferenceExpressionTest()
        {
            FieldReferenceExpression fre = ParseUtilVBNet.ParseExpression <FieldReferenceExpression>("myTargetObject.myField");

            Assert.AreEqual("myField", fre.FieldName);
            Assert.IsTrue(fre.TargetObject is IdentifierExpression);
            Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
        }
Exemplo n.º 19
0
        public void VBNetSimpleTryCastExpression()
        {
            CastExpression ce = ParseUtilVBNet.ParseExpression <CastExpression>("TryCast(o, MyObject)");

            Assert.AreEqual("MyObject", ce.CastTo.Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
            Assert.AreEqual(CastType.TryCast, ce.CastType);
        }
        void VBNetTestUnaryOperatorExpressionTest(string program, UnaryOperatorType op)
        {
            UnaryOperatorExpression uoe = ParseUtilVBNet.ParseExpression <UnaryOperatorExpression>(program);

            Assert.AreEqual(op, uoe.Op);

            Assert.IsTrue(uoe.Expression is IdentifierExpression);
        }
        public void VBNetGenericTypeOfIsExpression()
        {
            TypeOfIsExpression ce = ParseUtilVBNet.ParseExpression <TypeOfIsExpression>("TypeOf o Is List(of T)");

            Assert.AreEqual("List", ce.TypeReference.Type);
            Assert.AreEqual("T", ce.TypeReference.GenericTypes[0].Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
        }
Exemplo n.º 22
0
        public void VBNetSimplePreprocessingInstructionTest()
        {
            XmlContentExpression content = ParseUtilVBNet.ParseExpression <XmlContentExpression>("<?xml version='1.0'?>");

            Assert.AreEqual(XmlContentType.ProcessingInstruction, content.Type);
            Assert.AreEqual("xml version='1.0'", content.Content);
            Assert.AreEqual(new Location(1, 1), content.StartLocation);
            Assert.AreEqual(new Location(22, 1), content.EndLocation);
        }
Exemplo n.º 23
0
        public void VBNetSimpleCDataTest()
        {
            XmlContentExpression content = ParseUtilVBNet.ParseExpression <XmlContentExpression>("<![CDATA[<simple> <cdata>]]>");

            Assert.AreEqual(XmlContentType.CData, content.Type);
            Assert.AreEqual("<simple> <cdata>", content.Content);
            Assert.AreEqual(new Location(1, 1), content.StartLocation);
            Assert.AreEqual(new Location(29, 1), content.EndLocation);
        }
        void VBNetTestBinaryOperatorExpressionTest(string program, BinaryOperatorType op)
        {
            BinaryOperatorExpression boe = ParseUtilVBNet.ParseExpression <BinaryOperatorExpression>(program);

            Assert.AreEqual(op, boe.Op);

            Assert.IsTrue(boe.Left is IdentifierExpression);
            Assert.IsTrue(boe.Right is IdentifierExpression);
        }
        public void VBNetNotEqualTest()
        {
            UnaryOperatorExpression e = ParseUtilVBNet.ParseExpression <UnaryOperatorExpression>("Not a = b");

            Assert.AreEqual(UnaryOperatorType.Not, e.Op);
            BinaryOperatorExpression boe = (BinaryOperatorExpression)e.Expression;

            Assert.AreEqual(BinaryOperatorType.Equality, boe.Op);
        }
        public void VBNetInEqualsNotTest()
        {
            BinaryOperatorExpression e = ParseUtilVBNet.ParseExpression <BinaryOperatorExpression>("b <> Not a");

            Assert.AreEqual(BinaryOperatorType.InEquality, e.Op);
            UnaryOperatorExpression ue = (UnaryOperatorExpression)e.Right;

            Assert.AreEqual(UnaryOperatorType.Not, ue.Op);
        }
Exemplo n.º 27
0
        public void MemberReferenceAddressOfExpressionTest()
        {
            AddressOfExpression ae = ParseUtilVBNet.ParseExpression <AddressOfExpression>("AddressOf Me.t(Of X)");

            Assert.IsNotNull(ae);
            Assert.IsInstanceOf <MemberReferenceExpression>(ae.Expression);
            Assert.AreEqual("t", ((MemberReferenceExpression)ae.Expression).MemberName, "t");
            Assert.IsInstanceOf <ThisReferenceExpression>(((MemberReferenceExpression)ae.Expression).TargetObject);
        }
Exemplo n.º 28
0
        public void VBNetArrayCreateExpressionTest2()
        {
            ArrayCreateExpression ace = ParseUtilVBNet.ParseExpression <ArrayCreateExpression>("New Integer(0 To 5){0, 1, 2, 3, 4, 5}");

            Assert.AreEqual("System.Int32", ace.CreateType.Type);
            Assert.AreEqual(1, ace.Arguments.Count);
            Assert.AreEqual(5, (ace.Arguments[0] as PrimitiveExpression).Value);
            Assert.AreEqual(new int[] { 0 }, ace.CreateType.RankSpecifier);
        }
Exemplo n.º 29
0
        public void VBNetSimpleCommentTest()
        {
            XmlContentExpression content = ParseUtilVBNet.ParseExpression <XmlContentExpression>("<!-- test -->");

            Assert.AreEqual(XmlContentType.Comment, content.Type);
            Assert.AreEqual(" test ", content.Content);
            Assert.AreEqual(new Location(1, 1), content.StartLocation);
            Assert.AreEqual(new Location(14, 1), content.EndLocation);
        }
Exemplo n.º 30
0
        public void VBNetGenericTryCastExpression()
        {
            CastExpression ce = ParseUtilVBNet.ParseExpression <CastExpression>("TryCast(o, List(of T))");

            Assert.AreEqual("List", ce.CastTo.Type);
            Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
            Assert.AreEqual(CastType.TryCast, ce.CastType);
        }