public void Format_CodeCommentAroundMarkup_ReturnsSingleUnparsedBlock() { var input = new[] { MarkupGrammar.TokenUnparsed("%--", "--%", @" <html> <body style=""color:lime""> <!-- not much to say here --> </body> </html> ") }; const string expected = @"<%-- <html> <body style=""color:lime""> <!-- not much to say here --> </body> </html> --%>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_XmlContent_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("div")), MarkupGrammar.TokenAttribute(new DataName("class")), MarkupGrammar.TokenPrimitive("content"), MarkupGrammar.TokenElementBegin(new DataName("p")), MarkupGrammar.TokenAttribute(new DataName("style")), MarkupGrammar.TokenPrimitive("color:red"), MarkupGrammar.TokenElementBegin(new DataName("strong")), MarkupGrammar.TokenPrimitive("Lorem ipsum"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive(" dolor sit amet, "), MarkupGrammar.TokenElementBegin(new DataName("i")), MarkupGrammar.TokenPrimitive("consectetur"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive(" adipiscing elit."), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, }; const string expected = @"<div class=""content""><p style=""color:red""><strong>Lorem ipsum</strong> dolor sit amet, <i>consectetur</i> adipiscing elit.</p></div>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_EmptyInput_ReturnsEmptySequence() { var input = new Token <MarkupTokenType> [0]; const string expected = ""; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_XmlComment_ReturnsUnparsed() { var input = new[] { MarkupGrammar.TokenUnparsed("!--", "--", @" a quick note ") }; const string expected = @"<!-- a quick note -->"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_UnclosedOpenTag_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("root")) }; const string expected = @"<root />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_MixedEntities_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenPrimitive(@"there should <b>e decoded chars & inside this text") }; const string expected = @"there should <b>e decoded chars & inside this text"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_XmlEntityEuro_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenPrimitive("€") }; const string expected = "€"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_MarkupLikeText_ReturnsTextValue() { var input = new[] { MarkupGrammar.TokenPrimitive(@"value>""0"" && value<""10"" ?""valid"":""error""") }; const string expected = @"value>""0"" && value<""10"" ?""valid"":""error"""; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_AspNetPageDeclaration_ReturnsUnparsed() { var input = new[] { MarkupGrammar.TokenUnparsed("%@", "%", @" Page Language=""C#"" AutoEventWireup=""true"" CodeBehind=""Default.aspx.cs"" Inherits=""Foo._Default"" ") }; const string expected = @"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeBehind=""Default.aspx.cs"" Inherits=""Foo._Default"" %>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_XmlDeclaration_ReturnsUnparsed() { var input = new[] { MarkupGrammar.TokenUnparsed("?", "?", @"xml version=""1.0""") }; const string expected = @"<?xml version=""1.0""?>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_EntityWithTrailingText_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenPrimitive("&"), MarkupGrammar.TokenPrimitive("trailing") }; const string expected = @"&trailing"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_NamespacePrefixTag_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("root", "prefix", "http://example.com/schema")), MarkupGrammar.TokenElementEnd, }; const string expected = @"<prefix:root xmlns:prefix=""http://example.com/schema"" />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_SingleAttributeWhitespace_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("root")), MarkupGrammar.TokenAttribute(new DataName("whitespace")), MarkupGrammar.TokenPrimitive(" this contains whitespace "), MarkupGrammar.TokenElementEnd }; const string expected = @"<root whitespace="" this contains whitespace "" />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_SingleAttributeEmptyValue_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("root")), MarkupGrammar.TokenAttribute(new DataName("emptyValue")), MarkupGrammar.TokenPrimitive(String.Empty), MarkupGrammar.TokenElementEnd }; const string expected = @"<root emptyValue="""" />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_ParentAndAttributeDifferentNamespaces_CorrectlyEmitsNamespaces() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("foo", String.Empty, "http://json.org")), MarkupGrammar.TokenAttribute(new DataName("key", String.Empty, "http://jsonfx.net", true)), MarkupGrammar.TokenPrimitive("value"), MarkupGrammar.TokenElementEnd, }; var expected = @"<foo p1:key=""value"" xmlns:p1=""http://jsonfx.net"" xmlns=""http://json.org"" />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_UnopenedCloseTag_ThrowsTokenException() { var input = new [] { MarkupGrammar.TokenElementEnd }; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); TokenException <MarkupTokenType> ex = Assert.Throws <TokenException <MarkupTokenType> >( delegate() { var actual = formatter.Format(input); }); Assert.Equal(input[0], ex.Token); }
public void Format_MathML_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("p")), MarkupGrammar.TokenPrimitive(@"You can add a string to a number, but this stringifies the number:"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n"), MarkupGrammar.TokenElementBegin(new DataName("math")), MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("ms")), MarkupGrammar.TokenPrimitive(@"x<y"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("mo")), MarkupGrammar.TokenPrimitive(@"+"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("mn")), MarkupGrammar.TokenPrimitive(@"3"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("mo")), MarkupGrammar.TokenPrimitive(@"="), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("ms")), MarkupGrammar.TokenPrimitive(@"x<y3"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n"), MarkupGrammar.TokenElementEnd, }; const string expected = @"<p>You can add a string to a number, but this stringifies the number:</p> <math> <ms>x<y</ms> <mo>+</mo> <mn>3</mn> <mo>=</mo> <ms>x<y3</ms> </math>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_NamespacedChildTag_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("foo")), MarkupGrammar.TokenElementBegin(new DataName("child", String.Empty, "http://example.com/schema")), MarkupGrammar.TokenPrimitive("value"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd }; const string expected = @"<foo><child xmlns=""http://example.com/schema"">value</child></foo>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_ParentAndChildDifferentDefaultNamespaces_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("foo", String.Empty, "http://json.org")), MarkupGrammar.TokenElementBegin(new DataName("child", String.Empty, "http://jsonfx.net")), MarkupGrammar.TokenPrimitive("text value"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, }; const string expected = @"<foo xmlns=""http://json.org""><child xmlns=""http://jsonfx.net"">text value</child></foo>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_ParentAndChildSharePrefixedNamespace_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("foo", "bar", "http://example.org")), MarkupGrammar.TokenElementBegin(new DataName("child", "bar", "http://example.org")), MarkupGrammar.TokenPrimitive("value"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, }; const string expected = @"<bar:foo xmlns:bar=""http://example.org""><bar:child>value</bar:child></bar:foo>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_OverlappingTags_ReturnsBalanced() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("odd")), MarkupGrammar.TokenElementBegin(new DataName("auto-closed")), MarkupGrammar.TokenElementBegin(new DataName("even")), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd }; const string expected = @"<odd><auto-closed><even /></auto-closed></odd>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_NamespacedTags_ReturnsBalanced() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("odd", "a", "http://example.com/odd/a")), MarkupGrammar.TokenElementBegin(new DataName("auto-closed", "b", "http://example.com/auto-closed/b")), MarkupGrammar.TokenElementBegin(new DataName("even", "c", "http://example.com/even/c")), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, }; const string expected = @"<a:odd xmlns:a=""http://example.com/odd/a""><b:auto-closed xmlns:b=""http://example.com/auto-closed/b""><c:even xmlns:c=""http://example.com/even/c"" /></b:auto-closed></a:odd>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_XmlDocTypeExternal_ReturnsUnparsed() { var input = new[] { MarkupGrammar.TokenUnparsed("!", "", @"DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd""" ) }; const string expected = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">" ; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_MultipleAttributes_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementVoid(new DataName("root")), MarkupGrammar.TokenAttribute(new DataName("no-value")), MarkupGrammar.TokenPrimitive(String.Empty), MarkupGrammar.TokenAttribute(new DataName("whitespace")), MarkupGrammar.TokenPrimitive(" this contains whitespace "), MarkupGrammar.TokenAttribute(new DataName("anyQuotedText")), MarkupGrammar.TokenPrimitive("/\\\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?") }; const string expected = @"<root no-value="""" whitespace="" this contains whitespace "" anyQuotedText=""/\" + "\uCAFE\uBABE\uAB98\uFCDE\uBCDA\uEF4A\n\r\t" + @"`1~!@#$%^&*()_+-=[]{}|;:',./<>?"" />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
//[Fact(Skip="Embedded DOCTYPE not supported")] public void Format_XmlDocTypeLocal_ReturnsUnparsed() { var input = new[] { MarkupGrammar.TokenUnparsed("!", "", @"DOCTYPE doc [ <!ATTLIST normId id ID #IMPLIED> <!ATTLIST normNames attr NMTOKENS #IMPLIED> ]") }; const string expected = @"<!DOCTYPE doc [ <!ATTLIST normId id ID #IMPLIED> <!ATTLIST normNames attr NMTOKENS #IMPLIED> ]>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_DifferentPrefixSameNamespace_ReturnsMarkup() { // Not sure if this is correct: http://stackoverflow.com/questions/3312390 // "The namespace name for an unprefixed attribute name always has no value" // "The attribute value in a default namespace declaration MAY be empty. // This has the same effect, within the scope of the declaration, of there being no default namespace." // http://www.w3.org/TR/xml-names/#defaulting var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("foo", String.Empty, "http://example.org")), MarkupGrammar.TokenAttribute(new DataName("key", "blah", "http://example.org")), MarkupGrammar.TokenPrimitive("value"), MarkupGrammar.TokenElementEnd, }; const string expected = @"<foo blah:key=""value"" xmlns:blah=""http://example.org"" xmlns=""http://example.org"" />"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_NestedDefaultNamespaces_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("outer", String.Empty, "http://example.org/outer")), MarkupGrammar.TokenElementBegin(new DataName("middle-1", String.Empty, "http://example.org/inner")), MarkupGrammar.TokenElementBegin(new DataName("inner", String.Empty, "http://example.org/inner")), MarkupGrammar.TokenPrimitive("this should be inner"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementBegin(new DataName("middle-2", String.Empty, "http://example.org/outer")), MarkupGrammar.TokenPrimitive("this should be outer"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, }; const string expected = @"<outer xmlns=""http://example.org/outer""><middle-1 xmlns=""http://example.org/inner""><inner>this should be inner</inner></middle-1><middle-2>this should be outer</middle-2></outer>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }
public void Format_PhpHelloWorld_ReturnsMarkup() { var input = new[] { MarkupGrammar.TokenElementBegin(new DataName("html")), MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("head")), MarkupGrammar.TokenPrimitive("\r\n\t\t"), MarkupGrammar.TokenElementBegin(new DataName("title")), MarkupGrammar.TokenPrimitive("PHP Test"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementBegin(new DataName("body")), MarkupGrammar.TokenPrimitive("\r\n\t\t"), MarkupGrammar.TokenUnparsed("?", "?", @"php echo '<p>Hello World</p>'; "), MarkupGrammar.TokenPrimitive("\r\n\t"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenPrimitive("\r\n"), MarkupGrammar.TokenElementEnd, }; const string expected = @"<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>"; var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings()); var actual = formatter.Format(input); Assert.Equal(expected, actual); }