From e003ec86219b4466b05de97b757e0e3cfe303ebe Mon Sep 17 00:00:00 2001 From: Marcus Stollsteimer Date: Tue, 19 Dec 2017 23:17:53 +0100 Subject: Add test cases for fallback argument of Psych.load --- test/psych/test_psych.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index 8f9a100..a67342f 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -135,6 +135,31 @@ class TestPsych < Psych::TestCase assert_equal({ 'hello' => 'world' }, got) end + def test_load_default_return_value + assert_equal false, Psych.load("") + end + + def test_load_with_fallback + assert_equal 42, Psych.load("", "file", fallback: 42) + end + + def test_load_with_fallback_nil_or_false + assert_nil Psych.load("", "file", fallback: nil) + assert_equal false, Psych.load("", "file", fallback: false) + end + + def test_load_with_fallback_hash + assert_equal Hash.new, Psych.load("", "file", fallback: Hash.new) + end + + def test_load_with_fallback_for_nil + assert_nil Psych.load("--- null", "file", fallback: 42) + end + + def test_load_with_fallback_for_false + assert_equal false, Psych.load("--- false", "file", fallback: 42) + end + def test_load_file Tempfile.create(['yikes', 'yml']) {|t| t.binmode -- cgit v1.2.3