[ruby/psych] duplicate more tests

a3be6429bf
This commit is contained in:
OrenGitHub 2025-04-29 06:38:21 +03:00 committed by git
parent ae299cc9cd
commit 451e1dcf31

View file

@ -89,6 +89,7 @@ class TestPsych < Psych::TestCase
things = [22, "foo \n", {}] things = [22, "foo \n", {}]
stream = Psych.dump_stream(*things) stream = Psych.dump_stream(*things)
assert_equal things, Psych.load_stream(stream) assert_equal things, Psych.load_stream(stream)
assert_equal things, Psych.safe_load_stream(stream)
end end
def test_dump_file def test_dump_file
@ -119,6 +120,8 @@ class TestPsych < Psych::TestCase
def test_load_stream def test_load_stream
docs = Psych.load_stream("--- foo\n...\n--- bar\n...") docs = Psych.load_stream("--- foo\n...\n--- bar\n...")
assert_equal %w{ foo bar }, docs assert_equal %w{ foo bar }, docs
safe_docs = Psych.safe_load_stream("--- foo\n...\n--- bar\n...")
assert_equal %w{ foo bar }, safe_docs
end end
def test_load_stream_freeze def test_load_stream_freeze
@ -138,10 +141,18 @@ class TestPsych < Psych::TestCase
assert_equal [], Psych.load_stream("") assert_equal [], Psych.load_stream("")
end end
def test_safe_load_stream_default_fallback
assert_equal [], Psych.safe_load_stream("")
end
def test_load_stream_raises_on_bad_input def test_load_stream_raises_on_bad_input
assert_raise(Psych::SyntaxError) { Psych.load_stream("--- `") } assert_raise(Psych::SyntaxError) { Psych.load_stream("--- `") }
end end
def test_safe_load_stream_raises_on_bad_input
assert_raise(Psych::SyntaxError) { Psych.safe_load_stream("--- `") }
end
def test_parse_stream def test_parse_stream
docs = Psych.parse_stream("--- foo\n...\n--- bar\n...") docs = Psych.parse_stream("--- foo\n...\n--- bar\n...")
assert_equal(%w[foo bar], docs.children.map(&:transform)) assert_equal(%w[foo bar], docs.children.map(&:transform))