public void Unclosed() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <tag.a> <tag.b><tag.b>$ </tag.a>$ </doc> ", delegate { parser.AssertStateIs <XmlRootState> (); parser.AssertNodeDepth(5); parser.AssertPath("//doc/tag.a/tag.b/tag.b"); }, delegate { parser.AssertStateIs <XmlRootState> (); parser.AssertNodeDepth(2); parser.AssertPath("//doc"); } ); parser.AssertEmpty(); parser.AssertErrorCount(2); }
public void AssertAttributeValue(string doc, string val) { TestXmlParser.Parse(doc, p => { p.AssertStateIs <XmlAttributeValueState> (); Assert.AreEqual(val, p.GetContext().KeywordBuilder.ToString()); }); }
public void Misc() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <!DOCTYPE $ > <![CDATA[ ] $ ] ]]> <!-- <foo> <bar arg=""> $ --> </doc> ", delegate { parser.AssertStateIs <XmlDocTypeState> (); parser.AssertNodeDepth(3); parser.AssertPath("//doc/<!DOCTYPE>"); }, delegate { parser.AssertStateIs <XmlCDataState> (); parser.AssertNodeDepth(3); parser.AssertPath("//doc/<![CDATA[ ]]>"); }, delegate { parser.AssertStateIs <XmlCommentState> (); parser.AssertNodeDepth(3); parser.AssertPath("//doc/<!-- -->"); } ); parser.AssertEmpty(); parser.AssertErrorCount(0); }
public void DocTypeCapture() { var parser = new TestXmlParser(CreateRootState(), true); parser.Parse(@" <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""DTD/xhtml1-strict.dtd"" [ <!-- foo --> <!bar #baz> ]> <doc><foo/></doc>"); parser.AssertEmpty(); XDocument doc = (XDocument)parser.Nodes.Peek(); Assert.IsTrue(doc.FirstChild is XDocType); XDocType dt = (XDocType)doc.FirstChild; Assert.AreEqual("html", dt.RootElement.FullName); Assert.AreEqual("-//W3C//DTD XHTML 1.0 Strict//EN", dt.PublicFpi); Assert.AreEqual("DTD/xhtml1-strict.dtd", dt.Uri); Assert.AreEqual(dt.InternalDeclarationRegion.Begin.Line, 4); Assert.AreEqual(dt.InternalDeclarationRegion.End.Line, 7); parser.AssertNoErrors(); }
public void IncompleteTags() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <tag.a att1 > <tag.b att2="" > <tag.c att3 = ' <tag.d att4 = > <tag.e att5='' att6=' att7 = > <tag.f id='$foo' /> </tag.e> </tag.d> </tag.c> </tag.b> </tag.a> </doc> ", delegate { parser.AssertStateIs <XmlAttributeValueState> (); parser.AssertNodeDepth(9); parser.AssertPath("//doc/tag.a/tag.b/tag.c/tag.d/tag.e/tag.f/@id"); } ); parser.AssertEmpty(); parser.AssertErrorCount(5, x => x.ErrorType == ErrorType.Error); }
public void IncompleteTags() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <tag.a att1 > <tag.b att2="" > <tag.c att3 = ' <tag.d $ att4 = > <tag.e att5='' att6=' att7 = > <tag.f id='$foo' /> </tag.e> </tag.d> </tag.c> </tag.b> </tag.a> </doc> ", delegate { parser.AssertStateIs <XmlTagState> (); Assert.IsFalse(parser.Nodes.Peek(1).IsComplete); parser.AssertNodeDepth(6); parser.AssertPath("//doc/tag.a/tag.b/tag.c/tag.d"); }, delegate { parser.AssertStateIs <XmlAttributeValueState> (); parser.AssertNodeDepth(9); Assert.IsTrue(parser.Nodes.Peek(3) is XElement eld && eld.Name.Name == "tag.d" && eld.IsComplete); Assert.IsTrue(parser.Nodes.Peek(2) is XElement ele && ele.Name.Name == "tag.e" && !ele.IsComplete); Assert.IsTrue(parser.Nodes.Peek(1) is XElement elf && elf.Name.Name == "tag.f" && !elf.IsComplete); Assert.IsTrue(parser.Nodes.Peek() is XAttribute att && !att.IsComplete); parser.AssertPath("//doc/tag.a/tag.b/tag.c/tag.d/tag.e/tag.f/@id"); }
static void NotAttribute(string doc) { TestXmlParser.Parse(doc, p => { var att = p.PeekSpine() as XAttribute; Assert.IsNull(att); }); }
static void NotAttribute(string doc) { TestXmlParser.AssertState(doc, p => { var att = p.Nodes.FirstOrDefault() as XAttribute; Assert.IsNull(att); }); }
public void OutOfStartTagPathTest1() { TestXmlParser.AssertState( "<foo xmlns='" + namespaceURI + "'> $", p => p.AssertStateIs <XmlRootState> () ); }
public void AssertAttributeName(string doc, string name) { TestXmlParser.AssertState(doc, p => { var att = p.Nodes.First() as XAttribute; Assert.NotNull(att); Assert.AreEqual(name, GetName(p)); }); }
public void BadClosingTag() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@"<doc><x><abc></ab c><cd></cd></x></doc>"); parser.AssertEmpty(); parser.AssertErrorCount(2); }
public void AssertAttributeName(string doc, string name) { TestXmlParser.Parse(doc, p => { var att = p.PeekSpine() as XAttribute; Assert.NotNull(att); Assert.AreEqual(name, GetName(p)); }); }
public void ClosingTagWithWhitespace() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@"<doc><a></ a></doc >"); parser.AssertEmpty(); parser.AssertErrorCount(0); }
public void AssertParentPath(string doc, params QualifiedName[] qualifiedNames) { TestXmlParser.AssertState(doc, p => Assert.AreEqual( new XmlElementPath(qualifiedNames), XmlElementPath.Resolve(p.Nodes.ToArray()) ) );; }
static void AssertAttributeName(string doc, string name) { TestXmlParser.AssertState(doc, p => { var att = p.Nodes.FirstOrDefault() as XAttribute; Assert.NotNull(att); Assert.NotNull(att.Name); Assert.IsNull(att.Name.Prefix); Assert.AreEqual(att.Name.Name, name); }); }
static void AssertAttributeName(string doc, string name) { TestXmlParser.Parse(doc, p => { var att = p.PeekSpine() as XAttribute; Assert.NotNull(att); Assert.NotNull(att.Name); Assert.IsNull(att.Name.Prefix); Assert.AreEqual(att.Name.Name, name); }); }
public void PathTest1() { TestXmlParser.AssertTree( "<foo xmlns='" + namespaceURI + "'$><bar>", n => TestXmlParser.AssertPath( n, new QualifiedName("foo", namespaceURI) ) ); }
public void PathTest10() { TestXmlParser.AssertTree( "<foo xmlns='" + namespaceURI + "'><bar $Id=\r\n</foo>", n => TestXmlParser.AssertPath( n, new QualifiedName("foo", namespaceURI), new QualifiedName("bar", namespaceURI) ) ); }
static void AssertElementPath(string text, params QualifiedName[] qualifiedNames) { TestXmlParser.AssertState(text, p => { var arr = p.Nodes.ToArray(); Array.Reverse(arr); Assert.AreEqual( new XmlElementPath(qualifiedNames), XmlElementPath.Resolve(arr) ); }); }
public void PathTest9() { TestXmlParser.AssertTree( "<foo xmlns='" + namespaceURI + "'><bar \n\n hi='$'>", n => TestXmlParser.AssertPath( n, new QualifiedName("foo", namespaceURI), new QualifiedName("bar", namespaceURI) ) ); }
public void PathTest7() { TestXmlParser.Parse( "<foo xmlns='" + namespaceURI + "'><bar a='a' $>", n => TestXmlParser.AssertPath( n, new QualifiedName("foo", namespaceURI), new QualifiedName("bar", namespaceURI) ) ); }
public static void AssertTree(string txt, params Action <XNode>[] asserts) { var p = new TestXmlParser(new XmlRootState(), true); //parse and capture line/col info var list = new List <TextLocation> (); p.Parse(txt, Array.ConvertAll(asserts, a => (Action)(() => list.Add(p.Location)))); var doc = (XDocument)p.Nodes.Last(); for (int i = 0; i < asserts.Length; i++) { asserts [i] (doc.AllDescendentNodes.FirstOrDefault(n => n.Region.IsInside(list[i]))); } }
public void AssertIsNamespaceDeclaration(string doc) { TestXmlParser.AssertState(doc, p => { var node = p.Nodes.FirstOrDefault() as XAttribute; Assert.NotNull(node); Assert.IsTrue(node.IsNamed); if (node.Name.HasPrefix) { Assert.AreEqual("xmlns", node.Name.Prefix); } else { Assert.AreEqual("xmlns", node.Name.Name); } }); }
public void AssertNotNamespaceDeclaration(string doc) { TestXmlParser.Parse(doc, p => { var node = p.PeekSpine() as XAttribute; if (node != null && node.IsNamed) { if (node.Name.HasPrefix) { Assert.AreNotEqual("xmlns", node.Name.Prefix); } else { Assert.AreNotEqual("xmlns", node.Name.Name); } } }); }
public void Attributes() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <tag.a name=""foo"" arg=5 wibble = 6 bar.baz = 'y.ff7]' $ /> </doc> ", delegate { parser.AssertStateIs <XmlTagState> (); parser.AssertAttributes("name", "foo", "arg", "5", "wibble", "6", "bar.baz", "y.ff7]"); } ); parser.AssertEmpty(); parser.AssertErrorCount(0); }
public void AttributeName() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <tag.a> <tag.b id=""$foo"" /> </tag.a> </doc> ", delegate { parser.AssertStateIs <XmlAttributeValueState> (); parser.AssertPath("//doc/tag.a/tag.b/@id"); } ); parser.AssertEmpty(); parser.AssertErrorCount(0); }
public void NamespacedAttributes() { var parser = new TestXmlParser(CreateRootState(), true); parser.Parse(@"<tag foo:bar='1' foo:bar:baz='2' foo='3' />"); parser.AssertEmpty(); var doc = (XDocument)parser.Nodes.Peek(); var el = (XElement)doc.FirstChild; Assert.AreEqual(3, el.Attributes.Count()); Assert.AreEqual("foo", el.Attributes.ElementAt(0).Name.Prefix); Assert.AreEqual("bar", el.Attributes.ElementAt(0).Name.Name); Assert.AreEqual("foo", el.Attributes.ElementAt(1).Name.Prefix); Assert.AreEqual("bar:baz", el.Attributes.ElementAt(1).Name.Name); Assert.IsNull(el.Attributes.ElementAt(2).Name.Prefix); Assert.AreEqual("foo", el.Attributes.ElementAt(2).Name.Name); Assert.AreEqual(3, el.Attributes.Count()); parser.AssertErrorCount(1); Assert.AreEqual(1, parser.Errors [0].Region.Begin.Line); Assert.AreEqual(26, parser.Errors [0].Region.Begin.Column); }
public void AttributeRecovery() { var parser = new TestXmlParser(CreateRootState()); parser.Parse(@" <doc> <tag.a> <tag.b arg='fff' sdd = sdsds= 'foo' ff = 5 $ /> </tag.a> <a><b valid/></a> </doc> ", delegate { parser.AssertStateIs <XmlTagState> (); parser.AssertAttributes("arg", "fff", "sdd", "sdsds", "ff", "5"); parser.AssertErrorCount(3); } ); parser.AssertEmpty(); parser.AssertErrorCount(4); }
public void FailureTest1() { TestXmlParser.Parse("<a foo=''$", p => Assert.IsNull(p.GetContext().Nodes.LastOrDefault() as XAttribute)); }
public void AssertNotInsideAttributeValue(string doc) { TestXmlParser.Parse(doc, p => p.AssertStateIsNot <XmlAttributeValueState> ()); }