ruby-changes:30709
From: knu <ko1@a...>
Date: Tue, 3 Sep 2013 07:55:06 +0900 (JST)
Subject: [ruby-changes:30709] knu:r42788 (trunk): Retain behavior of Numeric#step when nil is given as second argument.
knu 2013-09-03 07:54:58 +0900 (Tue, 03 Sep 2013) New Revision: 42788 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42788 Log: Retain behavior of Numeric#step when nil is given as second argument. * numeric.c (NUM_STEP_SCAN_ARGS): On sencond thought, keep Numeral#step backward compatible in that it raises TypeError when nil is given as second argument. * test/ruby/test_float.rb (TestFloat#test_num2dbl): Revert. * test/ruby/test_numeric.rb (TestNumeric#test_step): Fix test cases for the above change. Modified files: trunk/ChangeLog trunk/numeric.c trunk/test/ruby/test_float.rb trunk/test/ruby/test_numeric.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42787) +++ ChangeLog (revision 42788) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Sep 3 07:49:25 2013 Akinori MUSHA <knu@i...> + + * numeric.c (NUM_STEP_SCAN_ARGS): On sencond thought, keep + Numeral#step backward compatible in that it raises TypeError + when nil is given as second argument. + + * test/ruby/test_float.rb (TestFloat#test_num2dbl): Revert. + + * test/ruby/test_numeric.rb (TestNumeric#test_step): Fix test + cases for the above change. + Tue Sep 3 07:39:58 2013 Tanaka Akira <akr@f...> * bignum.c (bytes_2comp): Define it only for little endian Index: numeric.c =================================================================== --- numeric.c (revision 42787) +++ numeric.c (revision 42788) @@ -1854,6 +1854,9 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/numeric.c#L1854 } \ else { \ /* compatibility */ \ + if (argc > 1 && NIL_P(step)) { \ + rb_raise(rb_eTypeError, "step must be numeric"); \ + } \ if (rb_equal(step, INT2FIX(0))) { \ rb_raise(rb_eArgError, "step can't be 0"); \ } \ Index: test/ruby/test_float.rb =================================================================== --- test/ruby/test_float.rb (revision 42787) +++ test/ruby/test_float.rb (revision 42788) @@ -561,6 +561,9 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L561 assert_raise(TypeError) do 1.0.step(2.0, "0.5") {} end + assert_raise(TypeError) do + 1.0.step(2.0, nil) {} + end end def test_sleep_with_Float Index: test/ruby/test_numeric.rb =================================================================== --- test/ruby/test_numeric.rb (revision 42787) +++ test/ruby/test_numeric.rb (revision 42788) @@ -229,8 +229,8 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L229 assert_raise(ArgumentError) { 1.step(10, 0).size } assert_raise(TypeError) { 1.step(10, "1") { } } assert_raise(TypeError) { 1.step(10, "1").size } - assert_nothing_raised { 1.step(10, nil) { } } - assert_nothing_raised { 1.step(10, nil).size } + assert_raise(TypeError) { 1.step(10, nil) { } } + assert_raise(TypeError) { 1.step(10, nil).size } assert_nothing_raised { 1.step(by: 0, to: nil) } assert_nothing_raised { 1.step(by: 0, to: nil).size } assert_nothing_raised { 1.step(by: 0) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/