Permalink
Browse files

ruby 1.9 compatibility!

  • Loading branch information...
1 parent d67ed75 commit e15c58ada6f2647633625c1c20ca66cfb8f23351 @bleything bleything committed Feb 24, 2010
Showing with 29 additions and 11 deletions.
  1. +1 −0 README.rdoc
  2. +12 −6 lib/plist/generator.rb
  3. +16 −5 test/test_data_elements.rb
View
@@ -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
View
@@ -155,12 +155,18 @@ def self.wrap(contents)
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
View
@@ -18,22 +18,33 @@ def setup
@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>
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

0 comments on commit e15c58a

Please sign in to comment.