Permalink
Browse files

adding tests and fixing bugs with ruby symbols. thanks Peter McLain!

  • Loading branch information...
1 parent 668fbbe commit 8be32c99e14b9d5cbb6499411c58c41558a0ef31 @tenderlove tenderlove committed Mar 23, 2010
Showing with 34 additions and 1 deletion.
  1. +5 −1 lib/psych/visitors/to_ruby.rb
  2. +1 −0 lib/psych/visitors/yaml_tree.rb
  3. +28 −0 test/psych/test_alias_and_anchor.rb
@@ -74,6 +74,8 @@ def visit_Psych_Nodes_Scalar o
}
args.push(args.delete_at(1) == '...')
Range.new(*args)
+ when /^!ruby\/sym(bol)?:?(.*)?$/
+ o.value.to_sym
else
@ss.tokenize o.value
end
@@ -170,7 +172,9 @@ def visit_Psych_Nodes_Mapping o
when /^!ruby\/object:?(.*)?$/
name = $1 || 'Object'
- revive((resolve_class(name) || Object), o)
+ obj = revive((resolve_class(name) || Object), o)
+ @st[o.anchor] = obj if o.anchor
+ obj
else
hash = {}
@st[o.anchor] = hash if o.anchor
@@ -54,6 +54,7 @@ def visit_Object o
end
map = append Nodes::Mapping.new(nil, tag, false)
+ register(o, map)
@stack.push map
dump_ivars(o, map)
@@ -0,0 +1,28 @@
+require 'minitest/autorun'
+require 'psych'
+
+module Psych
+ class TestAliasAndAnchor < MiniTest::Unit::TestCase
+
+ def test_mri_compatibility
+ yaml = <<EOYAML
+---
+- &id001 !ruby/object {}
+
+- *id001
+- *id001
+EOYAML
+ result = Psych.load yaml
+ result.each {|el| assert_same(result[0], el) }
+ end
+
+ def test_anchor_alias_round_trip
+ o = Object.new
+ original = [o,o,o]
+
+ yaml = Psych.dump original
+ result = Psych.load yaml
+ result.each {|el| assert_same(result[0], el) }
+ end
+ end
+end

0 comments on commit 8be32c9

Please sign in to comment.