diff options
author | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2014-05-23 20:47:21 +0530 |
---|---|---|
committer | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2014-05-23 20:47:21 +0530 |
commit | 3920d64479c8763e1f0a64db872e5f072268cda9 (patch) | |
tree | 5724a19d8876a3608bea1fb10e6864bdc95c5124 | |
parent | 0cc7f02b890d33a4e3d2a7e09f66781745e33820 (diff) | |
download | rails-3920d64479c8763e1f0a64db872e5f072268cda9.tar.gz rails-3920d64479c8763e1f0a64db872e5f072268cda9.tar.bz2 rails-3920d64479c8763e1f0a64db872e5f072268cda9.zip |
add test cases for negative position in Array#from
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/access.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index 67f58bc0fe..d0791a161f 100644 --- a/activesupport/lib/active_support/core_ext/array/access.rb +++ b/activesupport/lib/active_support/core_ext/array/access.rb @@ -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 diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index e0e54f47e4..4601a80d42 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -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 |