array literals
This commit is contained in:
@@ -61,6 +61,24 @@ func testExpectedObject(t *testing.T, expected interface{}, actual object.Object
|
||||
t.Errorf("testStringObject failed: %s", err)
|
||||
}
|
||||
|
||||
case []int:
|
||||
array, ok := actual.(*object.Array)
|
||||
if !ok {
|
||||
t.Errorf("object not Array: %T (%+v)", actual, actual)
|
||||
}
|
||||
|
||||
if len(array.Elements) != len(expected) {
|
||||
t.Errorf("wrong num of elements. want=%d, got=%d", len(expected), len(array.Elements))
|
||||
return
|
||||
}
|
||||
|
||||
for i, expectedElem := range expected {
|
||||
err := testIntegerObject(int64(expectedElem), array.Elements[i])
|
||||
if err != nil {
|
||||
t.Errorf("testIntgerObject failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
case *object.Null:
|
||||
if actual != Null {
|
||||
t.Errorf("object is not Null: %T (%+v)", actual, actual)
|
||||
@@ -204,3 +222,13 @@ func TestStringExpressions(t *testing.T) {
|
||||
|
||||
runVmTests(t, tests)
|
||||
}
|
||||
|
||||
func TestArrayLiterals(t *testing.T) {
|
||||
tests := []vmTestCase{
|
||||
{"[]", []int{}},
|
||||
{"[1, 2, 3]", []int{1, 2, 3}},
|
||||
{"[1 + 2, 3 * 4, 5 + 6]", []int{3, 12, 11}},
|
||||
}
|
||||
|
||||
runVmTests(t, tests)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user