diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-07 20:50:05 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-07 20:50:05 +0000 |
commit | 6b3bac29fe8341385ad70b8c6145e8f355369339 (patch) | |
tree | 40d791ced37f952fa05ce87aed4d0c1c6e54b451 /test | |
parent | 33d5c4848df9c000e80a28cc9ba1c5e63cfc631d (diff) |
merge revision(s) r36583, r36458, r36414, r36103, r35690, r35681, r35658, r35657, r35655, r35492: [Backport #6815]
* ext/psych/lib/psych.rb: updated to released version.
* ext/psych/psych.gemspec: ditto
* ext/psych/emitter.c (initialize): allow a configuration object to be
passed to the constructor so that mutation isn't required after
instantiation.
* ext/psych/lib/psych/handler.rb: add configuration object
* ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
extra configuration is present.
* ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
are properly referenced. Patched by Joe Rafaniello via Github:
https://github.com/tenderlove/psych/pull/69
* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
* test/psych/test_alias_and_anchor.rb: test for change
* ext/psych/lib/psych.rb: bumping psych to 1.3.3
* ext/psych/psych.gemspec: ditto
* ext/psych/extconf.rb: Use an exception instaed of bare abort.
* ext/psych/parser.c (transcode_string): fix encoding index names.
Thanks markizko for reporting.
* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
subclass dumping and loading.
* test/psych/test_array.rb: pertinent tests
* test/psych/test_string.rb: ditto
* ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
Psych::Omap objects rather than hashes. [Bug #6425]
* test/psych/test_omap.rb: pertinent test.
* ext/psych/lib/psych/visitors/yaml_tree.rb: keep a reference to
custom coders so that GC does not impact dumped yaml reference ids.
* ext/psych/lib/psych/json/yaml_events.rb: implicit styles should not
be changeable for JSON events.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@36654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_alias_and_anchor.rb | 70 | ||||
-rw-r--r-- | test/psych/test_array.rb | 10 | ||||
-rw-r--r-- | test/psych/test_omap.rb | 7 | ||||
-rw-r--r-- | test/psych/test_string.rb | 7 |
4 files changed, 94 insertions, 0 deletions
diff --git a/test/psych/test_alias_and_anchor.rb b/test/psych/test_alias_and_anchor.rb index 48771d6e25..aa4773bce4 100644 --- a/test/psych/test_alias_and_anchor.rb +++ b/test/psych/test_alias_and_anchor.rb @@ -1,5 +1,13 @@ require 'psych/helper' +class ObjectWithInstanceVariables + attr_accessor :var1, :var2 +end + +class SubStringWithInstanceVariables < String + attr_accessor :var1 +end + module Psych class TestAliasAndAnchor < TestCase def test_mri_compatibility @@ -14,6 +22,40 @@ EOYAML result.each {|el| assert_same(result[0], el) } end + def test_mri_compatibility_object_with_ivars + yaml = <<EOYAML +--- +- &id001 !ruby/object:ObjectWithInstanceVariables + var1: test1 + var2: test2 +- *id001 +- *id001 +EOYAML + + result = Psych.load yaml + result.each do |el| + assert_same(result[0], el) + assert_equal('test1', el.var1) + assert_equal('test2', el.var2) + end + end + + def test_mri_compatibility_substring_with_ivars + yaml = <<EOYAML +--- +- &id001 !str:SubStringWithInstanceVariables + str: test + "@var1": test +- *id001 +- *id001 +EOYAML + result = Psych.load yaml + result.each do |el| + assert_same(result[0], el) + assert_equal('test', el.var1) + end + end + def test_anchor_alias_round_trip o = Object.new original = [o,o,o] @@ -22,5 +64,33 @@ EOYAML result = Psych.load yaml result.each {|el| assert_same(result[0], el) } end + + def test_anchor_alias_round_trip_object_with_ivars + o = ObjectWithInstanceVariables.new + o.var1 = 'test1' + o.var2 = 'test2' + original = [o,o,o] + + yaml = Psych.dump original + result = Psych.load yaml + result.each do |el| + assert_same(result[0], el) + assert_equal('test1', el.var1) + assert_equal('test2', el.var2) + end + end + + def test_anchor_alias_round_trip_substring_with_ivars + o = SubStringWithInstanceVariables.new + o.var1 = 'test' + original = [o,o,o] + + yaml = Psych.dump original + result = Psych.load yaml + result.each do |el| + assert_same(result[0], el) + assert_equal('test', el.var1) + end + end end end diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb index 9eedbb4fda..747fe95062 100644 --- a/test/psych/test_array.rb +++ b/test/psych/test_array.rb @@ -14,6 +14,16 @@ module Psych @list = [{ :a => 'b' }, 'foo'] end + def test_another_subclass_with_attributes + y = Y.new.tap {|y| y.val = 1} + y << "foo" << "bar" + y = Psych.load Psych.dump y + + assert_equal %w{foo bar}, y + assert_equal Y, y.class + assert_equal 1, y.val + end + def test_subclass yaml = Psych.dump X.new assert_match X.name, yaml diff --git a/test/psych/test_omap.rb b/test/psych/test_omap.rb index 53f55f5aec..34df724998 100644 --- a/test/psych/test_omap.rb +++ b/test/psych/test_omap.rb @@ -2,6 +2,13 @@ require 'psych/helper' module Psych class TestOmap < TestCase + def test_parse_as_map + o = Psych.load "--- !!omap\na: 1\nb: 2" + assert_kind_of Psych::Omap, o + assert_equal 1, o['a'] + assert_equal 2, o['b'] + end + def test_self_referential map = Psych::Omap.new map['foo'] = 'bar' diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index c7d5c60623..77aefc6dae 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -9,6 +9,13 @@ module Psych attr_accessor :val end + def test_another_subclass_with_attributes + y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1} + assert_equal "foo", y + assert_equal Y, y.class + assert_equal 1, y.val + end + def test_backwards_with_syck x = Psych.load "--- !str:#{X.name} foo\n\n" assert_equal X, x.class |