2016-08-06 12:03:25 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/xml_mini"
|
2009-03-09 20:27:39 -04:00
|
|
|
|
2012-01-05 20:12:46 -05:00
|
|
|
class REXMLEngineTest < ActiveSupport::TestCase
|
2009-03-09 20:27:39 -04:00
|
|
|
def test_default_is_rexml
|
2015-01-04 16:57:43 -05:00
|
|
|
assert_equal ActiveSupport::XmlMini_REXML, ActiveSupport::XmlMini.backend
|
2009-03-09 20:27:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_rexml_as_backend
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::XmlMini.backend = "REXML"
|
2015-01-04 16:57:43 -05:00
|
|
|
assert_equal ActiveSupport::XmlMini_REXML, ActiveSupport::XmlMini.backend
|
2009-03-09 20:27:39 -04:00
|
|
|
end
|
2009-05-17 11:37:30 -04:00
|
|
|
|
|
|
|
def test_parse_from_io
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::XmlMini.backend = "REXML"
|
2009-05-17 11:37:30 -04:00
|
|
|
io = StringIO.new(<<-eoxml)
|
|
|
|
<root>
|
|
|
|
good
|
|
|
|
<products>
|
|
|
|
hello everyone
|
|
|
|
</products>
|
|
|
|
morning
|
|
|
|
</root>
|
|
|
|
eoxml
|
2016-05-21 08:14:22 -04:00
|
|
|
hash = ActiveSupport::XmlMini.parse(io)
|
2016-08-06 12:03:25 -04:00
|
|
|
assert hash.has_key?("root")
|
|
|
|
assert hash["root"].has_key?("products")
|
|
|
|
assert_match "good", hash["root"]["__content__"]
|
|
|
|
products = hash["root"]["products"]
|
2016-05-21 08:14:22 -04:00
|
|
|
assert products.has_key?("__content__")
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_match "hello everyone", products["__content__"]
|
2016-05-21 08:14:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_from_empty_string
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::XmlMini.backend = "REXML"
|
2016-05-21 08:14:22 -04:00
|
|
|
assert_equal({}, ActiveSupport::XmlMini.parse(""))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_from_frozen_string
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::XmlMini.backend = "REXML"
|
2016-05-21 08:14:22 -04:00
|
|
|
xml_string = "<root></root>".freeze
|
|
|
|
assert_equal({"root" => {}}, ActiveSupport::XmlMini.parse(xml_string))
|
2009-05-17 11:37:30 -04:00
|
|
|
end
|
2013-04-02 02:20:25 -04:00
|
|
|
|
2009-03-09 20:27:39 -04:00
|
|
|
end
|