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

ruby-changes:51073

From: hsbt <ko1@a...>
Date: Sat, 28 Apr 2018 10:48:04 +0900 (JST)
Subject: [ruby-changes:51073] hsbt:r63280 (trunk): Merge Pysch 3.0.3.pre1.

hsbt	2018-04-28 10:47:58 +0900 (Sat, 28 Apr 2018)

  New Revision: 63280

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

  Log:
    Merge Pysch 3.0.3.pre1.
    
      I added the following additional commits from 3.0.3.pre1:
        * https://github.com/ruby/psych/pull/356
        * https://github.com/ruby/psych/pull/357
        * https://github.com/ruby/psych/pull/359

  Modified files:
    trunk/ext/psych/lib/psych/handler.rb
    trunk/ext/psych/lib/psych/nodes/alias.rb
    trunk/ext/psych/lib/psych/nodes/document.rb
    trunk/ext/psych/lib/psych/nodes/mapping.rb
    trunk/ext/psych/lib/psych/nodes/node.rb
    trunk/ext/psych/lib/psych/nodes/scalar.rb
    trunk/ext/psych/lib/psych/nodes/sequence.rb
    trunk/ext/psych/lib/psych/nodes/stream.rb
    trunk/ext/psych/lib/psych/versions.rb
    trunk/ext/psych/lib/psych.rb
    trunk/ext/psych/psych.gemspec
    trunk/ext/psych/yaml/emitter.c
    trunk/test/psych/test_psych.rb
    trunk/test/psych/test_stream.rb
Index: ext/psych/psych.gemspec
===================================================================
--- ext/psych/psych.gemspec	(revision 63279)
+++ ext/psych/psych.gemspec	(revision 63280)
@@ -3,10 +3,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/psych.gemspec#L3
 
 Gem::Specification.new do |s|
   s.name = "psych"
-  s.version = "3.0.2"
+  s.version = "3.0.3.pre1"
   s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"]
   s.email = ["aaron@t...", "hsbt@r...", "headius@h..."]
