Skip to content

Commit

Permalink
test: run html5lib-tests in both script-on and script-off modes (#3277)
Browse files Browse the repository at this point in the history
**What problem is this PR intended to solve?**

run html5lib-tests in both script-on and script-off modes, unless the
test specifies one or the other.

Closes #3242
  • Loading branch information
flavorjones committed Jul 4, 2024
2 parents 5a10e95 + cadb1f8 commit 7942db6
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions test/html5/test_tree_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def compare_nodes(node, ng_node)
def run_test
options = {
max_errors: -1,
parse_noscript_content_as_text: @test[:script] == :on,
parse_noscript_content_as_text: @test_script_on,
}

if @test[:context]
Expand Down Expand Up @@ -166,7 +166,7 @@ module Html5libTestCaseParser
class BadHtml5libFormat < RuntimeError; end

def self.parse_test(test_data)
test = { script: :off }
test = { script: :both }
index = /(?:^#errors\n|\n#errors\n)/ =~ test_data
raise(BadHtml5libFormat, "Expected #errors in\n#{test_data}") if index.nil?

Expand Down Expand Up @@ -328,19 +328,47 @@ def self.generate_tests

klass = Class.new(TestHtml5TreeConstructionBase) do
tests.each_with_index do |test, index|
define_method "test_#{index}" do
@test = test
@index = index
@test_context_node = false
run_test
if test[:script] == :both || test[:script] == :off
define_method "test_#{index}__script_off" do
@test = test
@index = index
@test_script_on = false
@test_context_node = false
run_test
end
end

define_method "test_#{index}__with_node" do
@test = test
@index = index
@test_context_node = true
run_test
end if test[:context]
if test[:script] == :both || test[:script] == :on
define_method "test_#{index}__script_on" do
@test = test
@index = index
@test_script_on = true
@test_context_node = false
run_test
end
end

if test[:context]
if test[:script] == :both || test[:script] == :off
define_method "test_#{index}__script_off__with_node" do
@test = test
@index = index
@test_script_on = false
@test_context_node = true
run_test
end
end

if test[:script] == :both || test[:script] == :on
define_method "test_#{index}__script_on__with_node" do
@test = test
@index = index
@test_script_on = true
@test_context_node = true
run_test
end
end
end
end
end
Object.const_set(test_name, klass)
Expand Down

0 comments on commit 7942db6

Please sign in to comment.