add test cases for negative position in Array#from

This commit is contained in:
Kuldeep Aggarwal 2014-05-23 20:47:21 +05:30
parent 0cc7f02b89
commit 3920d64479
2 changed files with 4 additions and 0 deletions

View File

@ -5,6 +5,8 @@ class Array
# %w( a b c d ).from(2) # => ["c", "d"]
# %w( a b c d ).from(10) # => []
# %w().from(0) # => []
# %w( a b c d ).from(-2) # => ["c", "d"]
# %w( a b c ).from(-10) # => []
def from(position)
self[position, length] || []
end

View File

@ -10,6 +10,8 @@ class ArrayExtAccessTests < ActiveSupport::TestCase
assert_equal %w( a b c d ), %w( a b c d ).from(0)
assert_equal %w( c d ), %w( a b c d ).from(2)
assert_equal %w(), %w( a b c d ).from(10)
assert_equal %w( d e ), %w( a b c d e ).from(-2)
assert_equal %w(), %w( a b c d e ).from(-10)
end
def test_to