diff options
Diffstat (limited to 'test/ruby/test_case.rb')
| -rw-r--r-- | test/ruby/test_case.rb | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/test/ruby/test_case.rb b/test/ruby/test_case.rb index f20d1dfd7e..9e8502fb27 100644 --- a/test/ruby/test_case.rb +++ b/test/ruby/test_case.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'test/unit' class TestCase < Test::Unit::TestCase @@ -67,10 +68,13 @@ class TestCase < Test::Unit::TestCase assert(false) end - assert_raise(NameError) do - case - when false, *x, false + begin + verbose_bak, $VERBOSE = $VERBOSE, nil + assert_raise(NameError) do + eval("case; when false, *x, false; end") end + ensure + $VERBOSE = verbose_bak end end @@ -80,7 +84,7 @@ class TestCase < Test::Unit::TestCase EOS assert_in_out_err(['-e', <<-EOS], '', %w[42], []) - class Fixnum; undef ===; def ===(o); p 42; true; end; end; case 1; when 1; end + class Integer; undef ===; def ===(o); p 42; true; end; end; case 1; when 1; end EOS end @@ -101,6 +105,18 @@ class TestCase < Test::Unit::TestCase else assert(false) end + case 0 + when 0r + assert(true) + else + assert(false) + end + case 0 + when 0i + assert(true) + else + assert(false) + end end def test_method_missing @@ -121,4 +137,25 @@ class TestCase < Test::Unit::TestCase end } end + + module NilEqq + refine NilClass do + def === other + false + end + end + end + + class NilEqqClass + using NilEqq + + def eqq(a) + case a; when nil then nil; else :not_nil; end + end + end + + + def test_deoptimize_nil + assert_equal :not_nil, NilEqqClass.new.eqq(nil) + end end |
