From 6c284ec31f470681e333bac431d3a074fc1d27fd Mon Sep 17 00:00:00 2001 From: skandhas Date: Fri, 15 Mar 2013 11:28:01 +0800 Subject: add mrbgem: mrb-array-ext --- mrbgems/mruby-array-ext/test/array.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 mrbgems/mruby-array-ext/test/array.rb (limited to 'mrbgems/mruby-array-ext/test/array.rb') diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb new file mode 100644 index 000000000..905606c9d --- /dev/null +++ b/mrbgems/mruby-array-ext/test/array.rb @@ -0,0 +1,30 @@ +## +# Array(Ext) Test + +assert("Array::try_convert") do + Array.try_convert([1]) == [1] and + Array.try_convert("1").nil? +end + +assert("Array#assoc") do + s1 = [ "colors", "red", "blue", "green" ] + s2 = [ "letters", "a", "b", "c" ] + s3 = "foo" + a = [ s1, s2, s3 ] + + a.assoc("letters") == [ "letters", "a", "b", "c" ] and + a.assoc("foo").nil? +end + +assert("Array#at") do + a = [ "a", "b", "c", "d", "e" ] + a.at(0) == "a" and a.at(-1) == "e" +end + +assert("Array::rassoc") do + a = [ [ 1, "one"], [2, "two"], [3, "three"], ["ii", "two"] ] + + a.rassoc("two") == [2, "two"] and + a.rassoc("four").nil? +end + -- cgit v1.2.3