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); }
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); }
private void Visit(XamlNodeBase node, IXamlNodeVisitor visitor) { if (visitor.IsAllowedToVisit(node)) { visitor.Visit(node, this); } XamlObjectNode objectNode = node as XamlObjectNode; if (objectNode != null) { foreach (XamlAttribute attribute in objectNode.Attributes) { Visit(attribute, visitor); } foreach (XamlNodeBase child in objectNode.Children) { Visit(child, visitor); } } }
protected static void CheckTextRange(string prefix, int?expectedLs, int?expectedLe, int?expectedPs, int?expectedPe, XamlNodeBase node) { Assert.AreEqual(expectedLs, node.LineNumberStart, prefix + "Line number start"); Assert.AreEqual(expectedLe, node.LineNumberEnd, prefix + "Line number end"); Assert.AreEqual(expectedPs, node.LinePositionStart, prefix + "Position start"); Assert.AreEqual(expectedPe, node.LinePositionEnd, prefix + "Position end"); }