Sha256: 021d3d8475f3842aa96444867d679546cebc4a21c8ec97df07e9642eb78a7f82
Contents?: true
Size: 1.08 KB
Versions: 58
Compression:
Stored size: 1.08 KB
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 def test_subhash_with_default_proc h = Hash.new { |h, k| h[k] = :foo } h.update('foo' => 1, 'bar' => 2) s = h.subhash('foo') assert_equal 1, s['foo'] assert_equal :foo, s['bar'] end end end
Version data entries
58 entries across 55 versions & 8 rubygems