File: entity_tests.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 882 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Tests XML entity decoding (<, >, etc.) and dash-to-underscore key conversion
module ParserEntityTests
  def test_xml_entities_in_content_are_unescaped
    {"<" => "&lt;", ">" => "&gt;", '"' => "&quot;", "'" => "&apos;", "&" => "&amp;"}.each do |char, entity|
      assert_equal char, MultiXml.parse("<tag>#{entity}</tag>")["tag"]
    end
  end

  def test_xml_entities_in_attribute_are_unescaped
    {"<" => "&lt;", ">" => "&gt;", '"' => "&quot;", "'" => "&apos;", "&" => "&amp;"}.each do |char, entity|
      assert_equal char, MultiXml.parse("<tag attribute=\"#{entity}\"/>")["tag"]["attribute"]
    end
  end

  def test_dasherized_tag_is_undasherized
    assert_includes MultiXml.parse("<tag-1/>").keys, "tag_1"
  end

  def test_dasherized_attribute_is_undasherized
    assert_includes MultiXml.parse('<tag attribute-1="1"></tag>')["tag"].keys, "attribute_1"
  end
end