Skip to content

Instantly share code, notes, and snippets.

@maclover7
Last active November 17, 2016 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maclover7/4b7d1ccf4358f13bcc43d0037e48b9be to your computer and use it in GitHub Desktop.
Save maclover7/4b7d1ccf4358f13bcc43d0037e48b9be to your computer and use it in GitHub Desktop.

jruby: jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.112-b16 on 1.8.0_112-b16 +jit [darwin-x86_64]

test_children_with_simple_cdata

Input:

    <root>
      <products>
         <![CDATA[cdatablock]]>
      </products>
    </root>

Output:

--- expected
+++ actual
@@ -1,3 +1,3 @@
-{"root"=>{"products"=>{"__content__"=>"
-         cdatablock
+{"root"=>{"products"=>{"__content__"=>"cdatablock
+         
       "}}}

test_children_with_multiple_cdata

Input:

    <root>
      <products>
         <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
      </products>
    </root>

Output:

--- expected
+++ actual
@@ -1,3 +1,3 @@
-{"root"=>{"products"=>{"__content__"=>"
-         cdatablock1cdatablock2
+{"root"=>{"products"=>{"__content__"=>"cdatablock1cdatablock2
+         
       "}}}

test_children_with_text_and_cdata

Input:

    <root>
      <products>
        hello <![CDATA[cdatablock]]>
        morning
      </products>
    </root>

Output:

--- expected
+++ actual
@@ -1,4 +1,4 @@
-{"root"=>{"products"=>{"__content__"=>"
-        hello cdatablock
+{"root"=>{"products"=>{"__content__"=>"cdatablock
+        hello 
         morning
       "}}}
require "abstract_unit"
require "active_support/xml_mini"
require "active_support/core_ext/hash/conversions"
class NokogiriSAXEngineTest < ActiveSupport::TestCase
def setup
@default_backend = ActiveSupport::XmlMini.backend
ActiveSupport::XmlMini.backend = "NokogiriSAX"
end
def teardown
ActiveSupport::XmlMini.backend = @default_backend
end
def test_children_with_simple_cdata
assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock]]>
</products>
</root>
eoxml
end
def test_children_with_multiple_cdata
assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
</products>
</root>
eoxml
end
def test_children_with_text_and_cdata
assert_equal_rexml(<<-eoxml)
<root>
<products>
hello <![CDATA[cdatablock]]>
morning
</products>
</root>
eoxml
end
private
def assert_equal_rexml(xml)
parsed_xml = ActiveSupport::XmlMini.parse(xml)
xml.rewind if xml.respond_to?(:rewind)
hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) }
assert_equal(hash, parsed_xml)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment