Source

XmlFormatter4JR / test_xmlformatter.rb

Full commit
require 'test/unit'
require 'xmlformatter'


class TC_XmlFormatter < Test::Unit::TestCase
  def setup
  end

  def test_format_xml_empty_tag
    assert_equal(format_xml("<test></test>"), "<test/>")
  end

  def test_format_xml_text_node
    assert_equal(format_xml("<test>text</test>"), "<test>text</test>")
  end

  def test_format_xml_child_empty_node
    assert_equal(format_xml("<test><child></child></test>"), "<test>\n  <child/>\n</test>")
  end

  def test_format_xml_child_text_node
    assert_equal(format_xml("<test><child>text</child></test>"), "<test>\n  <child>text</child>\n</test>")
  end

  def test_format_xml_child_child_node
    assert_equal(format_xml("<test><child><child2>text</child2></child></test>"), "<test>\n  <child>\n    <child2>text</child2>\n  </child>\n</test>")
  end

  def test_format_xml_sibling_node
    assert_equal(format_xml("<test><sibling1>text</sibling1><sibling2></sibling2></test>"), "<test>\n  <sibling1>text</sibling1>\n  <sibling2/>\n</test>")
  end

  def test_format_xml_xml_declaration
    assert_equal(format_xml("<?xml version='1.0'?><test><sibling1>text</sibling1><sibling2></sibling2></test>"), "<?xml version='1.0'?>\n<test>\n  <sibling1>text</sibling1>\n  <sibling2/>\n</test>")
  end
end