From e15c58ada6f2647633625c1c20ca66cfb8f23351 Mon Sep 17 00:00:00 2001 From: Ben Bleything Date: Tue, 23 Feb 2010 21:16:24 -0800 Subject: ruby 1.9 compatibility! --- README.rdoc | 1 + lib/plist/generator.rb | 18 ++++++++++++------ test/test_data_elements.rb | 21 ++++++++++++++++----- 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: [Chuck Remes] who pushed Patrick towards implementing #to_plist [Mat Schaffer] who supplied code and test cases for elements [Michael Granger] for encouragement and help +[Carsten Bormann, Chris Hoffman, Dana Contreras, Hongli Lai, Johan Sørensen] 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 = < element below contains a Ruby object which has been serialized with Marshal.dump. --> @@ -26,14 +26,25 @@ BAhvOhZNYXJzaGFsYWJsZU9iamVjdAY6CUBmb28iHnRoaXMgb2JqZWN0IHdhcyBtYXJz aGFsZWQ= 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 -- cgit v1.2.1