Permalink
Browse files

add #dig tests

  • Loading branch information...
matz committed Mar 23, 2016
1 parent daf8394 commit 817b884343cc349d3c32da7f1c65cb4867963bde
@@ -310,3 +310,10 @@
assert_equal [], [].to_ary
assert_equal [1,2,3], [1,2,3].to_ary
end
assert("Array#dig") do
h = [[[1]], 0]
assert_equal(1, h.dig(0, 0, 0))
assert_nil(h.dig(2, 0))
assert_raise(TypeError) {h.dig(:a)}
end
@@ -236,3 +236,9 @@
assert_false(h2 > h1)
assert_false(h2 > h2)
end
assert("Hash#dig") do
h = {a:{b:{c:1}}}
assert_equal(1, h.dig(:a, :b, :c))
assert_nil(h.dig(:d))
end
@@ -148,3 +148,10 @@
assert_equal ['io', 'aki'], a.values_at(1, 0)
assert_raise(IndexError) { a.values_at 2 }
end
assert("Struct#dig") do
a = Struct.new(:blue, :purple).new('aki', Struct.new(:red).new(1))
assert_equal 'aki', a.dig(:blue)
assert_equal 1, a.dig(:purple, :red)
assert_equal 1, a.dig(1, 0)
end

0 comments on commit 817b884

Please sign in to comment.