require File.join(File.dirname(__FILE__), 'preamble') require 'html5/liberalxmlparser' XMLELEM = /<(\w+\s*)((?:[-:\w]+="[^"]*"\s*)+)(\/?)>/ def assert_xml_equal(input, expected=nil, parser=HTML5::XMLParser) sortattrs = proc {"<#{$1+$2.split.sort.join(' ')+$3}>"} document = parser.parse(input.chomp, :lowercase_attr_name => false, :lowercase_element_name => false).root if not expected expected = input.chomp.gsub(XMLELEM,&sortattrs) expected = expected.gsub(/&#(\d+);/) {[$1.to_i].pack('U')} output = document.to_s.gsub(/'/,'"').gsub(XMLELEM,&sortattrs) assert_equal(expected, output) else assert_equal(expected, document.to_s.gsub(/'/,'"')) end end def assert_xhtml_equal(input, expected=nil, parser=HTML5::XHTMLParser) assert_xml_equal(input, expected, parser) end class BasicXhtml5Test < Test::Unit::TestCase def test_title_body_mismatched_close assert_xhtml_equal( 'Xhtmlcontent', '' + 'Xhtml' + 'content' + '') end def test_title_body_named_charref assert_xhtml_equal( 'ntildeA ñ B', '' + 'ntilde' + 'A '+ [0xF1].pack('U') + ' B' + '') end end class BasicXmlTest < Test::Unit::TestCase def test_comment assert_xml_equal("") end def test_cdata assert_xml_equal("","foo") end def test_simple_text assert_xml_equal("

foo

","

foo

") end def test_optional_close assert_xml_equal("

foo","

foo

") end def test_html_mismatched assert_xml_equal("foo","foo") end end class OpmlTest < Test::Unit::TestCase def test_mixedCaseElement assert_xml_equal( '' + 'Dave Winer' + '') end def test_mixedCaseAttribute assert_xml_equal( '' + '' + '') end def test_malformed assert_xml_equal( '' + '' + '', '' + '' + '') end end class XhtmlTest < Test::Unit::TestCase def test_mathml assert_xhtml_equal < MathML x = - b ± b 2 - 4 a c 2 a EOX end def test_svg assert_xhtml_equal < SVG EOX end def test_xlink assert_xhtml_equal < XLINK EOX end def test_br assert_xhtml_equal < BR
EOX1 end def test_strong assert_xhtml_equal < STRONG EOX end def test_script assert_xhtml_equal < SCRIPT EOX end def test_script_src assert_xhtml_equal < SCRIPT EOX1 SCRIPT EOX2 end def test_title assert_xhtml_equal < 1 < 2 & 3 EOX end def test_prolog assert_xhtml_equal < PROLOG EOX1 PROLOG EOX2 end def test_tagsoup assert_xhtml_equal < TAGSOUP

EOX1 TAGSOUP

EOX2 end end