summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcus Stollsteimer <sto.mar@web.de>2017-12-19 23:17:53 +0100
committerMarcus Stollsteimer <sto.mar@web.de>2018-04-24 22:20:04 +0200
commite003ec86219b4466b05de97b757e0e3cfe303ebe (patch)
tree7915c7d27225bae77e53261871fdc40b13826e8d /test
parent89bd0d453f6f4ff15414747dcdd8cfee698ca9bb (diff)
downloadpsych-e003ec86219b4466b05de97b757e0e3cfe303ebe.zip
Add test cases for fallback argument of Psych.load
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_psych.rb25
1 files changed, 25 insertions, 0 deletions
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