From de573e57a0070bffb3a7e1af3ba5fbc290404b7e Mon Sep 17 00:00:00 2001 From: Jun Hiroe Date: Fri, 28 Mar 2014 20:24:00 +0900 Subject: Add Array#fetch --- mrbgems/mruby-array-ext/test/array.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mrbgems/mruby-array-ext/test') 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 -- cgit v1.2.3