Sha256: ad82671bac4d1b60ebaab3dfef5c2e42e088d98e05e7e3ea8be9df955380532d

Contents?: true

Size: 902 Bytes

Versions: 83

Compression:

Stored size: 902 Bytes

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'

describe "Hash#invert" do
  it "returns a new hash where keys are values and vice versa" do
    new_hash(1 => 'a', 2 => 'b', 3 => 'c').invert.should ==
      new_hash('a' => 1, 'b' => 2, 'c' => 3)
  end

  it "handles collisions by overriding with the key coming later in keys()" do
    h = new_hash(:a => 1, :b => 1)
    override_key = h.keys.last
    h.invert[1].should == override_key
  end

  it "compares new keys with eql? semantics" do
    h = new_hash(:a => 1.0, :b => 1)
    i = h.invert
    i[1.0].should == :a
    i[1].should == :b
  end

  it "does not return subclass instances for subclasses" do
    MyHash[1 => 2, 3 => 4].invert.class.should == hash_class
    MyHash[].invert.class.should == hash_class
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/hash/invert_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/hash/invert_spec.rb