From 3920d64479c8763e1f0a64db872e5f072268cda9 Mon Sep 17 00:00:00 2001 From: Kuldeep Aggarwal Date: Fri, 23 May 2014 20:47:21 +0530 Subject: [PATCH] add test cases for negative position in Array#from --- activesupport/lib/active_support/core_ext/array/access.rb | 2 ++ activesupport/test/core_ext/array_ext_test.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index 67f58bc0fe5..d0791a161fd 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 e0e54f47e46..4601a80d420 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