Feature #19618
openhash#dig tests
Description
diff --git a/spec/ruby/core/hash/hash_spec.rb b/spec/ruby/core/hash/hash_spec.rb
index 2ccb483120..3b583b338b 100644
--- a/spec/ruby/core/hash/hash_spec.rb
+++ b/spec/ruby/core/hash/hash_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require_relative "../../spec_helper"
describe "Hash" do
it "includes Enumerable" do
@@ -6,9 +6,18 @@
end
end
+describe "Hash#dig" do
- it "handles nested hash" do
- { foo: { bar: { baz: 2 } } }.dig(:foo).should == { :bar => { :baz => 2 } }
- { foo: { bar: { baz: 2 } } }.dig(:foo, :bar).should == { :baz => 2 }
- { foo: { bar: { baz: 2 } } }.dig(:foo, :bar, :baz).should == 2
- { foo: { bar: { baz: 2 } } }.dig(:BAZ).should.nil?
- end
+end
describe "Hash#hash" do
it "returns a value which doesn't depend on the hash order" do
- { 0=>2, 11=>1 }.hash.should == { 11=>1, 0=>2 }.hash
- { 0 => 2, 11 => 1 }.hash.should == { 11 => 1, 0 => 2 }.hash
end
it "returns a value in which element values do not cancel each other out" do
@@ -26,9 +35,9 @@
end
it "returns the same hash for recursive hashes" do
- h = {} ; h[:x] = h
- h.hash.should == {x: h}.hash
- h.hash.should == {x: {x: h}}.hash
- h = {}; h[:x] = h
- h.hash.should == { x: h }.hash
- h.hash.should == { x: { x: h } }.hash
This is because h.eql?(x: h)¶
Remember that if two objects are eql?¶
then the need to have the same hash.¶
@@ -36,9 +45,9 @@
end
it "returns the same hash for recursive hashes through arrays" do
- h = {} ; rec = [h] ; h[:x] = rec
- h.hash.should == {x: rec}.hash
- h.hash.should == {x: [h]}.hash
- h = {}; rec = [h]; h[:x] = rec
- h.hash.should == { x: rec }.hash
- h.hash.should == { x: [h] }.hash
Like above, because h.eql?(x: [h])¶
end
@@ -47,7 +56,7 @@
a = 1
b = 2
-
eval('{a:, b:}.should == { a: 1, b: 2 }')
-
endeval("{a:, b:}.should == { a: 1, b: 2 }")
end
end
adds tests for.Hash#dig¶
No data to display