2007-06-05 23:34:49 +02:00
|
|
|
require File.join(File.dirname(__FILE__), 'preamble')
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
require 'html5/html5parser'
|
|
|
|
require 'html5/serializer'
|
|
|
|
require 'html5/treewalkers'
|
2007-06-05 23:34:49 +02:00
|
|
|
|
|
|
|
#Run the serialize error checks
|
|
|
|
checkSerializeErrors = false
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
class JsonWalker < HTML5::TreeWalkers::Base
|
2007-06-05 23:34:49 +02:00
|
|
|
def each
|
|
|
|
@tree.each do |token|
|
|
|
|
case token[0]
|
|
|
|
when 'StartTag'
|
|
|
|
yield startTag(token[1], token[2])
|
|
|
|
when 'EndTag'
|
|
|
|
yield endTag(token[1])
|
|
|
|
when 'EmptyTag'
|
|
|
|
yield emptyTag(token[1], token[2])
|
|
|
|
when 'Comment'
|
|
|
|
yield comment(token[1])
|
|
|
|
when 'Characters', 'SpaceCharacters'
|
|
|
|
text(token[1]) {|textToken| yield textToken}
|
|
|
|
when 'Doctype'
|
|
|
|
yield doctype(token[1])
|
|
|
|
else
|
2007-06-14 06:05:15 +02:00
|
|
|
raise "Unknown token type: " + token[0]
|
2007-06-05 23:34:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Html5SerializeTestcase < Test::Unit::TestCase
|
2007-07-05 00:36:59 +02:00
|
|
|
html5_test_files('serializer').each do |filename|
|
2007-06-05 23:34:49 +02:00
|
|
|
test_name = File.basename(filename).sub('.test', '')
|
|
|
|
tests = JSON::parse(open(filename).read)
|
|
|
|
tests['tests'].each_with_index do |test, index|
|
|
|
|
|
|
|
|
define_method "test_#{test_name}_#{index+1}" do
|
2007-06-14 06:05:15 +02:00
|
|
|
if test["options"] and test["options"]["encoding"]
|
|
|
|
test["options"][:encoding] = test["options"]["encoding"]
|
|
|
|
end
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
result = HTML5::HTMLSerializer.
|
2007-06-05 23:34:49 +02:00
|
|
|
serialize(JsonWalker.new(test["input"]), (test["options"] || {}))
|
|
|
|
expected = test["expected"]
|
|
|
|
if expected.length == 1
|
|
|
|
assert_equal(expected[0], result, test["description"])
|
|
|
|
elsif !expected.include?(result)
|
|
|
|
flunk("Expected: #{expected.inspect}, Received: #{result.inspect}")
|
|
|
|
end
|
2007-06-22 10:12:08 +02:00
|
|
|
|
|
|
|
return if test_name == 'optionaltags'
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
result = HTML5::XHTMLSerializer.
|
2007-06-22 10:12:08 +02:00
|
|
|
serialize(JsonWalker.new(test["input"]), (test["options"] || {}))
|
|
|
|
expected = test["xhtml"] || test["expected"]
|
|
|
|
if expected.length == 1
|
|
|
|
assert_equal(expected[0], result, test["description"])
|
|
|
|
elsif !expected.include?(result)
|
|
|
|
flunk("Expected: #{expected.inspect}, Received: #{result.inspect}")
|
|
|
|
end
|
|
|
|
|
2007-06-05 23:34:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|