summaryrefslogtreecommitdiff
path: root/test/test_generator_collections.rb
diff options
context:
space:
mode:
authorBen Bleything <ben@bleything.net>2006-09-13 23:49:05 +0000
committerBen Bleything <ben@bleything.net>2006-09-13 23:49:05 +0000
commit576ab4da73cbf54def98079e6be6c4e24db373c6 (patch)
treed53d57e717beae2ac0200717ea4ed2ad2004e006 /test/test_generator_collections.rb
parent54486d3e0432cbc7d64de88ef114aac2f78285bc (diff)
downloadplist-576ab4da73cbf54def98079e6be6c4e24db373c6.tar.gz
merge generator-injection-removal branch into trunk
Diffstat (limited to 'test/test_generator_collections.rb')
-rw-r--r--test/test_generator_collections.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/test_generator_collections.rb b/test/test_generator_collections.rb
new file mode 100644
index 0000000..a421237
--- /dev/null
+++ b/test/test_generator_collections.rb
@@ -0,0 +1,66 @@
+##############################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+
+require 'test/unit'
+require 'plist'
+
+class TestGeneratorCollections < Test::Unit::TestCase
+ def test_array
+ expected = <<END
+<array>
+ <integer>1</integer>
+ <integer>2</integer>
+ <integer>3</integer>
+</array>
+END
+
+ assert_equal expected, [1,2,3].to_plist(false)
+ end
+
+ def test_hash
+ expected = <<END
+<dict>
+ <key>abc</key>
+ <integer>123</integer>
+ <key>foo</key>
+ <string>bar</string>
+</dict>
+END
+ # thanks to recent changes in the generator code, hash keys are sorted before emission,
+ # so multi-element hash tests should be reliable. We're testing that here too.
+ assert_equal expected, {:foo => :bar, :abc => 123}.to_plist(false)
+ end
+
+ def test_hash_with_array_element
+ expected = <<END
+<dict>
+ <key>ary</key>
+ <array>
+ <integer>1</integer>
+ <string>b</string>
+ <string>3</string>
+ </array>
+</dict>
+END
+ assert_equal expected, {:ary => [1,:b,'3']}.to_plist(false)
+ end
+
+ def test_array_with_hash_element
+ expected = <<END
+<array>
+ <dict>
+ <key>foo</key>
+ <string>bar</string>
+ </dict>
+ <string>b</string>
+ <integer>3</integer>
+</array>
+END
+
+ assert_equal expected, [{:foo => 'bar'}, :b, 3].to_plist(false)
+ end
+end