summaryrefslogtreecommitdiff
path: root/test/ruby/test_case.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_case.rb')
-rw-r--r--test/ruby/test_case.rb65
1 files changed, 60 insertions, 5 deletions
diff --git a/test/ruby/test_case.rb b/test/ruby/test_case.rb
index 0067b74e2b..9e8502fb27 100644
--- a/test/ruby/test_case.rb
+++ b/test/ruby/test_case.rb
@@ -1,5 +1,5 @@
+# frozen_string_literal: false
require 'test/unit'
-require_relative 'envutil.rb'
class TestCase < Test::Unit::TestCase
def test_case
@@ -68,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
@@ -81,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
@@ -102,5 +105,57 @@ 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
+ flag = false
+
+ case 1
+ when Class.new(BasicObject) { def method_missing(*) true end }.new
+ flag = true
+ end
+
+ assert(flag)
+ end
+
+ def test_nomethoderror
+ assert_raise(NoMethodError) {
+ case 1
+ when Class.new(BasicObject) { }.new
+ 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