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/treebuilders'
|
|
|
|
require 'html5/html5parser'
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
$tree_types_to_test = ['simpletree', 'rexml']
|
|
|
|
|
|
|
|
begin
|
2007-05-30 17:45:52 +02:00
|
|
|
require 'hpricot'
|
|
|
|
$tree_types_to_test.push('hpricot')
|
2007-05-26 03:52:27 +02:00
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
2007-06-22 10:12:08 +02:00
|
|
|
$CHECK_PARSER_ERRORS = ARGV.delete('-p') # TODO
|
2007-05-26 03:52:27 +02:00
|
|
|
|
2007-06-05 23:34:49 +02:00
|
|
|
puts 'Testing tree builders: ' + $tree_types_to_test * ', '
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Html5ParserTestCase < Test::Unit::TestCase
|
2007-07-05 00:36:59 +02:00
|
|
|
include HTML5
|
2007-06-05 23:34:49 +02:00
|
|
|
include TestSupport
|
2007-05-30 17:45:52 +02:00
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
html5_test_files('tree-construction').each do |test_file|
|
2007-05-30 17:45:52 +02:00
|
|
|
|
|
|
|
test_name = File.basename(test_file).sub('.dat', '')
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
TestData.new(test_file, %w(data errors document-fragment document)).
|
|
|
|
each_with_index do |(input, errors, innerHTML, expected), index|
|
|
|
|
|
|
|
|
expected = expected.gsub("\n| ","\n")[2..-1]
|
2007-05-30 17:45:52 +02:00
|
|
|
|
|
|
|
$tree_types_to_test.each do |tree_name|
|
|
|
|
define_method 'test_%s_%d_%s' % [ test_name, index + 1, tree_name ] do
|
|
|
|
|
2007-06-05 23:34:49 +02:00
|
|
|
parser = HTMLParser.new(:tree => TreeBuilders[tree_name])
|
2007-05-30 17:45:52 +02:00
|
|
|
|
|
|
|
if innerHTML
|
|
|
|
parser.parseFragment(input, innerHTML)
|
|
|
|
else
|
|
|
|
parser.parse(input)
|
|
|
|
end
|
|
|
|
|
|
|
|
actual_output = convertTreeDump(parser.tree.testSerializer(parser.tree.document))
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
assert_equal sortattrs(expected), sortattrs(actual_output), [
|
2007-06-22 10:12:08 +02:00
|
|
|
'', 'Input:', input,
|
2007-07-05 00:36:59 +02:00
|
|
|
'', 'Expected:', expected,
|
2007-06-22 10:12:08 +02:00
|
|
|
'', 'Recieved:', actual_output
|
2007-05-30 17:45:52 +02:00
|
|
|
].join("\n")
|
|
|
|
|
|
|
|
if $CHECK_PARSER_ERRORS
|
|
|
|
actual_errors = parser.errors.map do |(line, col), message|
|
|
|
|
'Line: %i Col: %i %s' % [line, col, message]
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
2007-07-05 00:36:59 +02:00
|
|
|
assert_equal errors.length, parser.errors.length, [
|
2007-06-13 00:37:55 +02:00
|
|
|
'Input', input + "\n",
|
2007-07-05 00:36:59 +02:00
|
|
|
'Expected errors:', errors.join("\n"),
|
2007-05-30 17:45:52 +02:00
|
|
|
'Actual errors:', actual_errors.join("\n")
|
|
|
|
].join("\n")
|
|
|
|
end
|
|
|
|
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-05-26 03:52:27 +02:00
|
|
|
end
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-05-26 03:52:27 +02:00
|
|
|
|
|
|
|
end
|