require File.join(File.dirname(__FILE__), 'preamble') require 'html5lib/liberalxmlparser' XMLELEM = /<(\w+\s*)((?:[-:\w]+="[^"]*"\s*)+)(\/?)>/ SORTATTRS = '<#{$1+$2.split.sort.join(' ')+$3}>' def assert_xml_equal(input, expected=nil, parser=HTML5lib::XMLParser) document = parser.parse(input.chomp).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=HTML5lib::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( 'mdashA &mdash B', '' + 'mdash' + 'A '+ [0x2014].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 < XLINK
EOX1 end def xtest_strong assert_xhtml_equal < XLINK EOX end end