summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-array-ext/test/array.rb
blob: 36da6bb176c1b9f493e9fc392b6de9fcd931e727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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