[前][次][番号順一覧][スレッド一覧]

ruby-changes:35235

From: tenderlove <ko1@a...>
Date: Sat, 30 Aug 2014 06:11:54 +0900 (JST)
Subject: [ruby-changes:35235] tenderlove:r47317 (trunk): * ext/psych/lib/psych/visitors/to_ruby.rb: merge keys with a hash

tenderlove	2014-08-30 06:11:47 +0900 (Sat, 30 Aug 2014)

  New Revision: 47317

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47317

  Log:
    * ext/psych/lib/psych/visitors/to_ruby.rb: merge keys with a hash
      should merge the hash in to the parent.
    * test/psych/test_merge_keys.rb: test for change. Fixes GH #202

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/to_ruby.rb
    trunk/test/psych/test_merge_keys.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47316)
+++ ChangeLog	(revision 47317)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Aug 30 06:10:39 2014  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: merge keys with a hash
+	  should merge the hash in to the parent.
+	* test/psych/test_merge_keys.rb: test for change. Fixes GH #202
+
 Sat Aug 30 06:00:26 2014  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/visitors/to_ruby.rb: quoted "<<" strings
Index: ext/psych/lib/psych/visitors/to_ruby.rb
===================================================================
--- ext/psych/lib/psych/visitors/to_ruby.rb	(revision 47316)
+++ ext/psych/lib/psych/visitors/to_ruby.rb	(revision 47317)
@@ -307,7 +307,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L307
 
           if key == '<<' && k.tag != "tag:yaml.org,2002:str"
             case v
-            when Nodes::Alias
+            when Nodes::Alias, Nodes::Mapping
               begin
                 hash.merge! val
               rescue TypeError
Index: test/psych/test_merge_keys.rb
===================================================================
--- test/psych/test_merge_keys.rb	(revision 47316)
+++ test/psych/test_merge_keys.rb	(revision 47317)
@@ -6,6 +6,16 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_merge_keys.rb#L6
       attr_reader :bar
     end
 
+    def test_merge_key_with_bare_hash
+      doc = Psych.load <<-eodoc
+map:
+  <<:
+    hello: world
+      eodoc
+      hash = { "map" => { "hello" => "world" } }
+      assert_equal hash, doc
+    end
+
     def test_roundtrip_with_chevron_key
       h = {}
       v = { 'a' => h, '<<' => h }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]