Sha256: f09112dba925d1dbc8ef05838d3147b445ffd638d886d7391cc672c1b510fc3e

Contents?: true

Size: 753 Bytes

Versions: 7

Compression:

Stored size: 753 Bytes

Contents

# frozen_string_literal: true

require_relative '../test_helper'

class MapCompactTest < Minitest::Test
  should "map_compact" do
    assert_equal [1, 9], [1, 2, nil, 3, 4].map_compact { |item| item**2 if (nil == item ? nil : item.odd?) }
  end

  should "map_compact to empty if nothing matches" do
    assert_equal [], {:a => 'aaa', :b => 'bbb'}.map_compact { |key, value| value if key == :c }
  end

  should "map_compact a hash" do
    assert_equal ['bbb'], {:a => 'aaa', :b => 'bbb'}.map_compact { |key, value| value if key == :b }
  end

  should "map_compact empty collection" do
    assert_equal [], [].map_compact { |item| true }
  end

  should "not map_compact false" do
    assert_equal [false], [nil, false].map_compact { |a| a }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
invoca-utils-0.4.1 test/unit/map_compact_test.rb
invoca-utils-0.4.0 test/unit/map_compact_test.rb
invoca-utils-0.3.0 test/unit/map_compact_test.rb
invoca-utils-0.2.0 test/unit/map_compact_test.rb
invoca-utils-0.2.0.pre.1 test/unit/map_compact_test.rb
invoca-utils-0.1.1 test/unit/map_compact_test.rb
invoca-utils-0.1.0 test/unit/map_compact_test.rb