2007-05-26 03:52:27 +02:00
|
|
|
require File.join(File.dirname(__FILE__), 'preamble')
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
require 'html5/liberalxmlparser'
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
XMLELEM = /<(\w+\s*)((?:[-:\w]+="[^"]*"\s*)+)(\/?)>/
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
def assert_xml_equal(input, expected=nil, parser=HTML5::XMLParser)
|
|
|
|
sortattrs = proc {"<#{$1+$2.split.sort.join(' ')+$3}>"}
|
2007-08-30 19:19:10 +02:00
|
|
|
document = parser.parse(input.chomp, :lowercase_attr_name => false, :lowercase_element_name => false).root
|
2007-05-30 17:45:52 +02:00
|
|
|
if not expected
|
2007-07-05 00:36:59 +02:00
|
|
|
expected = input.chomp.gsub(XMLELEM,&sortattrs)
|
2008-01-21 18:59:55 +01:00
|
|
|
if expected.respond_to? :force_encoding
|
|
|
|
expected = expected.gsub(/&#(\d+);/) {$1.to_i.chr('utf-8')}
|
|
|
|
else
|
|
|
|
expected = expected.gsub(/&#(\d+);/) {[$1.to_i].pack('U')}
|
|
|
|
end
|
2007-07-05 00:36:59 +02:00
|
|
|
output = document.to_s.gsub(/'/,'"').gsub(XMLELEM,&sortattrs)
|
2007-05-30 17:45:52 +02:00
|
|
|
assert_equal(expected, output)
|
|
|
|
else
|
|
|
|
assert_equal(expected, document.to_s.gsub(/'/,'"'))
|
|
|
|
end
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
def assert_xhtml_equal(input, expected=nil, parser=HTML5::XHTMLParser)
|
2007-05-30 17:45:52 +02:00
|
|
|
assert_xml_equal(input, expected, parser)
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class BasicXhtml5Test < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_title_body_mismatched_close
|
|
|
|
assert_xhtml_equal(
|
|
|
|
'<title>Xhtml</title><b><i>content</b></i>',
|
|
|
|
'<html xmlns="http://www.w3.org/1999/xhtml">' +
|
2007-05-30 17:45:52 +02:00
|
|
|
'<head><title>Xhtml</title></head>' +
|
|
|
|
'<body><b><i>content</i></b></body>' +
|
2007-05-26 03:52:27 +02:00
|
|
|
'</html>')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_title_body_named_charref
|
|
|
|
assert_xhtml_equal(
|
2007-07-05 00:36:59 +02:00
|
|
|
'<title>ntilde</title>A ñ B',
|
2007-05-26 03:52:27 +02:00
|
|
|
'<html xmlns="http://www.w3.org/1999/xhtml">' +
|
2007-07-05 00:36:59 +02:00
|
|
|
'<head><title>ntilde</title></head>' +
|
|
|
|
'<body>A '+ [0xF1].pack('U') + ' B</body>' +
|
2007-05-26 03:52:27 +02:00
|
|
|
'</html>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BasicXmlTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_comment
|
|
|
|
assert_xml_equal("<x><!-- foo --></x>")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cdata
|
|
|
|
assert_xml_equal("<x><![CDATA[foo]]></x>","<x>foo</x>")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_simple_text
|
|
|
|
assert_xml_equal("<p>foo</p>","<p>foo</p>")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_optional_close
|
|
|
|
assert_xml_equal("<p>foo","<p>foo</p>")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_html_mismatched
|
|
|
|
assert_xml_equal("<b><i>foo</b></i>","<b><i>foo</i></b>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class OpmlTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_mixedCaseElement
|
|
|
|
assert_xml_equal(
|
|
|
|
'<opml version="1.0">' +
|
2007-05-30 17:45:52 +02:00
|
|
|
'<head><ownerName>Dave Winer</ownerName></head>' +
|
2007-05-26 03:52:27 +02:00
|
|
|
'</opml>')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mixedCaseAttribute
|
|
|
|
assert_xml_equal(
|
|
|
|
'<opml version="1.0">' +
|
2007-05-30 17:45:52 +02:00
|
|
|
'<body><outline isComment="true"/></body>' +
|
2007-05-26 03:52:27 +02:00
|
|
|
'</opml>')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_malformed
|
|
|
|
assert_xml_equal(
|
|
|
|
'<opml version="1.0">' +
|
2007-05-30 17:45:52 +02:00
|
|
|
'<body><outline text="Odds & Ends"/></body>' +
|
2007-05-26 03:52:27 +02:00
|
|
|
'</opml>',
|
|
|
|
'<opml version="1.0">' +
|
2007-05-30 17:45:52 +02:00
|
|
|
'<body><outline text="Odds & Ends"/></body>' +
|
2007-05-26 03:52:27 +02:00
|
|
|
'</opml>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class XhtmlTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_mathml
|
|
|
|
assert_xhtml_equal <<EOX
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>MathML</title></head>
|
|
|
|
<body>
|
|
|
|
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
2007-05-30 17:45:52 +02:00
|
|
|
<mrow>
|
|
|
|
<mi>x</mi>
|
|
|
|
<mo>=</mo>
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-05-30 17:45:52 +02:00
|
|
|
<mfrac>
|
|
|
|
<mrow>
|
|
|
|
<mrow>
|
|
|
|
<mo>-</mo>
|
|
|
|
<mi>b</mi>
|
|
|
|
</mrow>
|
|
|
|
<mo>±</mo>
|
|
|
|
<msqrt>
|
|
|
|
|
|
|
|
<mrow>
|
|
|
|
<msup>
|
|
|
|
<mi>b</mi>
|
|
|
|
<mn>2</mn>
|
|
|
|
</msup>
|
|
|
|
<mo>-</mo>
|
2007-05-26 03:52:27 +02:00
|
|
|
<mrow>
|
2007-05-30 17:45:52 +02:00
|
|
|
|
|
|
|
<mn>4</mn>
|
|
|
|
<mo>⁢</mo>
|
|
|
|
<mi>a</mi>
|
|
|
|
<mo>⁢</mo>
|
|
|
|
<mi>c</mi>
|
2007-05-26 03:52:27 +02:00
|
|
|
</mrow>
|
2007-05-30 17:45:52 +02:00
|
|
|
</mrow>
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-05-30 17:45:52 +02:00
|
|
|
</msqrt>
|
|
|
|
</mrow>
|
|
|
|
<mrow>
|
|
|
|
<mn>2</mn>
|
|
|
|
<mo>⁢</mo>
|
|
|
|
<mi>a</mi>
|
2007-05-26 03:52:27 +02:00
|
|
|
</mrow>
|
2007-05-30 17:45:52 +02:00
|
|
|
</mfrac>
|
|
|
|
|
|
|
|
</mrow>
|
2007-05-26 03:52:27 +02:00
|
|
|
</math>
|
|
|
|
</body></html>
|
|
|
|
EOX
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_svg
|
|
|
|
assert_xhtml_equal <<EOX
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>SVG</title></head>
|
|
|
|
<body>
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
2007-05-30 17:45:52 +02:00
|
|
|
<path d="M38,38c0-12,24-15,23-2c0,9-16,13-16,23v7h11v-4c0-9,17-12,17-27
|
|
|
|
c-2-22-45-22-45,3zM45,70h11v11h-11z" fill="#371">
|
|
|
|
</path>
|
|
|
|
<circle cx="50" cy="50" r="45" fill="none" stroke="#371" stroke-width="10">
|
|
|
|
</circle>
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
</svg>
|
|
|
|
</body></html>
|
|
|
|
EOX
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_xlink
|
|
|
|
assert_xhtml_equal <<EOX
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>XLINK</title></head>
|
|
|
|
<body>
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
2007-05-30 17:45:52 +02:00
|
|
|
<defs xmlns:l="http://www.w3.org/1999/xlink">
|
|
|
|
<radialGradient id="s1" fx=".4" fy=".2" r=".7">
|
|
|
|
<stop stop-color="#FE8"/>
|
|
|
|
<stop stop-color="#D70" offset="1"/>
|
|
|
|
</radialGradient>
|
|
|
|
<radialGradient id="s2" fx=".8" fy=".5" l:href="#s1"/>
|
|
|
|
<radialGradient id="s3" fx=".5" fy=".9" l:href="#s1"/>
|
|
|
|
<radialGradient id="s4" fx=".1" fy=".5" l:href="#s1"/>
|
|
|
|
</defs>
|
|
|
|
<g stroke="#940">
|
|
|
|
<path d="M73,29c-37-40-62-24-52,4l6-7c-8-16,7-26,42,9z" fill="url(#s1)"/>
|
|
|
|
<path d="M47,8c33-16,48,21,9,47l-6-5c38-27,20-44,5-37z" fill="url(#s2)"/>
|
|
|
|
<path d="M77,32c22,30,10,57-39,51l-1-8c3,3,67,5,36-36z" fill="url(#s3)"/>
|
|
|
|
|
|
|
|
<path d="M58,84c-4,20-38-4-8-24l-6-5c-36,43,15,56,23,27z" fill="url(#s4)"/>
|
|
|
|
<path d="M40,14c-40,37-37,52-9,68l1-8c-16-13-29-21,16-56z" fill="url(#s1)"/>
|
|
|
|
<path d="M31,33c19,23,20,7,35,41l-9,1.7c-4-19-8-14-31-37z" fill="url(#s2)"/>
|
|
|
|
</g>
|
2007-05-26 03:52:27 +02:00
|
|
|
</svg>
|
|
|
|
</body></html>
|
|
|
|
EOX
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_br
|
2007-06-22 10:12:08 +02:00
|
|
|
assert_xhtml_equal <<EOX1
|
2007-05-26 03:52:27 +02:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
2007-07-05 00:36:59 +02:00
|
|
|
<head><title>BR</title></head>
|
2007-05-26 03:52:27 +02:00
|
|
|
<body>
|
|
|
|
<br/>
|
|
|
|
</body></html>
|
2007-06-22 10:12:08 +02:00
|
|
|
EOX1
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
def test_strong
|
2007-05-26 03:52:27 +02:00
|
|
|
assert_xhtml_equal <<EOX
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
2007-07-05 00:36:59 +02:00
|
|
|
<head><title>STRONG</title></head>
|
2007-05-26 03:52:27 +02:00
|
|
|
<body>
|
|
|
|
<strong></strong>
|
|
|
|
</body></html>
|
|
|
|
EOX
|
|
|
|
end
|
2007-07-05 00:36:59 +02:00
|
|
|
|
|
|
|
def test_script
|
|
|
|
assert_xhtml_equal <<EOX
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>SCRIPT</title></head>
|
|
|
|
<body>
|
|
|
|
<script>1 < 2 & 3</script>
|
|
|
|
</body></html>
|
|
|
|
EOX
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_script_src
|
|
|
|
assert_xhtml_equal <<EOX1, <<EOX2.strip
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>SCRIPT</title><script src="http://example.com"/></head>
|
|
|
|
<body>
|
|
|
|
<script>1 < 2 & 3</script>
|
|
|
|
</body></html>
|
|
|
|
EOX1
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>SCRIPT</title><script src="http://example.com"></script></head>
|
|
|
|
<body>
|
|
|
|
<script>1 < 2 & 3</script>
|
|
|
|
</body></html>
|
|
|
|
EOX2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_title
|
|
|
|
assert_xhtml_equal <<EOX
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>1 < 2 & 3</title></head>
|
|
|
|
<body>
|
|
|
|
</body></html>
|
|
|
|
EOX
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prolog
|
|
|
|
assert_xhtml_equal <<EOX1, <<EOX2.strip
|
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>PROLOG</title></head>
|
|
|
|
<body>
|
|
|
|
</body></html>
|
|
|
|
EOX1
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>PROLOG</title></head>
|
|
|
|
<body>
|
|
|
|
</body></html>
|
2007-08-30 19:19:10 +02:00
|
|
|
EOX2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tagsoup
|
|
|
|
assert_xhtml_equal <<EOX1, <<EOX2.strip
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>TAGSOUP</title></head>
|
|
|
|
<body>
|
|
|
|
<u><blockquote><p></u>
|
|
|
|
</body></html>
|
|
|
|
EOX1
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head><title>TAGSOUP</title></head>
|
|
|
|
<body>
|
|
|
|
<u/><blockquote><u/><p><u/>
|
|
|
|
</p></blockquote></body></html>
|
2007-07-05 00:36:59 +02:00
|
|
|
EOX2
|
|
|
|
end
|
|
|
|
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|