summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bleything <ben@bleything.net>2010-02-23 21:16:24 -0800
committerBen Bleything <ben@bleything.net>2010-02-23 21:16:24 -0800
commite15c58ada6f2647633625c1c20ca66cfb8f23351 (patch)
tree6459db0f77400dc82269af2b32133e1f790dc33c
parentd67ed75fbc6030032aceef2e52ee268ba159eedb (diff)
downloadplist-e15c58ada6f2647633625c1c20ca66cfb8f23351.tar.gz
ruby 1.9 compatibility!
-rw-r--r--README.rdoc1
-rw-r--r--lib/plist/generator.rb18
-rw-r--r--test/test_data_elements.rb21
3 files changed, 29 insertions, 11 deletions
diff --git a/README.rdoc b/README.rdoc
index 6b29f8e..d0fccf9 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -125,6 +125,7 @@ Other folks who have helped along the way:
[<b>Chuck Remes</b>] who pushed Patrick towards implementing <tt>#to_plist</tt>
[<b>Mat Schaffer</b>] who supplied code and test cases for <tt><data></tt> elements
[<b>Michael Granger</b>] for encouragement and help
+[<b>Carsten Bormann, Chris Hoffman, Dana Contreras, Hongli Lai, Johan Sørensen</b>] for contributing Ruby 1.9.x compatibility fixes
== License and Copyright
diff --git a/lib/plist/generator.rb b/lib/plist/generator.rb
index 5197210..02958c5 100644
--- a/lib/plist/generator.rb
+++ b/lib/plist/generator.rb
@@ -155,12 +155,18 @@ module Plist::Emit
end
def self.element_type(item)
- return case item
- when String, Symbol: 'string'
- when Fixnum, Bignum, Integer: 'integer'
- when Float: 'real'
- else
- raise "Don't know about this data type... something must be wrong!"
+ case item
+ when String, Symbol
+ 'string'
+
+ when Fixnum, Bignum, Integer
+ 'integer'
+
+ when Float
+ 'real'
+
+ else
+ raise "Don't know about this data type... something must be wrong!"
end
end
private
diff --git a/test/test_data_elements.rb b/test/test_data_elements.rb
index 584f9e5..36ceac0 100644
--- a/test/test_data_elements.rb
+++ b/test/test_data_elements.rb
@@ -18,7 +18,7 @@ class TestDataElements < Test::Unit::TestCase
@result = Plist.parse_xml( 'test/assets/test_data_elements.plist' )
end
- def test_marshal
+ def test_data_object_header
expected = <<END
<!-- The <data> element below contains a Ruby object which has been serialized with Marshal.dump. -->
<data>
@@ -26,14 +26,25 @@ BAhvOhZNYXJzaGFsYWJsZU9iamVjdAY6CUBmb28iHnRoaXMgb2JqZWN0IHdhcyBtYXJz
aGFsZWQ=
</data>
END
+ expected_elements = expected.chomp.split( "\n" )
- mo = MarshalableObject.new('this object was marshaled')
+ actual = Plist::Emit.dump( Object.new, false )
+ actual_elements = actual.chomp.split( "\n" )
- assert_equal expected.chomp, Plist::Emit.dump(mo, false).chomp
+ # check for header
+ assert_equal expected_elements.shift, actual_elements.shift
- assert_instance_of MarshalableObject, @result['marshal']
+ # check for opening and closing data tags
+ assert_equal expected_elements.shift, actual_elements.shift
+ assert_equal expected_elements.pop, actual_elements.pop
+ end
+
+ def test_marshal_round_trip
+ expected = MarshalableObject.new('this object was marshaled')
+ actual = Plist.parse_xml( Plist::Emit.dump(expected, false) )
- assert_equal mo.foo, @result['marshal'].foo
+ assert_kind_of expected.class, actual
+ assert_equal expected.foo, actual.foo
end
def test_generator_io_and_file