diff options
| author | Jun Hiroe <[email protected]> | 2014-03-28 20:24:00 +0900 |
|---|---|---|
| committer | Jun Hiroe <[email protected]> | 2014-03-28 20:28:14 +0900 |
| commit | de573e57a0070bffb3a7e1af3ba5fbc290404b7e (patch) | |
| tree | 03aac48e2eeb11138dd8a382e31bafd7ef8d974c /mrbgems/mruby-array-ext/test | |
| parent | 03fa45760e2da4c09acb725fdca20f4e8f7adb27 (diff) | |
| download | mruby-de573e57a0070bffb3a7e1af3ba5fbc290404b7e.tar.gz mruby-de573e57a0070bffb3a7e1af3ba5fbc290404b7e.zip | |
Add Array#fetch
Diffstat (limited to 'mrbgems/mruby-array-ext/test')
| -rw-r--r-- | mrbgems/mruby-array-ext/test/array.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb index 1c441cec4..ab830cca7 100644 --- a/mrbgems/mruby-array-ext/test/array.rb +++ b/mrbgems/mruby-array-ext/test/array.rb @@ -107,3 +107,14 @@ assert("Array#compact!") do a.compact! a == [1, "2", :t, false] end + +assert("Array#fetch") do + a = [ 11, 22, 33, 44 ] + assert_equal 22, a.fetch(1) + assert_equal 44, a.fetch(-1) + assert_equal 'cat', a.fetch(4, 'cat') + ret = 0 + a.fetch(100) { |i| ret = i } + assert_equal 100, ret + assert_raise(IndexError) { a.fetch(100) } +end |
