Example #1
0
        public void CommentAfterMainNode()
        {
            string     xamlText = "<tag/><!--Comment 1-->";
            XamlParser parser   = new XamlParser(Errors);

            Assert.Throws(typeof(XamlParseException), () => parser.ParseFromString(xamlText));
        }
Example #2
0
        public void TestEmpty()
        {
            XamlParser         parser   = new XamlParser(Errors);
            XamlMainObjectNode mainNode = parser.ParseFromString("");

            Assert.IsNull(mainNode, "It must be no parse result");
        }
Example #3
0
        public void TagClosed(string xamlText, XamlNodeBase.EState tagState)
        {
            XamlParser         parser   = new XamlParser(Errors);
            XamlMainObjectNode mainNode = parser.ParseFromString(xamlText);

            Assert.IsNotNull(mainNode, "It must be parse result");
            Assert.AreEqual("tag", mainNode.Name, "Wrong tag name");
            Assert.AreEqual(tagState, mainNode.State, "Node state");
        }
Example #4
0
        public void NotClosedTag()
        {
            XamlParser         parser   = new XamlParser(Errors);
            XamlMainObjectNode mainNode = parser.ParseFromString("<tag>");

            Assert.IsNotNull(mainNode, "It must be parse result");
            Assert.AreEqual("tag", mainNode.Name, "Wrong tag name");
            Assert.AreEqual(XamlNodeBase.EState.EndTagPresent, mainNode.State, "Node state");
        }
Example #5
0
        public void CommentInsideMainNode(string xamlText)
        {
            XamlParser parser = new XamlParser(Errors);

            XamlMainObjectNode mainNode = parser.ParseFromString(xamlText);

            Assert.IsNotNull(mainNode, "It must be parse result");
            Assert.AreEqual("tag", mainNode.Name, "Wrong tag name");
            Assert.AreEqual(XamlNodeBase.EState.Closed | XamlNodeBase.EState.EndTagPresent, mainNode.State, "Node state");
            Assert.AreEqual(1, mainNode.Children.Count, "Wrong children count");
            XamlNodeBase node = mainNode.Children[0];

            Assert.AreEqual(XamlNodeBase.ENodeType.Comment, node.NodeType, "Wrong node type");
            XamlCommentNode comment = node as XamlCommentNode;

            Assert.AreEqual("Comment 1", comment.Comment, "Comment text");
            CheckTextRange("Comment:", 1, 1, 6, 21, comment);
        }
Example #6
0
        public void SingleAttribute(string xamlText)
        {
            XamlParser         parser   = new XamlParser(Errors);
            XamlMainObjectNode mainNode = parser.ParseFromString(xamlText);

            Assert.IsNotNull(mainNode, "It must be parse result");
            Assert.AreEqual("tag", mainNode.Name, "Wrong tag name");
            Assert.AreEqual(XamlNodeBase.EState.Closed, mainNode.State, "Node state");
            Assert.AreEqual(0, mainNode.Children.Count, "Wrong children count");
            Assert.AreEqual(1, mainNode.Attributes.Count, "Wrong attributes count");
            XamlNodeBase node = mainNode.Attributes[0];

            Assert.AreEqual(XamlNodeBase.ENodeType.Attribute, node.NodeType, "Wrong attribute type");
            XamlAttribute attribute = node as XamlAttribute;

            Assert.AreEqual("a1", attribute.Name, "Wrong attribute name");
            Assert.AreEqual("value1", attribute.Value, "Wrong attribute value");
            CheckTextRange("Attribute:", 1, 1, 6, 16, node);
            CheckTextRangeValue("Attribute value:", 1, 1, 9, 16, attribute);
        }
Example #7
0
        public void TagWithValue(string xamlText, int endLineTag, int endPosTag, int startLineText, int startPosText, int endLineText, int endPosText)
        {
            XamlParser parser = new XamlParser(Errors);
            //                                                         12345678901234
            XamlMainObjectNode mainNode = parser.ParseFromString(xamlText);

            Assert.IsNotNull(mainNode, "It must be parse result");
            Assert.AreEqual(
                XamlNodeBase.EState.Closed | XamlNodeBase.EState.EndTagPresent | XamlNodeBase.EState.TextNodePresent,
                mainNode.State,
                "Node state");
            Assert.AreEqual("tag", mainNode.Name, "Wrong tag name");
            Assert.AreEqual(0, mainNode.Attributes.Count, "Wrong number of attributes");
            Assert.AreEqual(1, mainNode.Children.Count, "Wrong number of children");
            CheckTextRange("Tag:", 1, endLineTag, 1, endPosTag, mainNode);

            XamlTextNode textNode = mainNode.Children[0] as XamlTextNode;

            Assert.IsNotNull(textNode, "It must be text node as first child");
            Assert.AreEqual("123", textNode.Value, "Not expected text value");
            CheckTextRange("Text:", startLineText, endLineText, startPosText, endPosText, textNode);
        }
Example #8
0
        public void TestSomething()
        {
            XamlParser parser = new XamlParser(Errors);

            Assert.Throws(typeof(XamlParseException), () => parser.ParseFromString("abc"));
        }
Example #9
0
        public void TestNull()
        {
            XamlParser parser = new XamlParser(Errors);

            Assert.Throws(typeof(ArgumentNullException), () => parser.ParseFromString(null));
        }
Example #10
0
        public void CommentBeforeMainNode()
        {
            XamlParser parser = new XamlParser(Errors);

            Assert.Throws(typeof(XamlParseException), () => parser.ParseFromString("<!--Comment 1--><tag/>"));
        }
Example #11
0
        public void SingleComment()
        {
            XamlParser parser = new XamlParser(Errors);

            Assert.Throws(typeof(XamlParseException), () => parser.ParseFromString("<!--Comment 1-- >"));
        }