Ejemplo n.º 1
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);
        }
        ObjectCreateExpression ConvertXmlElementExpression(XmlElementExpression xmlElementExpression)
        {
            var newNode = new ObjectCreateExpression(new TypeReference("XElement"), xmlElementExpression.NameIsExpression ? new List <Expression> {
                xmlElementExpression.NameExpression
            } : Expressions(xmlElementExpression.XmlName));

            foreach (XmlExpression attr in xmlElementExpression.Attributes)
            {
                if (attr is XmlAttributeExpression)
                {
                    var a = attr as XmlAttributeExpression;
                    newNode.Parameters.Add(new ObjectCreateExpression(new TypeReference("XAttribute"), new List <Expression> {
                        new PrimitiveExpression(a.Name),
                        a.IsLiteralValue ? new PrimitiveExpression(ConvertEntities(a.LiteralValue)) : a.ExpressionValue
                    }));
                }
                else if (attr is XmlEmbeddedExpression)
                {
                    newNode.Parameters.Add((attr as XmlEmbeddedExpression).InlineVBExpression);
                }
            }

            foreach (XmlExpression expr in xmlElementExpression.Children)
            {
                XmlContentExpression c = expr as XmlContentExpression;
                // skip whitespace text
                if (!(expr is XmlContentExpression && c.Type == XmlContentType.Text && string.IsNullOrWhiteSpace(c.Content)))
                {
                    newNode.Parameters.Add(ConvertXmlExpression(expr));
                }
            }

            return(newNode);
        }
        public override object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data)
        {
            ObjectCreateExpression newNode = ConvertXmlElementExpression(xmlElementExpression);

            ReplaceCurrentNode(newNode);

            return(base.VisitObjectCreateExpression(newNode, data));
        }
Ejemplo n.º 4
0
        public void VBNetSimpleEmptyElementTest()
        {
            XmlElementExpression element = ParseUtil.ParseExpression <XmlElementExpression>("<Test />");

            Assert.IsFalse(element.NameIsExpression);
            Assert.AreEqual("Test", element.XmlName);
            Assert.IsEmpty(element.Attributes);
            Assert.IsEmpty(element.Children);
            Assert.AreEqual(new Location(1, 1), element.StartLocation);
            Assert.AreEqual(new Location(9, 1), element.EndLocation);
        }
Ejemplo n.º 5
0
        void CheckElement(INode node, string name, Location start, Location end)
        {
            Assert.IsTrue(node is XmlElementExpression);
            XmlElementExpression expr = node as XmlElementExpression;

            Assert.IsEmpty(expr.Attributes);
            Assert.IsEmpty(expr.Children);
            Assert.IsFalse(expr.NameIsExpression);
            Assert.AreEqual(name, expr.XmlName);
            Assert.AreEqual(start, expr.StartLocation);
            Assert.AreEqual(end, expr.EndLocation);
        }
Ejemplo n.º 6
0
        public void VBNetElementWithMixedContentTest2()
        {
            XmlElementExpression element = ParseUtil.ParseExpression <XmlElementExpression>("<Test>  aaaa	</Test>");

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

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

            CheckContent(element.Children[0], "  aaaa	", XmlContentType.Text, new Location(7, 1), new Location(14, 1));
        }
Ejemplo n.º 7
0
        public void VBNetSimpleEmptyElementWithAttributesTest()
        {
            XmlElementExpression element = ParseUtil.ParseExpression <XmlElementExpression>("<Test id='0' name=<%= name %> <%= contentData %> />");

            Assert.IsFalse(element.NameIsExpression);
            Assert.AreEqual("Test", element.XmlName);
            Assert.IsNotEmpty(element.Attributes);
            Assert.AreEqual(3, 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.IsTrue(element.Attributes[1] is XmlAttributeExpression);
            XmlAttributeExpression attribute2 = element.Attributes[1] as XmlAttributeExpression;

            Assert.AreEqual("name", attribute2.Name);
            Assert.IsFalse(attribute2.IsLiteralValue);
            Assert.IsFalse(attribute2.ExpressionValue.IsNull);

            Assert.IsTrue(attribute2.ExpressionValue is IdentifierExpression);
            IdentifierExpression identifier = attribute2.ExpressionValue as IdentifierExpression;

            Assert.AreEqual("name", identifier.Identifier);
            Assert.AreEqual(new Location(23, 1), identifier.StartLocation);
            Assert.AreEqual(new Location(27, 1), identifier.EndLocation);

            Assert.AreEqual(new Location(14, 1), attribute2.StartLocation);
            Assert.AreEqual(new Location(30, 1), attribute2.EndLocation);

            Assert.IsTrue(element.Attributes[2] is XmlEmbeddedExpression);
            XmlEmbeddedExpression attribute3 = element.Attributes[2] as XmlEmbeddedExpression;

            Assert.IsTrue(attribute3.InlineVBExpression is IdentifierExpression);
            IdentifierExpression identifier2 = attribute3.InlineVBExpression as IdentifierExpression;

            Assert.AreEqual("contentData", identifier2.Identifier);
            Assert.AreEqual(new Location(35, 1), identifier2.StartLocation);
            Assert.AreEqual(new Location(46, 1), identifier2.EndLocation);

            Assert.AreEqual(new Location(31, 1), attribute3.StartLocation);
            Assert.AreEqual(new Location(49, 1), attribute3.EndLocation);

            Assert.IsEmpty(element.Children);
            Assert.AreEqual(new Location(1, 1), element.StartLocation);
            Assert.AreEqual(new Location(52, 1), element.EndLocation);
        }
Ejemplo n.º 8
0
        public void VBNetElementWithMixedContentTest()
        {
            XmlElementExpression element = ParseUtil.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);
        }
Ejemplo n.º 9
0
        public void VBNetSimpleEmptyElementWithAttributeTest()
        {
            XmlElementExpression element = ParseUtil.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);
        }
Ejemplo n.º 10
0
 public virtual object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data)
 {
     throw new global::System.NotImplementedException("XmlElementExpression");
 }
Ejemplo n.º 11
0
 public object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public override object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data)
 {
     return(CreateResolveResult(new TypeReference("System.Xml.Linq.XElement")));
 }