diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2013-11-10 22:47:31 -0800 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2013-11-10 22:47:31 -0800 |
commit | 5b1221347d371464fbf69900deef251a9c07fbe9 (patch) | |
tree | 55bc60d393cee93e762c8bd0199ed15234e70aac /activesupport/test | |
parent | b72304f41ed33c266189973c7e8869124fbc2130 (diff) | |
parent | 133399482c12820c6c96c5e0e6697cdcc0f158e3 (diff) | |
download | rails-5b1221347d371464fbf69900deef251a9c07fbe9.tar.gz rails-5b1221347d371464fbf69900deef251a9c07fbe9.tar.bz2 rails-5b1221347d371464fbf69900deef251a9c07fbe9.zip |
Merge pull request #12839 from kuldeepaggarwal/array_split
Array#split preserving the calling array
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 6cd0eb39b7..57722fd52a 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -212,18 +212,24 @@ class ArraySplitTests < ActiveSupport::TestCase end def test_split_with_argument - assert_equal [[1, 2], [4, 5]], [1, 2, 3, 4, 5].split(3) - assert_equal [[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5].split(0) + a = [1, 2, 3, 4, 5] + assert_equal [[1, 2], [4, 5]], a.split(3) + assert_equal [[1, 2, 3, 4, 5]], a.split(0) + assert_equal [1, 2, 3, 4, 5], a end def test_split_with_block - assert_equal [[1, 2], [4, 5], [7, 8], [10]], (1..10).to_a.split { |i| i % 3 == 0 } + a = (1..10).to_a + assert_equal [[1, 2], [4, 5], [7, 8], [10]], a.split { |i| i % 3 == 0 } + assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9 ,10], a end def test_split_with_edge_values - assert_equal [[], [2, 3, 4, 5]], [1, 2, 3, 4, 5].split(1) - assert_equal [[1, 2, 3, 4], []], [1, 2, 3, 4, 5].split(5) - assert_equal [[], [2, 3, 4], []], [1, 2, 3, 4, 5].split { |i| i == 1 || i == 5 } + a = [1, 2, 3, 4, 5] + assert_equal [[], [2, 3, 4, 5]], a.split(1) + assert_equal [[1, 2, 3, 4], []], a.split(5) + assert_equal [[], [2, 3, 4], []], a.split { |i| i == 1 || i == 5 } + assert_equal [1, 2, 3, 4, 5], a end end |