mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_optimization.rb: restore method before calling assert_equal.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9987d53e51
commit
c2d5527bff
2 changed files with 34 additions and 84 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Feb 27 00:45:23 2007 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* test/ruby/test_optimization.rb: restore method before calling
|
||||||
|
assert_equal.
|
||||||
|
|
||||||
Mon Feb 26 00:58:39 2007 Koichi Sasada <ko1@atdot.net>
|
Mon Feb 26 00:58:39 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* yarvcore.h: add rb_thread_t#top_wrapper, top_self.
|
* yarvcore.h: add rb_thread_t#top_wrapper, top_self.
|
||||||
|
|
|
@ -16,6 +16,30 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
FIXNUM_MIN = -1073741824 # -2 ** 30
|
FIXNUM_MIN = -1073741824 # -2 ** 30
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redefine_method(klass, method)
|
||||||
|
(@redefine_method_seq ||= 0)
|
||||||
|
seq = (@redefine_method_seq += 1)
|
||||||
|
eval(<<-End, ::TOPLEVEL_BINDING)
|
||||||
|
class #{klass}
|
||||||
|
alias redefine_method_orig_#{seq} #{method}
|
||||||
|
undef #{method}
|
||||||
|
def #{method}(*args)
|
||||||
|
args[0]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
End
|
||||||
|
begin
|
||||||
|
return yield
|
||||||
|
ensure
|
||||||
|
eval(<<-End, ::TOPLEVEL_BINDING)
|
||||||
|
class #{klass}
|
||||||
|
undef #{method}
|
||||||
|
alias #{method} redefine_method_orig_#{seq}
|
||||||
|
end
|
||||||
|
End
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_fixnum_plus
|
def test_fixnum_plus
|
||||||
a, b = 1, 2
|
a, b = 1, 2
|
||||||
assert_equal 3, a + b
|
assert_equal 3, a + b
|
||||||
|
@ -23,23 +47,7 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
assert_instance_of Bignum, FIXNUM_MAX + 1
|
assert_instance_of Bignum, FIXNUM_MAX + 1
|
||||||
|
|
||||||
assert_equal 21, 10 + 11
|
assert_equal 21, 10 + 11
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
assert_equal 11, redefine_method('Fixnum', '+') { 10 + 11 }
|
||||||
class Fixnum
|
|
||||||
alias orig_plus +
|
|
||||||
undef +
|
|
||||||
def +(other)
|
|
||||||
other
|
|
||||||
end
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 11, 10 + 11
|
|
||||||
ensure
|
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
|
||||||
class Fixnum
|
|
||||||
undef +
|
|
||||||
alias + orig_plus
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 21, 10 + 11
|
assert_equal 21, 10 + 11
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,23 +57,7 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
assert_instance_of Bignum, FIXNUM_MIN - 1
|
assert_instance_of Bignum, FIXNUM_MIN - 1
|
||||||
|
|
||||||
assert_equal 5, 8 - 3
|
assert_equal 5, 8 - 3
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
assert_equal 3, redefine_method('Fixnum', '-') { 8 - 3 }
|
||||||
class Fixnum
|
|
||||||
alias orig_minus -
|
|
||||||
undef -
|
|
||||||
def -(other)
|
|
||||||
other
|
|
||||||
end
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 3, 8 - 3
|
|
||||||
ensure
|
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
|
||||||
class Fixnum
|
|
||||||
undef -
|
|
||||||
alias - orig_minus
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 5, 8 - 3
|
assert_equal 5, 8 - 3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,44 +75,13 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_float_plus
|
def test_float_plus
|
||||||
assert_equal 4.0, 2.0 + 2.0
|
assert_equal 4.0, 2.0 + 2.0
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
assert_equal 2.0, redefine_method('Float', '+') { 2.0 + 2.0 }
|
||||||
class Float
|
|
||||||
alias orig_plus +
|
|
||||||
undef +
|
|
||||||
def +(other)
|
|
||||||
other
|
|
||||||
end
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 2.0, 2.0 + 2.0
|
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
|
||||||
class Float
|
|
||||||
undef +
|
|
||||||
alias + orig_plus
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 4.0, 2.0 + 2.0
|
assert_equal 4.0, 2.0 + 2.0
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_string_length
|
def test_string_length
|
||||||
assert_equal 6, "string".length
|
assert_equal 6, "string".length
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
assert_nil redefine_method('String', 'length') { "string".length }
|
||||||
class String
|
|
||||||
alias orig_length length
|
|
||||||
undef length
|
|
||||||
def length
|
|
||||||
99
|
|
||||||
end
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 99, "string".length
|
|
||||||
ensure
|
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
|
||||||
class String
|
|
||||||
undef length
|
|
||||||
alias length orig_length
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 6, "string".length
|
assert_equal 6, "string".length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,23 +90,7 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
assert_equal "x", "x" + ""
|
assert_equal "x", "x" + ""
|
||||||
assert_equal "x", "" + "x"
|
assert_equal "x", "" + "x"
|
||||||
assert_equal "ab", "a" + "b"
|
assert_equal "ab", "a" + "b"
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
assert_equal 'b', redefine_method('String', '+') { "a" + "b" }
|
||||||
class String
|
|
||||||
alias orig_plus +
|
|
||||||
undef +
|
|
||||||
def +(other)
|
|
||||||
'OK'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal 'OK', "a" + "b"
|
|
||||||
ensure
|
|
||||||
eval(<<-End, ::TOPLEVEL_BINDING)
|
|
||||||
class String
|
|
||||||
undef +
|
|
||||||
alias + orig_plus
|
|
||||||
end
|
|
||||||
End
|
|
||||||
assert_equal "ab", "a" + "b"
|
assert_equal "ab", "a" + "b"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue