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

ruby-changes:19811

From: yugui <ko1@a...>
Date: Tue, 31 May 2011 12:46:32 +0900 (JST)
Subject: [ruby-changes:19811] yugui:r31856 (ruby_1_9_2): merges r30629 and r30630 from trunk into ruby_1_9_2.

yugui	2011-05-31 12:46:21 +0900 (Tue, 31 May 2011)

  New Revision: 31856

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

  Log:
    merges r30629 and r30630 from trunk into ruby_1_9_2.
    --
    * ext/psych/lib/psych/visitors/to_ruby.rb: merge keys are actually
      part of YAML 1.1, so they should be supported.  Remove warning and
      merge keys to parent.  [ruby-core:34679]
    * test/psych/test_merge_keys.rb: test for merge keys
    --
    * ext/psych/lib/psych/visitors/to_ruby.rb: fixing merge key support
      when multiple merge keys are specified.
    * test/psych/test_merge_keys.rb: tests for multi-merge key support

  Added files:
    branches/ruby_1_9_2/test/psych/test_merge_keys.rb
  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/ext/psych/lib/psych/visitors/to_ruby.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 31855)
+++ ruby_1_9_2/ChangeLog	(revision 31856)
@@ -1,3 +1,18 @@
+Sat Jan 22 11:49:55 2011  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: fixing merge key support
+	  when multiple merge keys are specified.
+
+	* test/psych/test_merge_keys.rb: tests for multi-merge key support
+	
+Sat Jan 22 11:33:04 2011  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: merge keys are actually
+	  part of YAML 1.1, so they should be supported.  Remove warning and
+	  merge keys to parent.  [ruby-core:34679]
+
+	* test/psych/test_merge_keys.rb: test for merge keys
+
 Thu Jul 15 00:35:09 2010  Tanaka Akira  <akr@f...>
 
 	* time.c (localtime_with_gmtoff_zone): renamed from
Index: ruby_1_9_2/ext/psych/lib/psych/visitors/to_ruby.rb
===================================================================
--- ruby_1_9_2/ext/psych/lib/psych/visitors/to_ruby.rb	(revision 31855)
+++ ruby_1_9_2/ext/psych/lib/psych/visitors/to_ruby.rb	(revision 31856)
@@ -190,14 +190,17 @@
           o.children.each_slice(2) { |k,v|
             key = accept(k)
 
-            if key == '<<' && Nodes::Alias === v
-              # FIXME: remove this when "<<" syntax is deprecated
-              if $VERBOSE
-                where = caller.find { |x| x !~ /psych/ }
-                warn where
-                warn "\"<<: *#{v.anchor}\" is no longer supported, please switch to \"*#{v.anchor}\""
+            if key == '<<'
+              case v
+              when Nodes::Alias
+                hash.merge! accept(v)
+              when Nodes::Sequence
+                accept(v).reverse_each do |value|
+                  hash.merge! value
+                end
+              else
+                hash[key] = accept(v)
               end
-              return accept(v)
             else
               hash[key] = accept(v)
             end
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 31855)
+++ ruby_1_9_2/version.h	(revision 31856)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 270
+#define RUBY_PATCHLEVEL 271
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/psych/test_merge_keys.rb
===================================================================
--- ruby_1_9_2/test/psych/test_merge_keys.rb	(revision 0)
+++ ruby_1_9_2/test/psych/test_merge_keys.rb	(revision 31856)
@@ -0,0 +1,72 @@
+require_relative 'helper'
+
+module Psych
+  class TestMergeKeys < TestCase
+    # [ruby-core:34679]
+    def test_merge_key
+      yaml = <<-eoyml
+foo: &foo
+  hello: world
+bar:
+  << : *foo
+  baz: boo
+      eoyml
+
+      hash = {
+        "foo" => { "hello" => "world"},
+        "bar" => { "hello" => "world", "baz" => "boo" } }
+      assert_equal hash, Psych.load(yaml)
+    end
+
+    def test_multiple_maps
+      yaml = <<-eoyaml
+---
+- &CENTER { x: 1, y: 2 }
+- &LEFT { x: 0, y: 2 }
+- &BIG { r: 10 }
+- &SMALL { r: 1 }
+
+# All the following maps are equal:
+
+- # Merge multiple maps
+  << : [ *CENTER, *BIG ]
+  label: center/big
+      eoyaml
+
+      hash = {
+        'x' => 1,
+        'y' => 2,
+        'r' => 10,
+        'label' => 'center/big'
+      }
+
+      assert_equal hash, Psych.load(yaml)[4]
+    end
+
+    def test_override
+      yaml = <<-eoyaml
+---
+- &CENTER { x: 1, y: 2 }
+- &LEFT { x: 0, y: 2 }
+- &BIG { r: 10 }
+- &SMALL { r: 1 }
+
+# All the following maps are equal:
+
+- # Override
+  << : [ *BIG, *LEFT, *SMALL ]
+  x: 1
+  label: center/big
+      eoyaml
+
+      hash = {
+        'x' => 1,
+        'y' => 2,
+        'r' => 10,
+        'label' => 'center/big'
+      }
+
+      assert_equal hash, Psych.load(yaml)[4]
+    end
+  end
+end

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

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