From ce7244c6f251c815e09ba45bd909f06e9a41b8b1 Mon Sep 17 00:00:00 2001 From: David Smalley Date: Thu, 25 Jun 2009 08:25:10 +0100 Subject: [PATCH 1/2] Added tests for libxml XmlMini parser --- activesupport/test/xml_mini/libxml_ruby_test.rb | 130 +++++++++++++++++++++++ 1 files changed, 130 insertions(+), 0 deletions(-) create mode 100644 activesupport/test/xml_mini/libxml_ruby_test.rb diff --git a/activesupport/test/xml_mini/libxml_ruby_test.rb b/activesupport/test/xml_mini/libxml_ruby_test.rb new file mode 100644 index 0000000..378f9cc --- /dev/null +++ b/activesupport/test/xml_mini/libxml_ruby_test.rb @@ -0,0 +1,130 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +begin + gem 'libxml-ruby', '>= 1.1.3' +rescue Gem::LoadError + # Skip nokogiri tests +else + +require 'libxml' + +class LibxmlRubyTest < Test::Unit::TestCase + include ActiveSupport + + def setup + @default_backend = XmlMini.backend + XmlMini.backend = 'LibXML' + end + + def teardown + XmlMini.backend = @default_backend + end + + def test_set_libxml_as_backend + assert_equal XmlMini_LibXML, XmlMini.backend + end + + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) + + + a post + another post + + + eoxml + end + + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end + + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end + + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) + + + + eoxml + end + + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) + + + + + eoxml + end + + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) + + hello world + + eoxml + end + + def test_children_with_children + assert_equal_rexml(<<-eoxml) + + + + + + eoxml + end + + def test_children_with_text + assert_equal_rexml(<<-eoxml) + + + hello everyone + + + eoxml + end + + def test_parse_from_io + io = StringIO.new(<<-eoxml) + + good + + hello everyone + + morning + + eoxml + XmlMini.parse(io) + end + + def test_handles_cdata + assert_equal_rexml(<<-eoxml) + + + + A blog post + A blog post about xml cdata]]> + + + + eoxml + end + + + private + def assert_equal_rexml(xml) + hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } + assert_equal(hash, XmlMini.parse(xml)) + end + +end +end \ No newline at end of file -- 1.6.2.5 From 332878c3bba2db9527342a657930a0414765eb8c Mon Sep 17 00:00:00 2001 From: David Smalley Date: Thu, 25 Jun 2009 08:25:32 +0100 Subject: [PATCH 2/2] Fix libxml to_hash to support cdata as well as text nodes --- .../lib/active_support/xml_mini/libxml.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb index 2ae22c3..97553d5 100644 --- a/activesupport/lib/active_support/xml_mini/libxml.rb +++ b/activesupport/lib/active_support/xml_mini/libxml.rb @@ -44,7 +44,7 @@ module LibXML #:nodoc: # hash:: # Hash to merge the converted element into. def to_hash(hash={}) - if text? + if text? || cdata? raise LibXML::XML::Error if content.length >= LIB_XML_LIMIT hash[CONTENT_ROOT] = content else -- 1.6.2.5