diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-14 06:15:58 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-14 06:15:58 +0000 |
commit | 0b396d588060707e227f21b80e964180674c8a50 (patch) | |
tree | 9164cd8f79f9e9b317dad2b399778e47b410cae1 /test/psych | |
parent | e870af8834bd3cb4aded02c6e63a4b817e4648b5 (diff) |
Merge psych-3.0.0.beta3 from ruby/psych.
* Rely on encoding tags to determine if string should be dumped as binary.
https://github.com/ruby/psych/commit/8949a47b8cee31e03e21608406ba116adcf74054
* Specify "frozen_string_literal: true".
* Support to binary release for mingw32 platform.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych')
45 files changed, 67 insertions, 56 deletions
diff --git a/test/psych/handlers/test_recorder.rb b/test/psych/handlers/test_recorder.rb index 17c7c6d0a0..d9d379ea9a 100644 --- a/test/psych/handlers/test_recorder.rb +++ b/test/psych/handlers/test_recorder.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' require 'psych/handlers/recorder' diff --git a/test/psych/helper.rb b/test/psych/helper.rb index 7b564bd2d7..9348457958 100644 --- a/test/psych/helper.rb +++ b/test/psych/helper.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'minitest/autorun' require 'stringio' require 'tempfile' diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb index 519c114b29..90a770c1b7 100644 --- a/test/psych/json/test_stream.rb +++ b/test/psych/json/test_stream.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych diff --git a/test/psych/nodes/test_enumerable.rb b/test/psych/nodes/test_enumerable.rb index 2f4e1f3bd0..76b36856f1 100644 --- a/test/psych/nodes/test_enumerable.rb +++ b/test/psych/nodes/test_enumerable.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych diff --git a/test/psych/test_alias_and_anchor.rb b/test/psych/test_alias_and_anchor.rb index ed009605ca..91c09dfdfa 100644 --- a/test/psych/test_alias_and_anchor.rb +++ b/test/psych/test_alias_and_anchor.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' class ObjectWithInstanceVariables diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb index 6306a049fc..f2bbdcab88 100644 --- a/test/psych/test_array.rb +++ b/test/psych/test_array.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych @@ -15,6 +15,12 @@ module Psych @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 {|o| o.val = 1} y << "foo" << "bar" diff --git a/test/psych/test_boolean.rb b/test/psych/test_boolean.rb index b2803a6550..a4b80fc13d 100644 --- a/test/psych/test_boolean.rb +++ b/test/psych/test_boolean.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_class.rb b/test/psych/test_class.rb index 4e1fd4a1d6..71f7ec31fd 100644 --- a/test/psych/test_class.rb +++ b/test/psych/test_class.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_coder.rb b/test/psych/test_coder.rb index e578d55f2d..5ea8cab966 100644 --- a/test/psych/test_coder.rb +++ b/test/psych/test_coder.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb index 3c8b436098..f73f34628f 100644 --- a/test/psych/test_date_time.rb +++ b/test/psych/test_date_time.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'date' diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index eab230231d..624f4379a6 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_document.rb b/test/psych/test_document.rb index 97de2e15ec..a88dd32f0d 100644 --- a/test/psych/test_document.rb +++ b/test/psych/test_document.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_emitter.rb b/test/psych/test_emitter.rb index 23e68b324e..52d5e9d1c1 100644 --- a/test/psych/test_emitter.rb +++ b/test/psych/test_emitter.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' @@ -7,7 +7,7 @@ module Psych class TestEmitter < TestCase def setup super - @out = StringIO.new('') + @out = StringIO.new(''.dup) @emitter = Psych::Emitter.new @out end diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb index 13ca5dbc74..a4f9f036fd 100644 --- a/test/psych/test_encoding.rb +++ b/test/psych/test_encoding.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb index fa80fdbeb2..3040bfb7a2 100644 --- a/test/psych/test_exception.rb +++ b/test/psych/test_exception.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb index b449ce49e3..e93aa73249 100644 --- a/test/psych/test_hash.rb +++ b/test/psych/test_hash.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_json_tree.rb b/test/psych/test_json_tree.rb index 8bb850b138..3c59a8dbda 100644 --- a/test/psych/test_json_tree.rb +++ b/test/psych/test_json_tree.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_marshalable.rb b/test/psych/test_marshalable.rb index 544947a521..b1f4a837f5 100644 --- a/test/psych/test_marshalable.rb +++ b/test/psych/test_marshalable.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'delegate' diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb index 76245ca7b5..1bc3dd1cb6 100644 --- a/test/psych/test_merge_keys.rb +++ b/test/psych/test_merge_keys.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_nil.rb b/test/psych/test_nil.rb index 3d4fa88eaa..910a2e697d 100644 --- a/test/psych/test_nil.rb +++ b/test/psych/test_nil.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_null.rb b/test/psych/test_null.rb index d8ccb7056f..9d92d74150 100644 --- a/test/psych/test_null.rb +++ b/test/psych/test_null.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_numeric.rb b/test/psych/test_numeric.rb index 9d8b74f7ca..db99a2a0d6 100644 --- a/test/psych/test_numeric.rb +++ b/test/psych/test_numeric.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'bigdecimal' diff --git a/test/psych/test_object.rb b/test/psych/test_object.rb index ed1ccd9bf8..f1c61451d0 100644 --- a/test/psych/test_object.rb +++ b/test/psych/test_object.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_object_references.rb b/test/psych/test_object_references.rb index 1300bfc1db..ca69c7d288 100644 --- a/test/psych/test_object_references.rb +++ b/test/psych/test_object_references.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_omap.rb b/test/psych/test_omap.rb index 80791aa918..98636ded97 100644 --- a/test/psych/test_omap.rb +++ b/test/psych/test_omap.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index 26aba0543b..6b554cedf0 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -1,5 +1,5 @@ # coding: utf-8 -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index 24030d55bc..d0de95627e 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'stringio' @@ -84,7 +84,7 @@ class TestPsych < Psych::TestCase def test_dump_io hash = {'hello' => 'TGIF!'} - stringio = StringIO.new '' + stringio = StringIO.new ''.dup assert_equal stringio, Psych.dump(hash, stringio) assert_equal Psych.dump(hash), stringio.string end diff --git a/test/psych/test_safe_load.rb b/test/psych/test_safe_load.rb index b69c54c199..f3fdb9b9a2 100644 --- a/test/psych/test_safe_load.rb +++ b/test/psych/test_safe_load.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych diff --git a/test/psych/test_scalar.rb b/test/psych/test_scalar.rb index 4353ec33fa..e2f9ec791d 100644 --- a/test/psych/test_scalar.rb +++ b/test/psych/test_scalar.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' @@ -8,5 +8,10 @@ module Psych def test_utf_8 assert_equal "日本語", Psych.load("--- 日本語") end + + def test_some_bytes # Ticket #278 + x = "\xEF\xBF\xBD\x1F" + assert_cycle x + end end end diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb index e51fc69c4a..ebe8daf672 100644 --- a/test/psych/test_scalar_scanner.rb +++ b/test/psych/test_scalar_scanner.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'date' diff --git a/test/psych/test_serialize_subclasses.rb b/test/psych/test_serialize_subclasses.rb index be209edf2f..8e1d0d354d 100644 --- a/test/psych/test_serialize_subclasses.rb +++ b/test/psych/test_serialize_subclasses.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_set.rb b/test/psych/test_set.rb index 0eb999cb2f..5690957eff 100644 --- a/test/psych/test_set.rb +++ b/test/psych/test_set.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb index 1b054289ea..3bd557cb68 100644 --- a/test/psych/test_stream.rb +++ b/test/psych/test_stream.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 4aa6016a59..973f38b9c2 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -1,5 +1,5 @@ # encoding: UTF-8 -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych @@ -166,7 +166,7 @@ string: &70121654388580 !ruby/string end def test_nonascii_string_as_binary - string = "hello \x80 world!" + string = "hello \x80 world!".dup string.force_encoding 'ascii-8bit' yml = Psych.dump string assert_match(/binary/, yml) @@ -174,7 +174,7 @@ string: &70121654388580 !ruby/string end def test_binary_string_null - string = "\x00" + string = "\x00\x92".b yml = Psych.dump string assert_match(/binary/, yml) assert_equal string, Psych.load(yml) @@ -187,8 +187,8 @@ string: &70121654388580 !ruby/string assert_equal string, Psych.load(yml) end - def test_non_binary_string - string = binary_string(0.29) + def test_ascii_only_binary_string + string = "non bnry string".b yml = Psych.dump string refute_match(/binary/, yml) assert_equal string, Psych.load(yml) @@ -202,7 +202,7 @@ string: &70121654388580 !ruby/string end def test_string_with_ivars - food = "is delicious" + food = "is delicious".dup ivar = "on rock and roll" food.instance_variable_set(:@we_built_this_city, ivar) @@ -220,9 +220,9 @@ string: &70121654388580 !ruby/string end def binary_string percentage = 0.31, length = 100 - string = '' + string = ''.b (percentage * length).to_i.times do |i| - string << "\b" + string << "\x92".b end string << 'a' * (length - string.length) string diff --git a/test/psych/test_struct.rb b/test/psych/test_struct.rb index b7968d3189..721df44216 100644 --- a/test/psych/test_struct.rb +++ b/test/psych/test_struct.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' class PsychStructWithIvar < Struct.new(:foo) diff --git a/test/psych/test_symbol.rb b/test/psych/test_symbol.rb index a98881cf4b..36416ffe29 100644 --- a/test/psych/test_symbol.rb +++ b/test/psych/test_symbol.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_tainted.rb b/test/psych/test_tainted.rb index 870583323d..dcf150b138 100644 --- a/test/psych/test_tainted.rb +++ b/test/psych/test_tainted.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych @@ -90,7 +90,7 @@ module Psych end def assert_taintedness string - @parser.parse string.taint + @parser.parse string.dup.taint end end diff --git a/test/psych/test_tree_builder.rb b/test/psych/test_tree_builder.rb index 09f1ee30c9..3e35788e35 100644 --- a/test/psych/test_tree_builder.rb +++ b/test/psych/test_tree_builder.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' module Psych diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index cfba770ee1..5fa759c981 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -1,5 +1,5 @@ # -*- coding: us-ascii; mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- -# frozen_string_literal: false +# frozen_string_literal: true # vim:sw=4:ts=4 # $Id$ # diff --git a/test/psych/test_yamldbm.rb b/test/psych/test_yamldbm.rb index 71ee04f863..1f9ba15cde 100644 --- a/test/psych/test_yamldbm.rb +++ b/test/psych/test_yamldbm.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'tmpdir' diff --git a/test/psych/test_yamlstore.rb b/test/psych/test_yamlstore.rb index a9ce652ced..d1e927cefe 100644 --- a/test/psych/test_yamlstore.rb +++ b/test/psych/test_yamlstore.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require_relative 'helper' require 'yaml/store' require 'tmpdir' diff --git a/test/psych/visitors/test_depth_first.rb b/test/psych/visitors/test_depth_first.rb index 8072c26b57..f8305e15ec 100644 --- a/test/psych/visitors/test_depth_first.rb +++ b/test/psych/visitors/test_depth_first.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych diff --git a/test/psych/visitors/test_emitter.rb b/test/psych/visitors/test_emitter.rb index 9317855bbb..70adbb9ca0 100644 --- a/test/psych/visitors/test_emitter.rb +++ b/test/psych/visitors/test_emitter.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych diff --git a/test/psych/visitors/test_to_ruby.rb b/test/psych/visitors/test_to_ruby.rb index 8878ea22b2..f342bf0a1a 100644 --- a/test/psych/visitors/test_to_ruby.rb +++ b/test/psych/visitors/test_to_ruby.rb @@ -1,5 +1,5 @@ # coding: US-ASCII -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb index 8fc18f2fe6..01f1aecd08 100644 --- a/test/psych/visitors/test_yaml_tree.rb +++ b/test/psych/visitors/test_yaml_tree.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/helper' module Psych @@ -37,7 +37,7 @@ module Psych end def test_binary_formatting - gif = "GIF89a\f\x00\f\x00\x84\x00\x00\xFF\xFF\xF7\xF5\xF5\xEE\xE9\xE9\xE5fff\x00\x00\x00\xE7\xE7\xE7^^^\xF3\xF3\xED\x8E\x8E\x8E\xE0\xE0\xE0\x9F\x9F\x9F\x93\x93\x93\xA7\xA7\xA7\x9E\x9E\x9Eiiiccc\xA3\xA3\xA3\x84\x84\x84\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9!\xFE\x0EMade with GIMP\x00,\x00\x00\x00\x00\f\x00\f\x00\x00\x05, \x8E\x810\x9E\xE3@\x14\xE8i\x10\xC4\xD1\x8A\b\x1C\xCF\x80M$z\xEF\xFF0\x85p\xB8\xB01f\r\e\xCE\x01\xC3\x01\x1E\x10' \x82\n\x01\x00;" + gif = "GIF89a\f\x00\f\x00\x84\x00\x00\xFF\xFF\xF7\xF5\xF5\xEE\xE9\xE9\xE5fff\x00\x00\x00\xE7\xE7\xE7^^^\xF3\xF3\xED\x8E\x8E\x8E\xE0\xE0\xE0\x9F\x9F\x9F\x93\x93\x93\xA7\xA7\xA7\x9E\x9E\x9Eiiiccc\xA3\xA3\xA3\x84\x84\x84\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9!\xFE\x0EMade with GIMP\x00,\x00\x00\x00\x00\f\x00\f\x00\x00\x05, \x8E\x810\x9E\xE3@\x14\xE8i\x10\xC4\xD1\x8A\b\x1C\xCF\x80M$z\xEF\xFF0\x85p\xB8\xB01f\r\e\xCE\x01\xC3\x01\x1E\x10' \x82\n\x01\x00;".b @v << gif scalar = @v.tree.children.first.children.first assert_equal Psych::Nodes::Scalar::LITERAL, scalar.style |