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 = "
1
2
"
+ 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 = %(
1
2
)
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(
1
2
), fragment.to_html.squish
+ assert_equal %(
1
2
), fragment.outer_html.squish
+ assert_equal %(
1
2
), 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 = "
1
2
"
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal "
1
2
", fragment.to_html.squish
+ assert_equal "
1
2
", fragment.outer_html.squish
+ assert_equal "
1
2
", fragment.inner_html.squish
+ end
+
+ test "should properly parse " do
+ html = "
1
2
"
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal "
1
2
", fragment.to_html.squish
+ assert_equal "
1
2
", fragment.outer_html.squish
+ assert_equal "
1
2
", fragment.inner_html.squish
+ end
+
+ test "should properly parse " do
+ html = "
1
2
"
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal "
1
2
", fragment.to_html.squish
+ assert_equal "
1
2
", fragment.outer_html.squish
+ assert_equal "
1
2
", 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
" 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 two siblings input" do
+ html = %(
+
), fragment.outer_html.squish
+ end
+
+ test "should properly parse after non-closed " do
+ html = %(
+
+
+
+
+ After Input
+
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(
After Input
), fragment.to_html.squish
+ assert_equal %(
After Input
), fragment.outer_html.squish
+ end
+
+ test "non-closing tag with -> in attribute" do
+ html = %(
+
+ some text
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %( some text), fragment.to_html.squish
+ assert_equal %( some text), fragment.outer_html.squish
+ end
+
+ test "non-closing tag" do
+ html = %(
+
+ test
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %( test), fragment.to_html.squish
+ assert_equal %( test), fragment.outer_html.squish
+ end
+
+ test "non-closing tag" do
+ html = %(
+
+ test
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %( test), fragment.to_html.squish
+ assert_equal %( test), fragment.outer_html.squish
+ end
+
+ test "non-closing tag" do
+ html = %(
+
+ test
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(test), fragment.to_html.squish
+ assert_equal %(test), fragment.outer_html.squish
+ end
+
+ test "
), fragment.outer_html.squish
+ end
+
+ test "" do
+ html = %(
+ Title
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(Title), fragment.to_html.squish
+ assert_equal %(Title), fragment.outer_html.squish
+ end
+
+ test " in " do
+ html = %(
+
+ Title
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %( Title ), fragment.to_html.squish
+ assert_equal %( Title ), fragment.outer_html.squish
+ end
+
+ test "non-closed " do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "closed " do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "non-closed in " do
+ html = %(
+
+
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %( ), fragment.to_html.squish
+ assert_equal %( ), fragment.outer_html.squish
+ end
+
+ test "closed in " do
+ html = %(
+
+
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %( ), fragment.to_html.squish
+ assert_equal %( ), fragment.outer_html.squish
+ end
+
+ test "uppercase tags" do
+ html = %(
+
+
+
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(
), fragment.to_html.squish
+ assert_equal %(
), fragment.outer_html.squish
+ end
+
+ test "boolean attribute on
tag" do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "boolean attribute with attribute name as value on
tag" do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "boolean attribute on non-closed tag" do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "boolean attribute on closed tag" do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "boolean attribute with attribute name as value on non-closed tag" do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "boolean attribute with attribute name as value on closed tag" do
+ html = %(
+
+ )
+ fragment = StimulusReflex::HTML::DocumentFragment.new(html)
+
+ assert_equal %(), fragment.to_html.squish
+ assert_equal %(), fragment.outer_html.squish
+ end
+
+ test "should parse comments" do
+ html = %(
+
+