mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_enum.rb: test_inject_array_op_redefined
* test/ruby/test_enum.rb (test_inject_array_op_redefined): test other operators too. [Bug#12178] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
73d797ad48
commit
da9d5db8bd
1 changed files with 16 additions and 7 deletions
|
@ -213,15 +213,24 @@ class TestEnumerable < Test::Unit::TestCase
|
||||||
assert_equal(2.0+3.0i, [2.0, 3.0i].inject(:+))
|
assert_equal(2.0+3.0i, [2.0, 3.0i].inject(:+))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inject_array_plus_redefined
|
def test_inject_array_op_redefined
|
||||||
assert_separately([], <<-"end;")
|
assert_separately([], "#{<<~"end;"}\n""end")
|
||||||
class Integer
|
all_assertions_foreach("", *%i[+ * / - %]) do |op|
|
||||||
undef :+
|
bug = '[ruby-dev:49510] [Bug#12178] should respect redefinition'
|
||||||
def +(x)
|
begin
|
||||||
0
|
Integer.class_eval do
|
||||||
|
alias_method :orig, op
|
||||||
|
define_method(op) do |x|
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_equal(0, [1,2,3].inject(op), bug)
|
||||||
|
ensure
|
||||||
|
Integer.class_eval do
|
||||||
|
undef_method op
|
||||||
|
alias_method op, :orig
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_equal(0, [1,2,3].inject(:+), "[ruby-dev:49510] [Bug#12178]")
|
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue