mirror of https://github.com/rails/rails
add test cases for negative position in Array#from
This commit is contained in:
parent
0cc7f02b89
commit
3920d64479
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue