forked from mitchellh/go-mruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_test.go
43 lines (36 loc) · 682 Bytes
/
array_test.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
package mruby
import (
"testing"
)
func TestArray(t *testing.T) {
mrb := NewMrb()
defer mrb.Close()
value, err := mrb.LoadString(`["foo", "bar", "baz", false]`)
if err != nil {
t.Fatalf("err: %s", err)
}
v := value.Array()
// Len
if n := v.Len(); n != 4 {
t.Fatalf("bad: %d", n)
}
// Get
value, err = v.Get(1)
if err != nil {
t.Fatalf("err: %s", err)
}
if value.String() != "bar" {
t.Fatalf("bad: %s", value)
}
// Get bool
value, err = v.Get(3)
if err != nil {
t.Fatalf("err: %s", err)
}
if valType := value.Type(); valType != TypeFalse {
t.Fatalf("bad type: %v", valType)
}
if value.String() != "false" {
t.Fatalf("bad: %s", value)
}
}