示例#1
0
        public void VBObjectReferenceExpression()
        {
            MemberReferenceExpression fre = ParseUtil.ParseExpression <MemberReferenceExpression>("Object.ReferenceEquals");

            Assert.AreEqual("ReferenceEquals", fre.MemberName);
            Assert.AreEqual("System.Object", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type);
        }
 public void VBNetContextKeywordsTest()
 {
     Assert.AreEqual("Assembly", ParseUtil.ParseExpression <IdentifierExpression>("Assembly").Identifier);
     Assert.AreEqual("Custom", ParseUtil.ParseExpression <IdentifierExpression>("Custom").Identifier);
     Assert.AreEqual("Off", ParseUtil.ParseExpression <IdentifierExpression>("Off").Identifier);
     Assert.AreEqual("Explicit", ParseUtil.ParseExpression <IdentifierExpression>("Explicit").Identifier);
 }
示例#3
0
        public void VBGenericTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtil.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 VBNetFieldReferenceExpressionWithoutTargetTest()
        {
            MemberReferenceExpression fre = ParseUtil.ParseExpression <MemberReferenceExpression>(".myField");

            Assert.AreEqual("myField", fre.MemberName);
            Assert.IsTrue(fre.TargetObject.IsNull);
        }
示例#5
0
        public void VBIntReferenceExpression()
        {
            MemberReferenceExpression fre = ParseUtil.ParseExpression <MemberReferenceExpression>("inTeGer.MaxValue");

            Assert.AreEqual("MaxValue", fre.MemberName);
            Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type);
        }
示例#6
0
        public void VBNetSimpleTypeOfIsExpression()
        {
            TypeOfIsExpression ce = ParseUtil.ParseExpression <TypeOfIsExpression>("TypeOf o Is MyObject");

            Assert.AreEqual("MyObject", ce.TypeReference.Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
        }
示例#7
0
        public void VBNetElementWithAttributeTest()
        {
            XmlElementExpression element = ParseUtil.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);
        }
示例#8
0
        public void VBNetGlobalReferenceExpressionTest()
        {
            TypeReferenceExpression tre = ParseUtil.ParseExpression <TypeReferenceExpression>("Global.System");

            Assert.IsTrue(tre.TypeReference.IsGlobal);
            Assert.AreEqual("System", tre.TypeReference.Type);
        }
示例#9
0
        public void VBArrayTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtil.ParseExpression <TypeOfExpression>("GetType(MyType())");

            Assert.AreEqual("MyType", toe.TypeReference.Type);
            Assert.AreEqual(new int[] { 0 }, toe.TypeReference.RankSpecifier);
        }
示例#10
0
        void VBNetTestUnaryOperatorExpressionTest(string program, UnaryOperatorType op)
        {
            UnaryOperatorExpression uoe = ParseUtil.ParseExpression <UnaryOperatorExpression>(program);

            Assert.AreEqual(op, uoe.Op);

            Assert.IsTrue(uoe.Expression is SimpleNameExpression);
        }
示例#11
0
        public void VBNetSimpleDirectCastExpression()
        {
            CastExpression ce = ParseUtil.ParseExpression <CastExpression>("DirectCast(o, MyObject)");

            Assert.AreEqual("MyObject", ce.CastTo.Type);
            Assert.IsTrue(ce.Expression is IdentifierExpression);
            Assert.AreEqual(CastType.Cast, ce.CastType);
        }
示例#12
0
        public void VBNetGenericTypeOfIsExpression()
        {
            TypeOfIsExpression ce = ParseUtil.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);
        }
示例#13
0
        public void VBNetPrimitiveParenthesizedExpression()
        {
            ParenthesizedExpression p = ParseUtil.ParseExpression <ParenthesizedExpression>("((1))");

            Assert.IsTrue(p.Expression is ParenthesizedExpression);
            p = p.Expression as ParenthesizedExpression;;
            Assert.IsTrue(p.Expression is PrimitiveExpression);
        }
示例#14
0
        public void VBNetSimpleTryCastExpression()
        {
            CastExpression ce = ParseUtil.ParseExpression <CastExpression>("TryCast(o, MyObject)");

            Assert.AreEqual("MyObject", ce.CastTo.Type);
            Assert.IsTrue(ce.Expression is SimpleNameExpression);
            Assert.AreEqual(CastType.TryCast, ce.CastType);
        }
