Skip to content

Instantly share code, notes, and snippets.

@Fryguy
Created December 15, 2011 19:22
Show Gist options
  • Save Fryguy/1482427 to your computer and use it in GitHub Desktop.
Save Fryguy/1482427 to your computer and use it in GitHub Desktop.
psych doesn't handle subclasses of String nor Array
diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb
index ec6a1aa..57b9428 100644
--- a/test/psych/test_array.rb
+++ b/test/psych/test_array.rb
@@ -2,11 +2,30 @@ require 'psych/helper'
module Psych
class TestArray < TestCase
+ class X < Array
+ end
+
+ class Y < Array
+ attr_accessor :val
+ end
+
def setup
super
@list = [{ :a => 'b' }, 'foo']
end
+ def test_empty_subclass
+ #assert_match "!ruby/seq:#{X}", Psych.dump(X.new)
+ x = Psych.load Psych.dump X.new
+ assert_equal X, x.class
+ end
+
+ def test_subclass_with_attributes
+ y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
+ assert_equal Y, y.class
+ assert_equal 1, y.val
+ end
+
def test_self_referential
@list << @list
assert_cycle(@list)
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index cffc121..aaa9e19 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -2,6 +2,25 @@ require 'psych/helper'
module Psych
class TestString < TestCase
+ class X < String
+ end
+
+ class Y < String
+ attr_accessor :val
+ end
+
+ def test_empty_subclass
+ #assert_match "!ruby/str:#{X}", Psych.dump(X.new)
+ x = Psych.load Psych.dump X.new
+ assert_equal X, x.class
+ end
+
+ def test_subclass_with_attributes
+ y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
+ assert_equal Y, y.class
+ assert_equal 1, y.val
+ end
+
def test_string_with_base_60
yaml = Psych.dump '01:03:05'
assert_match "'01:03:05'", yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment