diff options
author | Sam Stephenson <sam@37signals.com> | 2006-04-13 05:12:43 +0000 |
---|---|---|
committer | Sam Stephenson <sam@37signals.com> | 2006-04-13 05:12:43 +0000 |
commit | c71607e29c4ab5cd7b4ac7d3ef902868ab1cebf7 (patch) | |
tree | 625b21db6492a303fbd20d1973f6fc891233e5ff /activesupport/test | |
parent | bdb2a2f1cb645a5dfde2de3b03f0f22b54b8b5d0 (diff) | |
download | rails-c71607e29c4ab5cd7b4ac7d3ef902868ab1cebf7.tar.gz rails-c71607e29c4ab5cd7b4ac7d3ef902868ab1cebf7.tar.bz2 rails-c71607e29c4ab5cd7b4ac7d3ef902868ab1cebf7.zip |
Add Array#split for dividing arrays into one or more subarrays by value or block
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4208 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 0df27fde66..caf3af2345 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -69,7 +69,28 @@ class ArrayExtGroupingTests < Test::Unit::TestCase end end -class ArraToXmlTests < Test::Unit::TestCase +class ArraySplitTests < Test::Unit::TestCase + def test_split_with_empty_array + assert_equal [[]], [].split(0) + 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) + end + + def test_split_with_block + assert_equal [[1, 2], [4, 5], [7, 8], [10]], (1..10).to_a.split { |i| i % 3 == 0 } + 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 } + end +end + +class ArrayToXmlTests < Test::Unit::TestCase def test_to_xml xml = [ { :name => "David", :age => 26 }, { :name => "Jason", :age => 31 } |