ruby-changes:46755
From: nobu <ko1@a...>
Date: Wed, 24 May 2017 16:57:23 +0900 (JST)
Subject: [ruby-changes:46755] nobu:r58870 (trunk): test_enum.rb: test_inject_array_op_redefined
nobu 2017-05-24 16:57:19 +0900 (Wed, 24 May 2017) New Revision: 58870 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58870 Log: test_enum.rb: test_inject_array_op_redefined * test/ruby/test_enum.rb (test_inject_array_op_redefined): test other operators too. [Bug#12178] Modified files: trunk/test/ruby/test_enum.rb Index: test/ruby/test_enum.rb =================================================================== --- test/ruby/test_enum.rb (revision 58869) +++ test/ruby/test_enum.rb (revision 58870) @@ -213,15 +213,24 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L213 assert_equal(2.0+3.0i, [2.0, 3.0i].inject(:+)) end - def test_inject_array_plus_redefined - assert_separately([], <<-"end;") - class Integer - undef :+ - def +(x) - 0 + def test_inject_array_op_redefined + assert_separately([], "#{<<~"end;"}\n""end") + all_assertions_foreach("", *%i[+ * / - %]) do |op| + bug = '[ruby-dev:49510] [Bug#12178] should respect redefinition' + begin + 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 - assert_equal(0, [1,2,3].inject(:+), "[ruby-dev:49510] [Bug#12178]") end; end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/