diff options
Diffstat (limited to 'activesupport/test/core_ext/array/grouping_test.rb')
-rw-r--r-- | activesupport/test/core_ext/array/grouping_test.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/activesupport/test/core_ext/array/grouping_test.rb b/activesupport/test/core_ext/array/grouping_test.rb index 2eb0f05141..b06f87c008 100644 --- a/activesupport/test/core_ext/array/grouping_test.rb +++ b/activesupport/test/core_ext/array/grouping_test.rb @@ -1,38 +1,39 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +require "abstract_unit" +require "active_support/core_ext/array" class GroupingTest < ActiveSupport::TestCase def setup - Fixnum.send :private, :/ # test we avoid Integer#/ (redefined by mathn) + # In Ruby < 2.4, test we avoid Integer#/ (redefined by mathn) + Fixnum.send :private, :/ unless 0.class == Integer end def teardown - Fixnum.send :public, :/ + Fixnum.send :public, :/ unless 0.class == Integer end def test_in_groups_of_with_perfect_fit groups = [] - ('a'..'i').to_a.in_groups_of(3) do |group| + ("a".."i").to_a.in_groups_of(3) do |group| groups << group end assert_equal [%w(a b c), %w(d e f), %w(g h i)], groups - assert_equal [%w(a b c), %w(d e f), %w(g h i)], ('a'..'i').to_a.in_groups_of(3) + assert_equal [%w(a b c), %w(d e f), %w(g h i)], ("a".."i").to_a.in_groups_of(3) end def test_in_groups_of_with_padding groups = [] - ('a'..'g').to_a.in_groups_of(3) do |group| + ("a".."g").to_a.in_groups_of(3) do |group| groups << group end - assert_equal [%w(a b c), %w(d e f), ['g', nil, nil]], groups + assert_equal [%w(a b c), %w(d e f), ["g", nil, nil]], groups end def test_in_groups_of_pads_with_specified_values groups = [] - ('a'..'g').to_a.in_groups_of(3, 'foo') do |group| + ("a".."g").to_a.in_groups_of(3, "foo") do |group| groups << group end @@ -42,7 +43,7 @@ class GroupingTest < ActiveSupport::TestCase def test_in_groups_of_without_padding groups = [] - ('a'..'g').to_a.in_groups_of(3, false) do |group| + ("a".."g").to_a.in_groups_of(3, false) do |group| groups << group end @@ -82,8 +83,8 @@ class GroupingTest < ActiveSupport::TestCase assert_equal [[1, 2, 3], [4, 5, nil], [6, 7, nil]], array.in_groups(3) - assert_equal [[1, 2, 3], [4, 5, 'foo'], [6, 7, 'foo']], - array.in_groups(3, 'foo') + assert_equal [[1, 2, 3], [4, 5, "foo"], [6, 7, "foo"]], + array.in_groups(3, "foo") end def test_in_groups_without_padding @@ -123,4 +124,12 @@ class SplitTest < ActiveSupport::TestCase assert_equal [[], [2, 3, 4], []], a.split { |i| i == 1 || i == 5 } assert_equal [1, 2, 3, 4, 5], a end + + def test_split_with_repeated_values + a = [1, 2, 3, 5, 5, 3, 4, 6, 2, 1, 3] + assert_equal [[1, 2], [5, 5], [4, 6, 2, 1], []], a.split(3) + assert_equal [[1, 2, 3], [], [3, 4, 6, 2, 1, 3]], a.split(5) + assert_equal [[1, 2], [], [], [], [4, 6, 2, 1], []], a.split { |i| i == 3 || i == 5 } + assert_equal [1, 2, 3, 5, 5, 3, 4, 6, 2, 1, 3], a + end end |