summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-16 07:06:02 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-16 07:06:02 +0000
commit67ec7b5391a61985580db0abbae86f595a86d0d9 (patch)
tree8f74e4d581a1438b654b014afa42f9d8c40b60e9 /test
parent682e86bebc5f118be2defe9ffea8c9106af153f2 (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_1@53145 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_iseq.rb20
-rw-r--r--test/ruby/test_optimization.rb42
2 files changed, 62 insertions, 0 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 5fe90b0ebf..7fc6dba53e 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -52,6 +52,26 @@ class TestISeq < Test::Unit::TestCase
assert_raise_with_message(TypeError, /:foobar/) {RubyVM::InstructionSequence.load(ary)}
end if defined?(RubyVM::InstructionSequence.load)
+ def test_loaded_cdhash_mark
+ iseq = RubyVM::InstructionSequence.compile(<<-'end;', __FILE__, __FILE__, __LINE__+1)
+ def bug(kw)
+ case kw
+ when "false" then false
+ when "true" then true
+ when "nil" then nil
+ else raise("unhandled argument: #{kw.inspect}")
+ end
+ end
+ end;
+ assert_separately([], <<-"end;")
+ iseq = #{iseq.to_a.inspect}
+ RubyVM::InstructionSequence.load(iseq).eval
+ assert_equal(false, bug("false"))
+ GC.start
+ assert_equal(false, bug("false"))
+ end;
+ end if defined?(RubyVM::InstructionSequence.load)
+
def test_disasm_encoding
src = "\u{3042} = 1; \u{3042}"
enc, Encoding.default_internal = Encoding.default_internal, src.encoding
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