ruby-changes:46986
From: hsbt <ko1@a...>
Date: Fri, 16 Jun 2017 16:02:28 +0900 (JST)
Subject: [ruby-changes:46986] hsbt:r59101 (trunk): Merge psych-3.0.0.beta2 from https://github.com/ruby/psych
hsbt 2017-06-16 16:02:22 +0900 (Fri, 16 Jun 2017) New Revision: 59101 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59101 Log: Merge psych-3.0.0.beta2 from https://github.com/ruby/psych It contains following changes from 3.0.0.beta1 * Preserve time zone offset when deserializing times https://github.com/ruby/psych/pull/316 * Enable YAML serialization of Ruby delegators https://github.com/ruby/psych/pull/158 Modified files: trunk/ext/psych/lib/psych/scalar_scanner.rb trunk/ext/psych/lib/psych/versions.rb trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/ext/psych/psych.gemspec trunk/test/psych/test_date_time.rb trunk/test/psych/visitors/test_yaml_tree.rb Index: test/psych/test_date_time.rb =================================================================== --- test/psych/test_date_time.rb (revision 59100) +++ test/psych/test_date_time.rb (revision 59101) @@ -9,10 +9,41 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_date_time.rb#L9 assert_cycle time end + def test_usec + time = Time.utc(2017, 4, 13, 12, 0, 0, 5) + assert_cycle time + end + + def test_non_utc + time = Time.new(2017, 4, 13, 12, 0, 0.5, "+09:00") + assert_cycle time + end + + def test_timezone_offset + times = [Time.new(2017, 4, 13, 12, 0, 0, "+09:00"), + Time.new(2017, 4, 13, 12, 0, 0, "-05:00")] + cycled = Psych::load(Psych.dump times) + assert_match(/12:00:00 \+0900/, cycled.first.to_s) + assert_match(/12:00:00 -0500/, cycled.last.to_s) + end + def test_new_datetime assert_cycle DateTime.new end + def test_datetime_non_utc + dt = DateTime.new(2017, 4, 13, 12, 0, 0.5, "+09:00") + assert_cycle dt + end + + def test_datetime_timezone_offset + times = [DateTime.new(2017, 4, 13, 12, 0, 0, "+09:00"), + DateTime.new(2017, 4, 13, 12, 0, 0, "-05:00")] + cycled = Psych::load(Psych.dump times) + assert_match(/12:00:00\+09:00/, cycled.first.to_s) + assert_match(/12:00:00-05:00/, cycled.last.to_s) + end + def test_invalid_date assert_cycle "2013-10-31T10:40:07-000000000000033" end Index: test/psych/visitors/test_yaml_tree.rb =================================================================== --- test/psych/visitors/test_yaml_tree.rb (revision 59100) +++ test/psych/visitors/test_yaml_tree.rb (revision 59101) @@ -4,6 +4,15 @@ require 'psych/helper' https://github.com/ruby/ruby/blob/trunk/test/psych/visitors/test_yaml_tree.rb#L4 module Psych module Visitors class TestYAMLTree < TestCase + class TestDelegatorClass < Delegator + def initialize(obj); super; @obj = obj; end + def __setobj__(obj); @obj = obj; end + def __getobj__; @obj; end + end + + class TestSimpleDelegatorClass < SimpleDelegator + end + def setup super @v = Visitors::YAMLTree.create @@ -175,6 +184,14 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/visitors/test_yaml_tree.rb#L184 assert_cycle 'nUll' assert_cycle '~' end + + def test_delegator + assert_cycle(TestDelegatorClass.new([1, 2, 3])) + end + + def test_simple_delegator + assert_cycle(TestSimpleDelegatorClass.new([1, 2, 3])) + end end end end Index: ext/psych/lib/psych/versions.rb =================================================================== --- ext/psych/lib/psych/versions.rb (revision 59100) +++ ext/psych/lib/psych/versions.rb (revision 59101) @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/versions.rb#L1 # frozen_string_literal: false module Psych # The version is Psych you're using - VERSION = '3.0.0.beta1' + VERSION = '3.0.0.beta2' if RUBY_ENGINE == 'jruby' DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze Index: ext/psych/lib/psych/scalar_scanner.rb =================================================================== --- ext/psych/lib/psych/scalar_scanner.rb (revision 59100) +++ ext/psych/lib/psych/scalar_scanner.rb (revision 59101) @@ -143,7 +143,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/scalar_scanner.rb#L143 offset += ((tz[1] || 0) * 60) end - klass.at((time - offset).to_i, us) + klass.new(yy, m, dd, hh, mm, ss+us/(1_000_000r), offset) end end end Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 59100) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 59101) @@ -164,6 +164,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L164 @emitter.end_mapping end + alias :visit_Delegator :visit_Object + def visit_Struct o tag = ['!ruby/struct', o.class.name].compact.join(':') Index: ext/psych/psych.gemspec =================================================================== --- ext/psych/psych.gemspec (revision 59100) +++ ext/psych/psych.gemspec (revision 59101) @@ -2,10 +2,10 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/psych.gemspec#L2 Gem::Specification.new do |s| s.name = "psych" - s.version = "3.0.0.beta1" + s.version = "3.0.0.beta2" s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"] s.email = ["aaron@t...", "hsbt@r...", "headius@h..."] - s.date = "2016-11-14" + s.date = "2017-06-16" 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] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/