Skip to content

Commit

Permalink
Add out of range tests for Array#slice!
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Aug 29, 2021
1 parent 7731be9 commit 5dc36dd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/ruby/test_array.rb
Expand Up @@ -1624,6 +1624,19 @@ def test_slice!
assert_raise(ArgumentError) { @cls[1].slice!(0, 0, 0) }
end

def test_slice_out_of_range!
a = @cls[*(1..100).to_a]

assert_nil(a.clone.slice!(-101..-1))
assert_nil(a.clone.slice!(-101..))

# assert_raise_with_message(RangeError, "((-101..-1).%(2)) out of range") { a.clone.slice!((-101..-1)%2) }
# assert_raise_with_message(RangeError, "((-101..).%(2)) out of range") { a.clone.slice!((-101..)%2) }

assert_nil(a.clone.slice!(10, -3))
assert_equal @cls[], a.clone.slice!(10..7)
end

def test_sort
a = @cls[ 4, 1, 2, 3 ]
assert_equal(@cls[1, 2, 3, 4], a.sort)
Expand Down

0 comments on commit 5dc36dd

Please sign in to comment.