summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-10 13:25:39 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-10 13:25:39 +0000
commitd2e596ad04050ebfe575106ea815849aefb689b2 (patch)
treeb0263011852abcd32f8d941951ffa11c02e6e592 /test/ruby/test_array.rb
parent6d7999c13285a7a2bec9073504703226e1a2b2f2 (diff)
* array.c (rb_ary_slice_bang): If an invalid range is given, do
not raise an exception but return nil just like slice() does. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 6787d9c99c..c0206baed5 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1031,6 +1031,8 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[10, 11, 12], a.slice(9, 3))
assert_equal(@cls[10, 11, 12], a.slice(-91, 3))
+ assert_nil(a.slice(-101, 2))
+
assert_equal(@cls[1], a.slice(0..0))
assert_equal(@cls[100], a.slice(99..99))
assert_equal(@cls[], a.slice(100..100))
@@ -1041,6 +1043,8 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[10, 11, 12], a.slice(9..11))
assert_equal(@cls[10, 11, 12], a.slice(-91..-89))
+ assert_nil(a.slice(-101..-1))
+
assert_nil(a.slice(10, -3))
# Ruby 1.8 feature change:
# Array#slice[size..x] always returns [].
@@ -1072,6 +1076,18 @@ class TestArray < Test::Unit::TestCase
a = @cls[1, 2, 3, 4, 5]
assert_equal(nil, a.slice!(20))
assert_equal(@cls[1, 2, 3, 4, 5], a)
+
+ a = @cls[1, 2, 3, 4, 5]
+ assert_equal(nil, a.slice!(-6))
+ assert_equal(@cls[1, 2, 3, 4, 5], a)
+
+ a = @cls[1, 2, 3, 4, 5]
+ assert_equal(nil, a.slice!(-6..4))
+ assert_equal(@cls[1, 2, 3, 4, 5], a)
+
+ a = @cls[1, 2, 3, 4, 5]
+ assert_equal(nil, a.slice!(-6,2))
+ assert_equal(@cls[1, 2, 3, 4, 5], a)
end
def test_sort