Sha256: c945d4b1a88446d9f05c9934e56cdd9289805b9aacd4c556a50a8f1eab3d431d

Contents?: true

Size: 890 Bytes

Versions: 33

Compression:

Stored size: 890 Bytes

Contents

require 'test_helper'
require 'tins'

module Tins
  class SubhashTest < Test::Unit::TestCase
    require 'tins/xt/subhash'

    def test_subhash
      h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 }
      assert_equal [ [ 'bar666', 666 ] ], h.subhash(/\Abar/).to_a
      assert h.subhash(/\Abaz/).empty?
      assert_equal [ [ 'foo1', 1 ], [ 'foo2', 2 ] ], h.subhash(/\Afoo\d/).sort
      assert_equal [ [ 'foo2', 2 ] ], h.subhash('foo2').to_a
    end

    def test_subhash_bang
      h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 }
      h.subhash!('foo2')
      assert_equal [ [ 'foo2', 2 ] ], h.to_a
    end

    def test_subhash_with_block
      h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 }
      assert h.subhash(/\Abaz/) { :foo }.empty?
      assert_equal [ [ 'foo1', 1 ], [ 'foo2', 2 ] ],
        h.subhash(/\Afoo(\d)/) { |_,_,m| Integer(m[1]) }.to_a.sort
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/tins-0.13.1/tests/subhash_test.rb
tins-0.13.1 tests/subhash_test.rb
tins-0.13.0 tests/subhash_test.rb
tins-0.12.0 tests/subhash_test.rb
tins-0.11.0 tests/subhash_test.rb
tins-0.10.0 tests/subhash_test.rb
tins-0.9.0 tests/subhash_test.rb
tins-0.8.4 tests/subhash_test.rb
tins-0.8.3 tests/subhash_test.rb
tins-0.8.2 tests/subhash_test.rb
tins-0.8.0 tests/subhash_test.rb
tins-0.7.4 tests/subhash_test.rb
tins-0.7.3 tests/subhash_test.rb
tins-0.7.2 tests/subhash_test.rb
tins-0.7.1 tests/subhash_test.rb
tins-0.7.0 tests/subhash_test.rb
tins-0.6.0 tests/subhash_test.rb
tins-0.5.6 tests/subhash_test.rb
tins-0.5.5 tests/subhash_test.rb
tins-0.5.4 tests/subhash_test.rb