Skip to content

Commit

Permalink
Update Psych and its tests to 3.0.3.pre1. See #5142.
Browse files Browse the repository at this point in the history
There are several failures, either regressions in JRuby's psych
code or in SnakeYAML, or new failures from issues only fixed in
the psych C code.
headius committed Apr 16, 2018
1 parent 7464f3a commit 39b94f2
Showing 49 changed files with 311 additions and 232 deletions.
2 changes: 1 addition & 1 deletion lib/pom.rb
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def initialize( name, version, default_spec = true )
ImportedGem.new( 'minitest', '${minitest.version}' ),
ImportedGem.new( 'test-unit', '${test-unit.version}' ),
ImportedGem.new( 'power_assert', '${power_assert.version}' ),
ImportedGem.new( 'psych', '2.2.4' ),
ImportedGem.new( 'psych', '3.0.3.pre1' ),
ImportedGem.new( 'json', '${json.version}' ),
ImportedGem.new( 'jar-dependencies', '${jar-dependencies.version}' ),
ImportedGem.new( 'net-telnet', '0.1.1'),
2 changes: 1 addition & 1 deletion lib/pom.xml
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>rubygems</groupId>
<artifactId>psych</artifactId>
<version>2.2.4</version>
<version>3.0.3.pre1</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
2 changes: 1 addition & 1 deletion test/mri/excludes/Psych/TestEmitter.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exclude :test_line_width, "SnakeYAML defaults to 80, does not handle 0"
exclude :test_line_width, "SnakeYAML defaults to 80, does not handle 0"
3 changes: 2 additions & 1 deletion test/mri/excludes/Psych/TestParser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exclude :test_column_numbers, "column numbers are off"
exclude :test_start_document_version, "fails with SnakeYAML 1.11"
exclude :test_event_location, "new test or regression, #5142"
exclude :test_index_numbers, "indices are off"
exclude :test_line_numbers, "line numbers are off"
exclude :test_start_document_tag, "tag includes extra chars"
exclude :test_start_document_version, "fails with SnakeYAML 1.11"
2 changes: 1 addition & 1 deletion test/mri/psych/handlers/test_recorder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'psych/helper'
require 'psych/handlers/recorder'

