diff options
Diffstat (limited to 'test/ruby/test_optimization.rb')
-rw-r--r-- | test/ruby/test_optimization.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index fe25cdf1c9..c484dcd0c8 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestRubyOptimization < Test::Unit::TestCase @@ -200,4 +201,45 @@ class TestRubyOptimization < Test::Unit::TestCase EOF assert_equal(123, delay { 123 }.call, bug6901) end + + def test_opt_case_dispatch + code = <<-EOF + case foo + when "foo" then :foo + when :sym then :sym + when 6 then :fix + when 0.1 then :float + when 0xffffffffffffffff then :big + else + :nomatch + end + EOF + check = { + 'foo' => :foo, + :sym => :sym, + 6 => :fix, + 0.1 => :float, + 0xffffffffffffffff => :big, + } + iseq = RubyVM::InstructionSequence.compile(code) + assert_match %r{\bopt_case_dispatch\b}, iseq.disasm + check.each do |foo, expect| + assert_equal expect, eval("foo = #{foo.inspect}\n#{code}") + end + assert_equal :nomatch, eval("foo = :blah\n#{code}") + check.each do |foo, _| + klass = foo.class.to_s + assert_separately([], <<-"end;") # do + class #{klass} + undef === + def ===(*args) + false + end + end + foo = #{foo.inspect} + ret = #{code} + assert_equal :nomatch, ret, foo.inspect + end; + end + end end |