-  s.date = "2017-12-04"
   s.summary = "Psych is a YAML parser and emitter"
   s.description = <<-DESCRIPTION
 Psych is a YAML parser and emitter. Psych leverages libyaml[http://pyyaml.org/wiki/LibYAML]
@@ -20,7 +19,7 @@ DESCRIPTION https://github.com/ruby/ruby/blob/trunk/ext/psych/psych.gemspec#L19
   # for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
   s.files = [
     ".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console",
-    "bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h",
+    "bin/setup", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h",
     "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h",
     "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h",
     "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c",
@@ -54,7 +53,7 @@ DESCRIPTION https://github.com/ruby/ruby/blob/trunk/ext/psych/psych.gemspec#L53
       "ext/java/PsychEmitter.java", "ext/java/PsychLibrary.java", "ext/java/PsychParser.java", "ext/java/PsychToRuby.java",
       "ext/java/PsychYamlTree.java", "lib/psych_jars.rb", "lib/psych.jar"
     ]
-    s.requirements = "jar org.yaml:snakeyaml, 1.18"
+    s.requirements = "jar org.yaml:snakeyaml, 1.21"
     s.add_dependency 'jar-dependencies', '>= 0.1.7'
     s.add_development_dependency 'ruby-maven'
   else
Index: ext/psych/yaml/emitter.c
===================================================================
--- ext/psych/yaml/emitter.c	(revision 63279)
+++ ext/psych/yaml/emitter.c	(revision 63280)
@@ -1234,7 +1234,7 @@ yaml_emitter_select_scalar_style(yaml_em https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1234
 }
 
 /*
- * Write an achor.
+ * Write an anchor.
  */
 
 static int
Index: ext/psych/lib/psych/nodes/node.rb
===================================================================
--- ext/psych/lib/psych/nodes/node.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/node.rb	(revision 63280)
@@ -63,6 +63,13 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/node.rb#L63
         io
       end
       alias :to_yaml :yaml
+
+      def alias?;    false; end
+      def document?; false; end
+      def mapping?;  false; end
+      def scalar?;   false; end
+      def sequence?; false; end
+      def stream?;   false; end
     end
   end
 end
Index: ext/psych/lib/psych/nodes/scalar.rb
===================================================================
--- ext/psych/lib/psych/nodes/scalar.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/scalar.rb	(revision 63280)
@@ -63,6 +63,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/scalar.rb#L63
         @quoted = quoted
         @style  = style
       end
+
+      def scalar?; true; end
     end
   end
 end
Index: ext/psych/lib/psych/nodes/sequence.rb
===================================================================
--- ext/psych/lib/psych/nodes/sequence.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/sequence.rb	(revision 63280)
@@ -77,6 +77,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/sequence.rb#L77
         @implicit = implicit
         @style    = style
       end
+
+      def sequence?; true; end
     end
   end
 end
Index: ext/psych/lib/psych/nodes/alias.rb
===================================================================
--- ext/psych/lib/psych/nodes/alias.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/alias.rb	(revision 63280)
@@ -14,6 +14,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/alias.rb#L14
       def initialize anchor
         @anchor = anchor
       end
+
+      def alias?; true; end
     end
   end
 end
Index: ext/psych/lib/psych/nodes/mapping.rb
===================================================================
--- ext/psych/lib/psych/nodes/mapping.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/mapping.rb	(revision 63280)
@@ -52,6 +52,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/mapping.rb#L52
         @implicit = implicit
         @style    = style
       end
+
+      def mapping?; true; end
     end
   end
 end
Index: ext/psych/lib/psych/nodes/stream.rb
===================================================================
--- ext/psych/lib/psych/nodes/stream.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/stream.rb	(revision 63280)
@@ -33,6 +33,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/stream.rb#L33
         super()
         @encoding = encoding
       end
+
+      def stream?; true; end
     end
   end
 end
Index: ext/psych/lib/psych/nodes/document.rb
===================================================================
--- ext/psych/lib/psych/nodes/document.rb	(revision 63279)
+++ ext/psych/lib/psych/nodes/document.rb	(revision 63280)
@@ -56,6 +56,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/nodes/document.rb#L56
       def root
         children.first
       end
+
+      def document?; true; end
     end
   end
 end
Index: ext/psych/lib/psych/versions.rb
===================================================================
--- ext/psych/lib/psych/versions.rb	(revision 63279)
+++ ext/psych/lib/psych/versions.rb	(revision 63280)
@@ -1,9 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/versions.rb#L1
 # frozen_string_literal: true
 module Psych
   # The version is Psych you're using
-  VERSION = '3.0.2'
+  VERSION = '3.0.3.pre1'
 
   if RUBY_ENGINE == 'jruby'
-    DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze
+    DEFAULT_SNAKEYAML_VERSION = '1.21'.freeze
   end
 end
Index: ext/psych/lib/psych/handler.rb
===================================================================
--- ext/psych/lib/psych/handler.rb	(revision 63279)
+++ ext/psych/lib/psych/handler.rb	(revision 63280)
@@ -105,7 +105,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/handler.rb#L105
     #   - first element
     #   - *ponies
     #
-    # &ponies is the achor, *ponies is the alias.  In this case, alias is
+    # &ponies is the anchor, *ponies is the alias.  In this case, alias is
     # called with "ponies".
     def alias anchor
     end
Index: ext/psych/lib/psych.rb
===================================================================
--- ext/psych/lib/psych.rb	(revision 63279)
+++ ext/psych/lib/psych.rb	(revision 63280)
@@ -418,6 +418,24 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych.rb#L418
   # to control the output format.  If an IO object is passed in, the YAML will
   # be dumped to that IO object.
   #
+  # Currently supported options are:
+  #
+  # [<tt>:indentation</tt>]   Number of space characters used to indent.
+  #                           Acceptable value should be in <tt>0..9</tt> range,
+  #                           otherwise option is ignored.
+  #
+  #                           Default: <tt>2</tt>.
+  # [<tt>:line_width</tt>]    Max character to wrap line at.
+  #
+  #                           Default: <tt>0</tt> (meaning "wrap at 81").
+  # [<tt>:canonical</tt>]     Write "canonical" YAML form (very verbose, yet
+  #                           strictly formal).
+  #
+  #                           Default: <tt>false</tt>.
+  # [<tt>:header</tt>]        Write <tt>%YAML [version]</tt> at the beginning of document.
+  #
+  #                           Default: <tt>false</tt>.
+  #
   # Example:
   #
   #   # Dump an array, get back a YAML string
@@ -427,10 +445,10 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych.rb#L445
   #   Psych.dump(['a', 'b'], StringIO.new)  # => #<StringIO:0x000001009d0890>
   #
   #   # Dump an array with indentation set
-  #   Psych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n-  - b\n"
+  #   Psych.dump(['a', ['b']], indentation: 3) # => "---\n- a\n-  - b\n"
   #
   #   # Dump an array to an IO with indentation set
-  #   Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
+  #   Psych.dump(['a', ['b']], StringIO.new, indentation: 3)
   def self.dump o, io = nil, options = {}
     if Hash === io
       options = io
@@ -492,7 +510,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych.rb#L510
   ###
   # Load the document contained in +filename+.  Returns the yaml contained in
   # +filename+ as a Ruby object, or if the file is empty, it returns
-  # the specified default return value, which defaults to an empty Hash
+  # the specified +fallback+ return value, which defaults to +false+.
   def self.load_file filename, fallback: false
     File.open(filename, 'r:bom|utf-8') { |f|
       self.load f, filename, fallback: FALLBACK.new(fallback)
Index: test/psych/test_psych.rb
===================================================================
--- test/psych/test_psych.rb	(revision 63279)
+++ test/psych/test_psych.rb	(revision 63280)
@@ -144,12 +144,49 @@ class TestPsych < Psych::TestCase https://github.com/ruby/ruby/blob/trunk/test/psych/test_psych.rb#L144
     }
   end
 
+  def test_load_file_default_return_value
+    Tempfile.create(['empty', 'yml']) {|t|
+      assert_equal false, Psych.load_file(t.path)
+    }
+  end
+
   def test_load_file_with_fallback
     Tempfile.create(['empty', 'yml']) {|t|
+      assert_equal 42, Psych.load_file(t.path, fallback: 42)
+    }
+  end
+
+  def test_load_file_with_fallback_nil_or_false
+    Tempfile.create(['empty', 'yml']) {|t|
+      assert_nil Psych.load_file(t.path, fallback: nil)
+      assert_equal false, Psych.load_file(t.path, fallback: false)
+    }
+  end
+
+  def test_load_file_with_fallback_hash
+    Tempfile.create(['empty', 'yml']) {|t|
       assert_equal Hash.new, Psych.load_file(t.path, fallback: Hash.new)
     }
   end
 
+  def test_load_file_with_fallback_for_nil
+    Tempfile.create(['nil', 'yml']) {|t|
+      t.binmode
+      t.write('--- null')
+      t.close
+      assert_nil Psych.load_file(t.path, fallback: 42)
+    }
+  end
+
+  def test_load_file_with_fallback_for_false
+    Tempfile.create(['false', 'yml']) {|t|
+      t.binmode
+      t.write('--- false')
+      t.close
+      assert_equal false, Psych.load_file(t.path, fallback: 42)
+    }
+  end
+
   def test_parse_file
     Tempfile.create(['yikes', 'yml']) {|t|
       t.binmode
Index: test/psych/test_stream.rb
===================================================================
--- test/psych/test_stream.rb	(revision 63279)
+++ test/psych/test_stream.rb	(revision 63280)
@@ -3,6 +3,22 @@ require_relative 'helper' https://github.com/ruby/ruby/blob/trunk/test/psych/test_stream.rb#L3
 
 module Psych
   class TestStream < TestCase
+    [
+      [Psych::Nodes::Alias, :alias?],
+      [Psych::Nodes::Document, :document?],
+      [Psych::Nodes::Mapping, :mapping?],
+      [Psych::Nodes::Scalar, :scalar?],
+      [Psych::Nodes::Sequence, :sequence?],
+      [Psych::Nodes::Stream, :stream?],
+    ].each do |klass, block|
+      define_method :"test_predicate_#{block}" do
+        rb = Psych.parse_stream("---\n- foo: bar\n- &a !!str Anchored\n- *a")
+        nodes = rb.grep(klass)
+        assert_operator nodes.length, :>, 0
+        assert_equal nodes, rb.find_all(&block)
+      end
+    end
+
     def test_parse_partial
       rb = Psych.parse("--- foo\n...\n--- `").to_ruby
       assert_equal 'foo', rb

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

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