示例#15
0
        void TestSpecializedCast(string castExpression, Type castType)
        {
            CastExpression ce = ParseUtil.ParseExpression <CastExpression>(castExpression);

            Assert.AreEqual(castType.FullName, ce.CastTo.Type);
            Assert.IsTrue(ce.Expression is SimpleNameExpression);
            Assert.AreEqual(CastType.PrimitiveConversion, ce.CastType);
        }
        public void SimpleAddressOfExpressionTest()
        {
            AddressOfExpression ae = ParseUtil.ParseExpression <AddressOfExpression>("AddressOf t");

            Assert.IsNotNull(ae);
            Assert.IsInstanceOf(typeof(IdentifierExpression), ae.Expression);
            Assert.AreEqual("t", ((IdentifierExpression)ae.Expression).Identifier, "t");
        }
示例#17
0
        public void VBNetConditionalExpressionTest()
        {
            ConditionalExpression ce = ParseUtil.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);
        }
        public void VBNetWithDictionaryAccess()
        {
            BinaryOperatorExpression boe = ParseUtil.ParseExpression <BinaryOperatorExpression>("!b");

            Assert.AreEqual(BinaryOperatorType.DictionaryAccess, boe.Op);
            Assert.IsTrue(boe.Left.IsNull);
            Assert.IsTrue(boe.Right is PrimitiveExpression);
        }
        public void VBNetNullableObjectArrayCreateExpressionTest()
        {
            ObjectCreateExpression oce = ParseUtil.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);
        }
示例#20
0
        public void ArrayCreateExpressionTest1()
        {
            ArrayCreateExpression ace = ParseUtil.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);
        }
示例#21
0
        public void VBUnboundTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtil.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);
        }
        public void VBNetSimpleFieldReferenceExpressionTest()
        {
            MemberReferenceExpression fre = ParseUtil.ParseExpression <MemberReferenceExpression>("myTargetObject.myField");

            Assert.AreEqual("myField", fre.MemberName);
            Assert.IsTrue(fre.TargetObject is SimpleNameExpression);
            Assert.AreEqual("myTargetObject", ((SimpleNameExpression)fre.TargetObject).Identifier);
        }
示例#23
0
        public void VBNetSimpleDescendentsReferenceWithDotTest()
        {
            XmlMemberAccessExpression xmae = ParseUtil.ParseExpression <XmlMemberAccessExpression>("...<ns:Element>");

            Assert.AreEqual("ns:Element", xmae.Identifier);
            Assert.IsTrue(xmae.IsXmlIdentifier);
            Assert.AreEqual(XmlAxisType.Descendents, xmae.AxisType);
            Assert.IsTrue(xmae.TargetObject.IsNull);
        }
示例#24
0
        public void VBNetSimpleCDataTest()
        {
            XmlContentExpression content = ParseUtil.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);
        }
示例#25
0
        public void VBNetSimplePreprocessingInstructionTest()
        {
            XmlContentExpression content = ParseUtil.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);
        }
示例#26
0
        public void VBNetSimpleCommentTest()
        {
            XmlContentExpression content = ParseUtil.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);
        }
示例#27
0
        public void VBNetGenericTryCastExpression()
        {
            CastExpression ce = ParseUtil.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 SimpleNameExpression);
            Assert.AreEqual(CastType.TryCast, ce.CastType);
        }
示例#28
0
        public void VBNetInEqualsNotTest()
        {
            BinaryOperatorExpression e = ParseUtil.ParseExpression <BinaryOperatorExpression>("b <> Not a");

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

            Assert.AreEqual(UnaryOperatorType.Not, ue.Op);
        }
示例#29
0
        public void ArrayCreateExpressionTest2()
        {
            ArrayCreateExpression ace = ParseUtil.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);
        }
示例#30
0
        public void VBNetNotEqualTest()
        {
            UnaryOperatorExpression e = ParseUtil.ParseExpression <UnaryOperatorExpression>("Not a = b");

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

            Assert.AreEqual(BinaryOperatorType.Equality, boe.Op);
        }