summaryrefslogtreecommitdiff
path: root/test/psych/test_alias_and_anchor.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-16 19:00:59 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-16 19:00:59 +0000
commit7d1f53e782b5340591c3788d369a2951e9707f9b (patch)
tree36be6bf81b8a861dda48dd59187b698019556bf5 /test/psych/test_alias_and_anchor.rb
parent43395d53c9f9352f5fe9ed9a8ff443b62732f5f8 (diff)
* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych/test_alias_and_anchor.rb')
-rw-r--r--test/psych/test_alias_and_anchor.rb70
1 files changed, 70 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