Sha256: 541f38ea0845aa351ee417dbeede97d5a5006f8d8f424eda163aa076f6dca7df

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

shared_examples_for :hash_store do |method|
  before { @method = method }

  it "associates the key with the value and return the value" do
    h = new_hash(:a => 1)
    h.send(@method, :b, 2).should == 2
    h.should == new_hash(:b=>2, :a=>1)
  end

  it "duplicates string keys using dup semantics" do
    # dup doesn't copy singleton methods
    key = "foo"
    def key.reverse() "bar" end
    h = new_hash
    h.send(@method, key, 0)
    h.keys[0].reverse.should == "oof"
  end

  it "stores unequal keys that hash to the same value" do
    h = new_hash
    k1 = ["x"]
    k2 = ["y"]
    # So they end up in the same bucket
    k1.should_receive(:hash).and_return(0)
    k2.should_receive(:hash).and_return(0)

    h[k1] = 1
    h[k2] = 2
    h.size.should == 2
  end

=begin frozen
  it "duplicates and freezes string keys" do
    key = "foo"
    h = new_hash
    h.send(@method, key, 0)
    key << "bar"

    h.should == new_hash("foo" => 0)
    h.keys[0].frozen?.should == true
  end

  it "doesn't duplicate and freeze already frozen string keys" do
    key = "foo".freeze
    h = new_hash
    h.send(@method, key, 0)
    h.keys[0].should equal(key)
  end

  ruby_version_is ""..."1.9" do
    it "raises a TypeError if called on a frozen instance" do
      lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(TypeError)
    end
  end

  ruby_version_is "1.9" do
    it "raises a RuntimeError if called on a frozen instance" do
      lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(RuntimeError)
    end
  end
=end

  it "does not raise an exception if changing the value of an existing key during iteration" do
      hash = {1 => 2, 3 => 4, 5 => 6}
      hash.each { hash.send(@method, 1, :foo) }
      hash.should == {1 => :foo, 3 => 4, 5 => 6}
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jactive_support-2.1.2 spec/java_ext/map/shared/store.rb
jactive_support-3.0.0 spec/java_ext/map/shared/store.rb
jactive_support-3.0.0.pre2 spec/java_ext/map/shared/store.rb
jactive_support-3.0.0.pre1 spec/java_ext/map/shared/store.rb
jactive_support-2.1.1 spec/java_ext/map/shared/store.rb
jactive_support-2.1.0 spec/java_ext/map/shared/store.rb
jactive_support-2.0.0 spec/java_ext/map/shared/store.rb
jactive_support-1.0.2 spec/java_ext/map/shared/store.rb
jactive_support-1.0.1-universal-java-1.6 spec/java_ext/map/shared/store.rb
jactive_support-1.0.0-universal-java-1.6 spec/java_ext/map/shared/store.rb