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)).
|
2007-08-30 19:19:10 +02:00
|
|
|
each_with_index do |(input, errors, inner_html, expected), index|
|
2007-07-05 00:36:59 +02:00
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
errors = errors.split("\n")
|
2007-07-05 00:36:59 +02:00
|
|
|
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
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
if inner_html
|
|
|
|
parser.parse_fragment(input, inner_html)
|
2007-05-30 17:45:52 +02:00
|
|
|
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")
|
|
|
|
|
2007-09-10 05:26:19 +02:00
|
|
|
actual_errors = parser.errors.map do |(line, col), message, datavars|
|
|
|
|
'Line: %i Col: %i %s' % [line, col, E[message] % datavars]
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-08-30 19:19:10 +02:00
|
|
|
assert_equal errors.length, parser.errors.length, [
|
|
|
|
'', 'Input', input,
|
|
|
|
'', "Expected errors (#{errors.length}):", errors.join("\n"),
|
|
|
|
'', "Actual errors (#{actual_errors.length}):",
|
|
|
|
actual_errors.join("\n")
|
|
|
|
].join("\n")
|
2007-05-30 17:45:52 +02:00
|
|
|
|
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
|