Sha256: a47d0c07a1eacf0748c925e891654ecafaef1b5539ce67ed2a2d782a7449ba38

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

require 'helper'

test_case Hash do

  method :rekey do

    test "default" do
      foo = { "a"=>1, "b"=>2 }
      foo.rekey.assert == { :a=>1, :b=>2 }
      foo.assert == { "a"=>1, "b"=>2 }
    end

    test "specific key" do
      bar = { :a=>1, :b=>2 }
      foo = bar.rekey(:a=>:c)
      foo[:c].assert == 1
      foo[:b].assert == 2
      foo[:a].assert == nil
    end

    test "with block" do
      bar = { :a=>1, :b=>2 }
      foo = bar.rekey{ |k| k.to_s }
      foo['a'].assert == 1
      foo['b'].assert == 2
      foo[:a].assert  == nil
      foo[:b].assert  == nil
      foo.assert == { 'a'=>1, 'b'=>2 }
    end

    test "symbol proc" do
      foo = { :a=>1, :b=>2 }
      foo.rekey(&:to_s).assert == { "a"=>1, "b"=>2 }
      foo.assert == { :a =>1, :b=>2 }
    end

  end

  method :rekey! do

    test "default" do
      foo = { "a"=>1, "b"=>2 }
      foo.rekey!.assert == { :a=>1, :b=>2 }
      foo.assert == { :a=>1, :b=>2 }
    end

    test "specific key" do
      foo = { :a=>1, :b=>2 }
      foo.rekey!(:a=>:c)
      foo[:c].assert == 1
      foo[:b].assert == 2
      foo[:a].assert == nil
    end

    test "with block" do
      foo = { :a=>1, :b=>2 }
      foo.rekey!{ |k| k.to_s }
      foo['a'].assert == 1
      foo['b'].assert == 2
      foo[:a].assert == nil
      foo[:b].assert == nil
      foo.assert == { 'a'=>1, 'b'=>2 }
    end

    test "symbol proc" do
      foo = { :a=>1, :b=>2 }
      foo.rekey!(&:to_s).assert == { "a"=>1, "b"=>2 }
      foo.assert == { "a"=>1, "b"=>2 }
    end

    test "no conflict between keys" do
      r = {1 => :a, 2 => :b}.rekey!{ |k| k + 1 }
      r.refute = {3 => :a}
      r.assert = {2 => :a, 3 => :b}  
    end

  end

end

Version data entries

6 entries across 5 versions & 2 rubygems

Version Path
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.4.0/gems/hashery-2.1.2/test/case_core_ext.rb
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.5.0/gems/hashery-2.1.2/test/case_core_ext.rb
hashery-2.1.2 test/case_core_ext.rb
hashery-2.1.1 test/case_core_ext.rb
hashery-2.1.0 test/case_core_ext.rb
hashery-2.0.1 test/case_core_ext.rb