summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 17:10:43 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 17:10:43 +0000
commit4beed07cf7ec7a2cdff73c9a0675b40a340fa186 (patch)
tree29ef104afee1469d1804e1128fac1c08beb81271 /test
parent3bec9a875387e0ad7737115d4cd708cdc3e6e7d5 (diff)
merge revision(s) 52928: [Backport #11784]
* insns.def (opt_case_dispatch): check Float#=== redefinition * test/ruby/test_optimization.rb (test_opt_case_dispatch): new [ruby-core:71920] [Bug #11784] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@52977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_optimization.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 4a5484e43d..9250f013c4 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -289,4 +289,45 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_equal(false, "block".freeze)
end;
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