diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-03-23 12:34:32 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-03-23 12:34:32 +0900 |
| commit | 817b884343cc349d3c32da7f1c65cb4867963bde (patch) | |
| tree | 49ffcd28618ed32c94c393dfa9367daae02a6249 | |
| parent | daf83946bbf2834da8393cd50af2bc7bcee3289f (diff) | |
| download | mruby-817b884343cc349d3c32da7f1c65cb4867963bde.tar.gz mruby-817b884343cc349d3c32da7f1c65cb4867963bde.zip | |
add #dig tests
| -rw-r--r-- | mrbgems/mruby-array-ext/test/array.rb | 7 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/test/hash.rb | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/test/struct.rb | 7 |
3 files changed, 20 insertions, 0 deletions
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb index f17cb80e1..ec1528fc3 100644 --- a/mrbgems/mruby-array-ext/test/array.rb +++ b/mrbgems/mruby-array-ext/test/array.rb @@ -310,3 +310,10 @@ assert("Array#to_ary") do 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 diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index 8b6b2e5b9..b43541b7f 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -236,3 +236,9 @@ assert('Hash#>') do 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 diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb index 605f23e20..63a02817e 100644 --- a/mrbgems/mruby-struct/test/struct.rb +++ b/mrbgems/mruby-struct/test/struct.rb @@ -148,3 +148,10 @@ assert('Struct#values_at') do 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 |
