diff options
author | Kenta Murata <mrkn@users.noreply.github.com> | 2020-10-23 15:26:51 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-23 15:26:51 +0900 |
commit | f754b422855131111092c0c147d744775cc4793f (patch) | |
tree | 1ca57f3b6cedb36549c456a79a57cffce940e6fc /test/ruby/test_numeric.rb | |
parent | 40bad72f31248c48048249b1d7536e87b4994664 (diff) | |
download | ruby-f754b422855131111092c0c147d744775cc4793f.tar.gz |
numeric.c, range.c: prohibit zero step
* numeric.c: prohibit zero step in Numeric#step
* range.c: prohibit zero step in Range#step
* Fix ruby-spec
[Feature #15573]
Diffstat (limited to 'test/ruby/test_numeric.rb')
-rw-r--r-- | test/ruby/test_numeric.rb | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 0fcf385c0d..c8751fbc57 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -267,12 +267,7 @@ class TestNumeric < Test::Unit::TestCase assert_raise(ArgumentError) { 1.step(10, "1") { } } assert_raise(ArgumentError) { 1.step(10, "1").size } assert_raise(TypeError) { 1.step(10, nil) { } } - assert_nothing_raised { 1.step(10, 0).size } assert_nothing_raised { 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) } - assert_nothing_raised { 1.step(by: 0).size } assert_nothing_raised { 1.step(by: nil) } assert_nothing_raised { 1.step(by: nil).size } @@ -292,6 +287,22 @@ class TestNumeric < Test::Unit::TestCase assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11) {} } assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11).size } + feature15573 = "[ruby-core:91324] [Feature #15573]" + assert_raise(ArgumentError, feature15573) { 1.step(10, 0) } + assert_raise(ArgumentError, feature15573) { 1.step(10, by: 0) } + assert_raise(ArgumentError, feature15573) { 1.step(10, 0) { break } } + assert_raise(ArgumentError, feature15573) { 1.step(10, by: 0) { break } } + assert_raise(ArgumentError, feature15573) { 42.step(by: 0, to: -Float::INFINITY) } + assert_raise(ArgumentError, feature15573) { 42.step(by: 0, to: 42.5) } + assert_raise(ArgumentError, feature15573) { 4.2.step(by: 0.0) } + assert_raise(ArgumentError, feature15573) { 4.2.step(by: -0.0) } + assert_raise(ArgumentError, feature15573) { 42.step(by: 0.0, to: 44) } + assert_raise(ArgumentError, feature15573) { 42.step(by: 0.0, to: 0) } + assert_raise(ArgumentError, feature15573) { 42.step(by: -0.0, to: 44) } + assert_raise(ArgumentError, feature15573) { bignum.step(by: 0) } + assert_raise(ArgumentError, feature15573) { bignum.step(by: 0.0) } + assert_raise(ArgumentError, feature15573) { bignum.step(by: 0, to: bignum+1) } + assert_raise(ArgumentError, feature15573) { bignum.step(by: 0, to: 0) } e = 1.step(10, {by: "1"}) assert_raise(TypeError) {e.next} @@ -322,8 +333,6 @@ class TestNumeric < Test::Unit::TestCase assert_step [], [2, 1, 3] assert_step [], [-2, -1, -3] - assert_step [3, 3, 3, 3], [3, by: 0], inf: true - assert_step [3, 3, 3, 3], [3, by: 0, to: 42], inf: true assert_step [10], [10, 1, -bignum] assert_step [], [1, 0, Float::INFINITY] @@ -333,19 +342,6 @@ class TestNumeric < Test::Unit::TestCase assert_step [10, 11, 12, 13], [10], inf: true assert_step [10, 9, 8, 7], [10, by: -1], inf: true assert_step [10, 9, 8, 7], [10, by: -1, to: nil], inf: true - - assert_step [42, 42, 42, 42], [42, by: 0, to: -Float::INFINITY], inf: true - assert_step [42, 42, 42, 42], [42, by: 0, to: 42.5], inf: true - assert_step [4.2, 4.2, 4.2, 4.2], [4.2, by: 0.0], inf: true - assert_step [4.2, 4.2, 4.2, 4.2], [4.2, by: -0.0], inf: true - assert_step [42.0, 42.0, 42.0, 42.0], [42, by: 0.0, to: 44], inf: true - assert_step [42.0, 42.0, 42.0, 42.0], [42, by: 0.0, to: 0], inf: true - assert_step [42.0, 42.0, 42.0, 42.0], [42, by: -0.0, to: 44], inf: true - - assert_step [bignum]*4, [bignum, by: 0], inf: true - assert_step [bignum]*4, [bignum, by: 0.0], inf: true - assert_step [bignum]*4, [bignum, by: 0, to: bignum+1], inf: true - assert_step [bignum]*4, [bignum, by: 0, to: 0], inf: true end def test_step_bug15537 |