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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2018-04-28 01:47:58 +00:00
parent 13dc8e4ef0
commit f114089585
14 changed files with 100 additions and 11 deletions

View file

@ -144,12 +144,49 @@ class TestPsych < Psych::TestCase
}
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

View file

@ -3,6 +3,22 @@ require_relative 'helper'
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