20 changes: 13 additions & 7 deletions test/mri/psych/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'minitest/autorun'
require 'stringio'
require 'tempfile'
@@ -50,10 +50,10 @@ def with_default_internal(enc)
def assert_to_yaml( obj, yaml )
assert_equal( obj, Psych::load( yaml ) )
assert_equal( obj, Psych::parse( yaml ).transform )
assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
assert_equal( obj, Psych::parse( obj.psych_to_yaml ).transform )
assert_equal( obj, Psych::load( obj.to_yaml ) )
assert_equal( obj, Psych::parse( obj.to_yaml ).transform )
assert_equal( obj, Psych::load(
obj.psych_to_yaml(
obj.to_yaml(
:UseVersion => true, :UseHeader => true, :SortKeys => true
)
))
@@ -70,9 +70,15 @@ def assert_parse_only( obj, yaml )
def assert_cycle( obj )
v = Visitors::YAMLTree.create
v << obj
assert_equal(obj, Psych.load(v.tree.yaml))
assert_equal( obj, Psych::load(Psych.dump(obj)))
assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
if obj.nil?
assert_nil Psych.load(v.tree.yaml)
assert_nil Psych::load(Psych.dump(obj))
assert_nil Psych::load(obj.to_yaml)
else
assert_equal(obj, Psych.load(v.tree.yaml))
assert_equal(obj, Psych::load(Psych.dump(obj)))
assert_equal(obj, Psych::load(obj.to_yaml))
end
end

#
2 changes: 1 addition & 1 deletion test/mri/psych/json/test_stream.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'psych/helper'

module Psych
2 changes: 1 addition & 1 deletion test/mri/psych/nodes/test_enumerable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'psych/helper'

module Psych
2 changes: 1 addition & 1 deletion test/mri/psych/test_alias_and_anchor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

class ObjectWithInstanceVariables
12 changes: 9 additions & 3 deletions test/mri/psych/test_array.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

module Psych
@@ -15,8 +15,14 @@ def setup
@list = [{ :a => 'b' }, 'foo']
end

def test_enumerator
x = [1, 2, 3, 4]
y = Psych.load Psych.dump x.to_enum
assert_equal x, y
end

def test_another_subclass_with_attributes
y = Y.new.tap {|y| y.val = 1}
y = Y.new.tap {|o| o.val = 1}
y << "foo" << "bar"
y = Psych.load Psych.dump y

@@ -36,7 +42,7 @@ def test_subclass
end

def test_subclass_with_attributes
y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
y = Psych.load Psych.dump Y.new.tap {|o| o.val = 1}
assert_equal Y, y.class
assert_equal 1, y.val
end
2 changes: 1 addition & 1 deletion test/mri/psych/test_boolean.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

module Psych
2 changes: 1 addition & 1 deletion test/mri/psych/test_class.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

module Psych
2 changes: 1 addition & 1 deletion test/mri/psych/test_coder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

module Psych
35 changes: 33 additions & 2 deletions test/mri/psych/test_date_time.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'
require 'date'

module Psych
class TestDateTime < TestCase
def test_negative_year
time = Time.utc -1, 12, 16
time = Time.utc(-1, 12, 16)
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
128 changes: 2 additions & 126 deletions test/mri/psych/test_deprecated.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

module Psych
@@ -8,47 +8,12 @@ def teardown
Psych.domain_types.clear
end

class QuickEmitter
attr_reader :name
attr_reader :value

def initialize
@name = 'hello!!'
@value = 'Friday!'
end

def to_yaml opts = {}
Psych.quick_emit object_id, opts do |out|
out.map taguri, to_yaml_style do |map|
map.add 'name', @name
map.add 'value', nil
end
end
end
end
class QuickEmitter; end

def setup
@qe = QuickEmitter.new
@orig_verbose, $VERBOSE = $VERBOSE, false
end

def test_quick_emit
qe2 = Psych.load @qe.to_yaml
assert_equal @qe.name, qe2.name
assert_instance_of QuickEmitter, qe2
assert_nil qe2.value
end

def test_recursive_quick_emit
hash = { :qe => @qe }
hash2 = Psych.load Psych.dump hash
qe = hash2[:qe]

assert_equal @qe.name, qe.name
assert_instance_of QuickEmitter, qe
assert_nil qe.value
end

class QuickEmitterEncodeWith
attr_reader :name
attr_reader :value
@@ -84,30 +49,6 @@ def test_recursive_quick_emit_encode_with
assert_nil qe.value
end

class YamlInit
attr_reader :name
attr_reader :value

def initialize
@name = 'hello!!'
@value = 'Friday!'
end

def yaml_initialize tag, vals
vals.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
end
end

def test_yaml_initialize
hash = { :yi => YamlInit.new }
hash2 = Psych.load Psych.dump hash
yi = hash2[:yi]

assert_equal 'TGIF!', yi.name
assert_equal 'TGIF!', yi.value
assert_instance_of YamlInit, yi
end

class YamlInitAndInitWith
attr_reader :name
attr_reader :value
@@ -146,70 +87,5 @@ def test_coder_scalar
assert_equal 'some string', coder.scalar
assert_equal :scalar, coder.type
end

class YamlAs
TestCase.suppress_warning do
psych_yaml_as 'helloworld' # this should be yaml_as but to avoid syck
end
end

def test_yaml_as
assert_match(/helloworld/, Psych.dump(YamlAs.new))
end

def test_ruby_type
types = []
appender = lambda { |*args| types << args }

Psych.add_ruby_type('foo', &appender)
Psych.load <<-eoyml
- !ruby.yaml.org,2002/foo bar
eoyml

assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types
end

def test_detect_implicit
assert_equal '', Psych.detect_implicit(nil)
assert_equal '', Psych.detect_implicit(Object.new)
assert_equal '', Psych.detect_implicit(1.2)
assert_equal 'null', Psych.detect_implicit('')
assert_equal 'string', Psych.detect_implicit('foo')
end

def test_private_type
types = []
Psych.add_private_type('foo') { |*args| types << args }
Psych.load <<-eoyml
- !x-private:foo bar
eoyml

assert_equal [["x-private:foo", "bar"]], types
end

def test_tagurize
assert_nil Psych.tagurize nil
assert_equal Psych, Psych.tagurize(Psych)
assert_equal 'tag:yaml.org,2002:foo', Psych.tagurize('foo')
end

def test_read_type_class
things = Psych.read_type_class 'tag:yaml.org,2002:int:Psych::TestDeprecated::QuickEmitter', Object
assert_equal 'int', things.first
assert_equal Psych::TestDeprecated::QuickEmitter, things.last
end

def test_read_type_class_no_class
things = Psych.read_type_class 'tag:yaml.org,2002:int', Object
assert_equal 'int', things.first
assert_equal Object, things.last
end

def test_object_maker
thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' })
assert_instance_of(Object, thing)
assert_equal 'b', thing.instance_variable_get(:@a)
assert_equal 'd', thing.instance_variable_get(:@c)
end
end
end
2 changes: 1 addition & 1 deletion test/mri/psych/test_document.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative 'helper'

module Psych
4 changes: 2 additions & 2 deletions test/mri/psych/test_emitter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: false
# frozen_string_literal: true

require_relative 'helper'

module Psych
class TestEmitter < TestCase
def setup
super
@out = StringIO.new('')
@out = StringIO.new(''.dup)
@emitter = Psych::Emitter.new @out
end

14 changes: 13 additions & 1 deletion test/mri/psych/test_encoding.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: false
# frozen_string_literal: true

require_relative 'helper'

@@ -106,6 +106,18 @@ def test_io_utf8
}
end

def test_io_utf8_read_as_binary
Tempfile.create(['utf8', 'yml']) {|t|
t.binmode
t.write '--- こんにちは!'.encode('UTF-8')
t.close

File.open(t.path, 'rb', :encoding => 'ascii-8bit') do |f|
assert_equal "こんにちは!", Psych.load(f)
end
}
end

def test_emit_alias
@emitter.start_stream Psych::Parser::UTF8
@emitter.start_document [], [], true
Loading

0 comments on commit 39b94f2

Please sign in to comment.