summaryrefslogtreecommitdiff
path: root/test/rexml/test_document.rb
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-28 05:59:59 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-28 05:59:59 +0000
commitde2e09e0bcf61fa54572feb6ed2e432ac003fe3d (patch)
treebc03ff3e692bc029fb8e50224f89bc167eb8b03c /test/rexml/test_document.rb
parent134ded5d7720544f28c8949743ec4d64cc9b8b9d (diff)
* lib/rexml/document.rb (REXML::Document#write): Accept options
Hash as argument. * test/rexml/test_document.rb: Add tests for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rexml/test_document.rb')
-rw-r--r--test/rexml/test_document.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/rexml/test_document.rb b/test/rexml/test_document.rb
index ab0b1e4..e8ca2e1 100644
--- a/test/rexml/test_document.rb
+++ b/test/rexml/test_document.rb
@@ -106,4 +106,99 @@ EOX
doc = REXML::Document.new('<?xml version="1.0" standalone= "no" ?>')
assert_equal('no', doc.stand_alone?, bug2539)
end
+
+ class WriteTest < Test::Unit::TestCase
+ def setup
+ @document = REXML::Document.new(<<-EOX)
+<?xml version="1.0" encoding="UTF-8"?>
+<message>Hello world!</message>
+EOX
+ end
+
+ class ArgumentsTest < self
+ def test_output
+ output = ""
+ @document.write(output)
+ assert_equal(<<-EOX, output)
+<?xml version='1.0' encoding='UTF-8'?>
+<message>Hello world!</message>
+EOX
+ end
+
+ def test_indent
+ output = ""
+ indent = 2
+ @document.write(output, indent)
+ assert_equal(<<-EOX.chomp, output)
+<?xml version='1.0' encoding='UTF-8'?>
+<message>
+ Hello world!
+</message>
+EOX
+ end
+
+ def test_transitive
+ output = ""
+ indent = 2
+ transitive = true
+ @document.write(output, indent, transitive)
+ assert_equal(<<-EOX, output)
+<?xml version='1.0' encoding='UTF-8'?>
+<message
+>Hello world!</message
+>
+EOX
+ end
+
+ def test_ie_hack
+ output = ""
+ indent = -1
+ transitive = false
+ ie_hack = true
+ document = REXML::Document.new("<empty/>")
+ document.write(output, indent, transitive, ie_hack)
+ assert_equal("<empty />", output)
+ end
+ end
+
+ class OptionsTest < self
+ def test_output
+ output = ""
+ @document.write(:output => output)
+ assert_equal(<<-EOX, output)
+<?xml version='1.0' encoding='UTF-8'?>
+<message>Hello world!</message>
+EOX
+ end
+
+ def test_indent
+ output = ""
+ @document.write(:output => output, :indent => 2)
+ assert_equal(<<-EOX.chomp, output)
+<?xml version='1.0' encoding='UTF-8'?>
+<message>
+ Hello world!
+</message>
+EOX
+ end
+
+ def test_transitive
+ output = ""
+ @document.write(:output => output, :indent => 2, :transitive => true)
+ assert_equal(<<-EOX, output)
+<?xml version='1.0' encoding='UTF-8'?>
+<message
+>Hello world!</message
+>
+EOX
+ end
+
+ def test_ie_hack
+ output = ""
+ document = REXML::Document.new("<empty/>")
+ document.write(:output => output, :ie_hack => true)
+ assert_equal("<empty />", output)
+ end
+ end
+ end
end