From 6d77e28763ed17f75edf3b4072701b4dbd7644bb Mon Sep 17 00:00:00 2001 From: hsbt Date: Wed, 5 Apr 2017 13:16:32 +0000 Subject: Import psych-3.0.0.beta1 from ruby/psych. * Removed deprecated code. * Removed code related syck gem. * Fixed typos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/psych/helper.rb | 18 +++-- test/psych/test_array.rb | 4 +- test/psych/test_date_time.rb | 2 +- test/psych/test_deprecated.rb | 126 +--------------------------------- test/psych/test_exception.rb | 13 ---- test/psych/test_psych.rb | 4 +- test/psych/test_scalar_scanner.rb | 12 +++- test/psych/test_string.rb | 18 ++--- test/psych/test_to_yaml_properties.rb | 64 ----------------- test/psych/test_yaml.rb | 4 +- test/psych/visitors/test_yaml_tree.rb | 8 +-- 11 files changed, 42 insertions(+), 231 deletions(-) delete mode 100644 test/psych/test_to_yaml_properties.rb (limited to 'test/psych') diff --git a/test/psych/helper.rb b/test/psych/helper.rb index 498cdf8b09..7b564bd2d7 100644 --- a/test/psych/helper.rb +++ b/test/psych/helper.rb @@ -50,10 +50,10 @@ module Psych 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 @@ module Psych 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 # diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb index f1e71fb16c..6306a049fc 100644 --- a/test/psych/test_array.rb +++ b/test/psych/test_array.rb @@ -16,7 +16,7 @@ module Psych 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 +36,7 @@ module Psych 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 diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb index 433fbf3d26..443669d17f 100644 --- a/test/psych/test_date_time.rb +++ b/test/psych/test_date_time.rb @@ -5,7 +5,7 @@ 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 diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index a806f6b972..eab230231d 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -8,47 +8,12 @@ module Psych 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 @@ module Psych 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 @@ module Psych 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 diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb index 85fa78f5df..fa80fdbeb2 100644 --- a/test/psych/test_exception.rb +++ b/test/psych/test_exception.rb @@ -121,19 +121,6 @@ module Psych assert_equal 2, w.bar end - def test_to_yaml_properties - class << @wups - def to_yaml_properties - [:@foo] - end - end - - w = Psych.load(Psych.dump(@wups)) - assert_equal @wups, w - assert_equal 1, w.foo - assert_nil w.bar - end - def test_psych_syntax_error Tempfile.create(['parsefile', 'yml']) do |t| t.binmode diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index 0e769274fd..24030d55bc 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -98,8 +98,8 @@ class TestPsych < Psych::TestCase assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION end - def test_load_documents - docs = Psych.load_documents("--- foo\n...\n--- bar\n...") + def test_load_stream + docs = Psych.load_stream("--- foo\n...\n--- bar\n...") assert_equal %w{ foo bar }, docs end diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb index 25999892bc..e51fc69c4a 100644 --- a/test/psych/test_scalar_scanner.rb +++ b/test/psych/test_scalar_scanner.rb @@ -79,15 +79,21 @@ module Psych end def test_scan_null - assert_equal nil, ss.tokenize('null') - assert_equal nil, ss.tokenize('~') - assert_equal nil, ss.tokenize('') + assert_nil ss.tokenize('null') + assert_nil ss.tokenize('~') + assert_nil ss.tokenize('') end def test_scan_symbol assert_equal :foo, ss.tokenize(':foo') end + def test_scan_not_sexagesimal + assert_equal '00:00:00:00:0f', ss.tokenize('00:00:00:00:0f') + assert_equal '00:00:00:00:00', ss.tokenize('00:00:00:00:00') + assert_equal '00:00:00:00:00.0', ss.tokenize('00:00:00:00:00.0') + end + def test_scan_sexagesimal_float assert_equal 685230.15, ss.tokenize('190:20:30.15') end diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 25c6353cee..4aa6016a59 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -33,28 +33,28 @@ module Psych def test_doublequotes_when_there_is_a_single str = "@123'abc" yaml = Psych.dump str - assert_match /---\s*"/, yaml + assert_match(/---\s*"/, yaml) assert_equal str, Psych.load(yaml) end def test_plain_when_shorten_than_line_width_and_no_final_line_break str = "Lorem ipsum" yaml = Psych.dump str, line_width: 12 - assert_match /---\s*[^>|]+\n/, yaml + assert_match(/---\s*[^>|]+\n/, yaml) assert_equal str, Psych.load(yaml) end def test_plain_when_shorten_than_line_width_and_with_final_line_break str = "Lorem ipsum\n" yaml = Psych.dump str, line_width: 12 - assert_match /---\s*[^>|]+\n/, yaml + assert_match(/---\s*[^>|]+\n/, yaml) assert_equal str, Psych.load(yaml) end def test_folded_when_longer_than_line_width_and_with_final_line_break str = "Lorem ipsum dolor sit\n" yaml = Psych.dump str, line_width: 12 - assert_match /---\s*>\n(.*\n){2}\Z/, yaml + assert_match(/---\s*>\n(.*\n){2}\Z/, yaml) assert_equal str, Psych.load(yaml) end @@ -62,7 +62,7 @@ module Psych def test_folded_strip_when_longer_than_line_width_and_no_newlines str = "Lorem ipsum dolor sit amet, consectetur" yaml = Psych.dump str, line_width: 12 - assert_match /---\s*>-\n(.*\n){3}\Z/, yaml + assert_match(/---\s*>-\n(.*\n){3}\Z/, yaml) assert_equal str, Psych.load(yaml) end @@ -72,7 +72,7 @@ module Psych "Lorem ipsum\nZolor\n", ].each do |str| yaml = Psych.dump str, line_width: 12 - assert_match /---\s*\|\n(.*\n){2}\Z/, yaml + assert_match(/---\s*\|\n(.*\n){2}\Z/, yaml) assert_equal str, Psych.load(yaml) end end @@ -84,7 +84,7 @@ module Psych "Lorem ipsum\nZolor", ].each do |str| yaml = Psych.dump str, line_width: 12 - assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml + assert_match(/---\s*\|-\n(.*\n){2}\Z/, yaml) assert_equal str, Psych.load(yaml) end end @@ -129,7 +129,7 @@ string: &70121654388580 !ruby/string end def test_another_subclass_with_attributes - y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1} + y = Psych.load Psych.dump Y.new("foo").tap {|o| o.val = 1} assert_equal "foo", y assert_equal Y, y.class assert_equal 1, y.val @@ -154,7 +154,7 @@ string: &70121654388580 !ruby/string 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 diff --git a/test/psych/test_to_yaml_properties.rb b/test/psych/test_to_yaml_properties.rb deleted file mode 100644 index 8a29b6a9b9..0000000000 --- a/test/psych/test_to_yaml_properties.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: false -require_relative 'helper' - -module Psych - class TestToYamlProperties < Psych::TestCase - class Foo - attr_accessor :a, :b, :c - def initialize - @a = 1 - @b = 2 - @c = 3 - end - - def to_yaml_properties - [:@a, :@b] - end - end - - def test_object_dump_yaml_properties - foo = Psych.load(Psych.dump(Foo.new)) - assert_equal 1, foo.a - assert_equal 2, foo.b - assert_nil foo.c - end - - class Bar < Struct.new(:foo, :bar) - attr_reader :baz - def initialize *args - super - @baz = 'hello' - end - - def to_yaml_properties - [] - end - end - - def test_struct_dump_yaml_properties - bar = Psych.load(Psych.dump(Bar.new('a', 'b'))) - assert_equal 'a', bar.foo - assert_equal 'b', bar.bar - assert_nil bar.baz - end - - def test_string_dump - string = "okonomiyaki" - class << string - def to_yaml_properties - [:@tastes] - end - end - - string.instance_variable_set(:@tastes, 'delicious') - v = Psych.load Psych.dump string - assert_equal 'delicious', v.instance_variable_get(:@tastes) - end - - def test_string_load_syck - str = Psych.load("--- !str \nstr: okonomiyaki\n:@tastes: delicious\n") - assert_equal 'okonomiyaki', str - assert_equal 'delicious', str.instance_variable_get(:@tastes) - end - end -end diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index f8e9e2f955..cfba770ee1 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -512,7 +512,7 @@ EOY def test_spec_log_file doc_ct = 0 - Psych::load_documents( < nil}, Psych.load('foo: ')) assert_cycle 'null' -- cgit v1.2.3