From cadb1f8c392eeff401c175d6c6c8bc6a1f068cd4 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 4 Jul 2024 09:44:08 -0400 Subject: [PATCH] test: run html5lib-tests in both script-on and script-off modes unless the test specifies one or the other. Closes #3242 --- test/html5/test_tree_construction.rb | 54 +++++++++++++++++++++------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/test/html5/test_tree_construction.rb b/test/html5/test_tree_construction.rb index 1e321b3eca..724ed9dba3 100644 --- a/test/html5/test_tree_construction.rb +++ b/test/html5/test_tree_construction.rb @@ -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] @@ -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? @@ -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)