Skip to content

Commit

Permalink
add #dig tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Mar 23, 2016
1 parent daf8394 commit 817b884
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mrbgems/mruby-array-ext/test/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions mrbgems/mruby-hash-ext/test/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions mrbgems/mruby-struct/test/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.