summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
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