Sha256: 03714f7ad8f6223da85cac8dfee2796325dfcdb0bd5e323bcc076b99f4de0ef2

Contents?: true

Size: 962 Bytes

Versions: 23

Compression:

Stored size: 962 Bytes

Contents

describe "Hash literal" do
  it "{} should return an empty hash" do
    {}.size.should == 0
    {}.should == {}
  end

  it "{} should return a new hash populated with the given elements" do
    h = {:a => 'a', 'b' => 3, 44 => 2.3}
    h.size.should == 3
    h.should == {:a => 'a', 'b' => 3, 44 => 2.3}
  end

  it "treats empty expressions an nils" do
    h = {() => ()}
    h.keys.should == [nil]
    h.values.should == [nil]
    h[nil].should == nil

    h = {() => :value}
    h.keys.should == [nil]
    h.values.should == [:value]
    h[nil].should == :value

    h = {:keys => ()}
    h.keys.should == [:keys]
    h.values.should == [nil]
    h[:key].should == nil
  end

  it "checks duplicated keys on initialization" do
    h = {:foo => :bar, :foo => :foo}
    h.keys.size.should == 1
    h.should == {:foo => :foo}
  end

  it "accepts a hanging comma" do
    h = {:a => 1, :b => 2,}
    h.size.should == 2
    h.should == {:a => 1, :b => 2}
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
opal-0.3.41 spec/language/hash_spec.rb
opal-0.3.40 spec/language/hash_spec.rb
opal-0.3.39 spec/language/hash_spec.rb
opal-0.3.38 spec/language/hash_spec.rb
opal-0.3.37 spec/language/hash_spec.rb
opal-0.3.36 spec/language/hash_spec.rb
opal-0.3.35 spec/language/hash_spec.rb
opal-0.3.34 spec/language/hash_spec.rb
opal-0.3.33 spec/language/hash_spec.rb
opal-0.3.32 spec/language/hash_spec.rb
opal-0.3.31 spec/language/hash_spec.rb
opal-0.3.30 spec/language/hash_spec.rb
opal-0.3.29 spec/language/hash_spec.rb
opal-0.3.28 spec/language/hash_spec.rb
opal-0.3.27 spec/language/hash_spec.rb
opal-0.3.26 spec/language/hash_spec.rb
opal-0.3.25 spec/language/hash_spec.rb
opal-0.3.22 spec/language/hash_spec.rb
opal-0.3.21 test/language/hash_spec.rb
opal-0.3.20 test/language/hash_spec.rb