diff --git a/lib/stimulus_reflex/html/document_fragment.rb b/lib/stimulus_reflex/html/document_fragment.rb index 7ad6879f..ea1b6a5b 100644 --- a/lib/stimulus_reflex/html/document_fragment.rb +++ b/lib/stimulus_reflex/html/document_fragment.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -# forzen_string_literal: true - module StimulusReflex module HTML class DocumentFragment < Document diff --git a/test/html/document_fragment_test.rb b/test/html/document_fragment_test.rb index d386fbc9..848eff64 100644 --- a/test/html/document_fragment_test.rb +++ b/test/html/document_fragment_test.rb @@ -35,6 +35,520 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase assert_nil fragment.match("body").inner_html end + + test "should handle string" do + fragment = StimulusReflex::HTML::DocumentFragment.new("Some String") + + assert_equal "Some String", fragment.to_html + assert_equal "Some String", fragment.outer_html + assert_equal "Some String", fragment.inner_html + + assert_nil fragment.match("html").to_html + assert_nil fragment.match("html").outer_html + assert_nil fragment.match("html").inner_html + + assert_nil fragment.match("body").to_html + assert_nil fragment.match("body").outer_html + assert_nil fragment.match("body").inner_html + end + + test "should handle number" do + fragment = StimulusReflex::HTML::DocumentFragment.new(123) + + assert_equal "123", fragment.to_html + assert_equal "123", fragment.outer_html + assert_equal "123", fragment.inner_html + + assert_nil fragment.match("html").to_html + assert_nil fragment.match("html").outer_html + assert_nil fragment.match("html").inner_html + + assert_nil fragment.match("body").to_html + assert_nil fragment.match("body").outer_html + assert_nil fragment.match("body").inner_html + end + + test "should properly handle a tr without the parent table" do + html = "12" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal html, fragment.to_html.squish + end + + test "should properly handle a td without the parent table or td" do + html = "1" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal html, fragment.to_html.squish + end + + test "should properly parse " do + html = %(12) + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal %(12), fragment.to_html.squish + assert_equal %(12), fragment.outer_html.squish + assert_equal %(12), fragment.inner_html.squish + end + + test "should properly parse " do + html = "1" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal "1", fragment.to_html.squish + assert_equal "1", fragment.outer_html.squish + assert_equal "1", fragment.inner_html.squish + end + + test "should properly parse " do + html = "1" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal "1", fragment.to_html.squish + assert_equal "1", fragment.outer_html.squish + assert_equal "1", fragment.inner_html.squish + end + + test "should properly parse " do + html = "12" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal "12", fragment.to_html.squish + assert_equal "12", fragment.outer_html.squish + assert_equal "12", fragment.inner_html.squish + end + + test "should properly parse " do + html = "12" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal "12", fragment.to_html.squish + assert_equal "12", fragment.outer_html.squish + assert_equal "12", fragment.inner_html.squish + end + + test "should properly parse " do + html = "12" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal "12", fragment.to_html.squish + assert_equal "12", fragment.outer_html.squish + assert_equal "12", fragment.inner_html.squish + end + + test "should properly parse " do + html = "Caption" + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal "Caption", fragment.to_html.squish + assert_equal "Caption", fragment.outer_html.squish + assert_equal "Caption", fragment.inner_html.squish + end + + test "should properly parse and " do + html = %( + + + + + + ) + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal %( ), fragment.to_html.squish + assert_equal %( ), fragment.outer_html.squish + assert_equal %( ), fragment.inner_html.squish + end + + test "should properly parse " do + html = %( + + ) + fragment = StimulusReflex::HTML::DocumentFragment.new(html) + + assert_equal %(), fragment.to_html.squish + assert_equal %(), fragment.outer_html.squish + end + + test "should properly parse