public void DocTypeCapture() { TestParser parser = new TestParser(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 Unclosed() { TestParser parser = new TestParser(CreateRootState()); parser.Parse(@" <doc> <tag.a> <tag.b><tag.b>$ </tag.a>$ </doc> ", delegate { parser.AssertStateIs <XmlFreeState> (); parser.AssertNodeDepth(5); parser.AssertPath("//doc/tag.a/tag.b/tag.b"); }, delegate { parser.AssertStateIs <XmlFreeState> (); parser.AssertNodeDepth(2); parser.AssertPath("//doc"); } ); parser.AssertEmpty(); parser.AssertErrorCount(2); }
public void Misc() { TestParser parser = new TestParser(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 TestAutoClosing() { TestParser parser = new TestParser(CreateRootState()); parser.Parse(@" <html> <body> <p><img>$ <p><div> $ </div> <p> <p><a href =""http://mono-project.com/"" ><b>foo $ </a> <p> <p>$ </body> </html> ", delegate { parser.AssertPath("//html/body/p"); }, delegate { parser.AssertPath("//html/body/div"); }, delegate { parser.AssertPath("//html/body/p/a/b"); }, delegate { parser.AssertPath("//html/body/p"); } ); parser.AssertEmpty(); parser.AssertErrorCount(8); }
public void IncompleteTags() { TestParser parser = new TestParser(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 <XmlSingleQuotedAttributeValueState> (); parser.AssertNodeDepth(9); parser.AssertPath("//doc/tag.a/tag.b/tag.c/tag.d/tag.e/tag.f/@id"); } ); parser.AssertEmpty(); parser.AssertErrorCount(3, x => x.ErrorType == ErrorType.Error); parser.AssertErrorCount(2, x => x.ErrorType == ErrorType.Warning); }
public void TestHtmlImplicitClosing() { TestParser parser = new TestParser(CreateRootState()); parser.Parse(@" <html> <body> <li><li>$ <dt><img><dd>$</dd> <tr><tr>$</tr></li> <p> <table>$</table> <td><th><td>$ </body> </html> ", delegate { parser.AssertPath("//html/body/li"); }, delegate { parser.AssertPath("//html/body/li/dd"); }, delegate { parser.AssertPath("//html/body/li/tr"); }, delegate { parser.AssertPath("//html/body/table"); }, delegate { parser.AssertPath("//html/body/td"); } ); parser.AssertEmpty(); parser.AssertErrorCount(1); }
public void Attributes() { TestParser parser = new TestParser(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() { TestParser parser = new TestParser(CreateRootState()); parser.Parse(@" <doc> <tag.a> <tag.b id=""$foo"" /> </tag.a> </doc> ", delegate { parser.AssertStateIs <XmlDoubleQuotedAttributeValueState> (); parser.AssertPath("//doc/tag.a/tag.b/@id"); } ); parser.AssertEmpty(); parser.AssertErrorCount(0); }
public void Directives() { var parser = new TestParser(CreateRootState(), true); parser.Parse(@"<%@ Page Language=""C#"" Inherits=""SomeGenericType<int>"" %>"); parser.AssertNoErrors(); var doc = (XDocument)parser.Nodes.Peek(); var directive = doc.Nodes.First() as AspNetDirective; Assert.NotNull(directive); Assert.AreEqual("Page", directive.Name.FullName); Assert.AreEqual(2, directive.Attributes.Count()); var att = directive.Attributes[0]; Assert.AreEqual("Language", att.Name.FullName); Assert.AreEqual("C#", att.Value); att = directive.Attributes[1]; Assert.AreEqual("Inherits", att.Name.FullName); Assert.AreEqual("SomeGenericType<int>", att.Value); }
public void AttributeRecovery() { TestParser parser = new TestParser(CreateRootState()); parser.Parse(@" <doc> <tag.a> <tag.b arg='fff' sdd = sdsds= 'foo' ff $ /> </tag.a> <a><b valid/></a> </doc> ", delegate { parser.AssertStateIs <XmlTagState> (); parser.AssertAttributes("arg", "fff", "sdd", "", "sdsds", "foo", "ff", ""); parser.AssertErrorCount(1); } ); parser.AssertEmpty(); parser.AssertErrorCount(1); }
public void NamespacedAttributes() { var parser = new TestParser(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.BeginLine); Assert.AreEqual(25, parser.Errors [0].Region.BeginColumn); }
public void AttributeWithExpression() { var parser = new TestParser(CreateRootState(), true); parser.Parse(@"<tag foo='<%=5$%>' bar=""<%$$5$%><%--$--%>"" baz='<%#5$%>=<%:fhfjhf %0 $%>' quux = <% 5 $%> />", delegate { parser.AssertNodeIs <AspNetRenderExpression> (); }, delegate { parser.AssertNodeIs <AspNetResourceExpression> (); }, delegate { parser.AssertNodeIs <AspNetServerComment> (); }, delegate { parser.AssertNodeIs <AspNetDataBindingExpression> (); }, delegate { parser.AssertNodeIs <AspNetHtmlEncodedExpression> (); }, delegate { parser.AssertNodeIs <AspNetRenderBlock> (); }); parser.AssertNoErrors(); var doc = (XDocument)parser.Nodes.Peek(); }
public void SimpleTree() { var parser = new TestParser(CreateRootState(), true); parser.Parse(@" <doc> <a> <b> <c/> <d> <e/> </d> <f> <g/> </f> </b> </a> </doc>"); parser.AssertErrorCount(0); var doc = ((XDocument)parser.Nodes.Peek()).RootElement; Assert.NotNull(doc); Assert.AreEqual("doc", doc.Name.Name); Assert.True(doc.IsEnded); var a = (XElement)doc.FirstChild; Assert.NotNull(a); Assert.AreEqual("a", a.Name.Name); Assert.True(a.IsEnded); Assert.False(a.IsSelfClosing); Assert.IsNull(a.NextSibling); var b = (XElement)a.FirstChild; Assert.NotNull(b); Assert.AreEqual("b", b.Name.Name); Assert.True(b.IsEnded); Assert.False(b.IsSelfClosing); Assert.IsNull(b.NextSibling); var c = (XElement)b.FirstChild; Assert.NotNull(c); Assert.AreEqual("c", c.Name.Name); Assert.True(c.IsEnded); Assert.True(c.IsSelfClosing); Assert.IsNull(c.FirstChild); var d = (XElement)c.NextSibling; Assert.True(d.IsEnded); Assert.False(d.IsSelfClosing); Assert.AreEqual("d", d.Name.Name); var e = (XElement)d.FirstChild; Assert.NotNull(e); Assert.True(e.IsEnded); Assert.True(e.IsSelfClosing); Assert.AreEqual("e", e.Name.Name); var f = (XElement)d.NextSibling; Assert.AreEqual(f, b.LastChild); Assert.True(f.IsEnded); Assert.False(f.IsSelfClosing); Assert.AreEqual("f", f.Name.Name); var g = (XElement)f.FirstChild; Assert.NotNull(g); Assert.True(g.IsEnded); Assert.True(g.IsSelfClosing); Assert.AreEqual("g", g.Name.Name); }