Fix VM memory allocation optimizations by reducing what we allocate on the heap
This commit is contained in:
@@ -25,25 +25,25 @@ func assertEvaluated(t *testing.T, expected interface{}, actual object.Object) {
|
||||
|
||||
switch expected.(type) {
|
||||
case nil:
|
||||
if _, ok := actual.(*object.Null); ok {
|
||||
if _, ok := actual.(object.Null); ok {
|
||||
assert.True(ok)
|
||||
} else {
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
case int:
|
||||
if i, ok := actual.(*object.Integer); ok {
|
||||
if i, ok := actual.(object.Integer); ok {
|
||||
assert.Equal(int64(expected.(int)), i.Value)
|
||||
} else {
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
case error:
|
||||
if e, ok := actual.(*object.Integer); ok {
|
||||
if e, ok := actual.(object.Integer); ok {
|
||||
assert.Equal(expected.(error).Error(), e.Value)
|
||||
} else {
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
case string:
|
||||
if s, ok := actual.(*object.String); ok {
|
||||
if s, ok := actual.(object.String); ok {
|
||||
assert.Equal(expected.(string), s.Value)
|
||||
} else {
|
||||
assert.Equal(expected, actual)
|
||||
@@ -161,7 +161,6 @@ func TestIfElseExpression(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Log(tt.input)
|
||||
evaluated := testEval(tt.input)
|
||||
integer, ok := tt.expected.(int)
|
||||
if ok {
|
||||
@@ -279,7 +278,7 @@ func TestErrorHandling(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
evaluated := testEval(tt.input)
|
||||
|
||||
errObj, ok := evaluated.(*object.Error)
|
||||
errObj, ok := evaluated.(object.Error)
|
||||
if !ok {
|
||||
t.Errorf("no error object returned. got=%T(%+v)",
|
||||
evaluated, evaluated)
|
||||
@@ -409,7 +408,7 @@ func TestStringLiteral(t *testing.T) {
|
||||
input := `"Hello World!"`
|
||||
|
||||
evaluated := testEval(input)
|
||||
str, ok := evaluated.(*object.String)
|
||||
str, ok := evaluated.(object.String)
|
||||
if !ok {
|
||||
t.Fatalf("object is not String. got=%T (+%v)", evaluated, evaluated)
|
||||
}
|
||||
@@ -423,7 +422,7 @@ func TestStringConcatenation(t *testing.T) {
|
||||
input := `"Hello" + " " + "World!"`
|
||||
|
||||
evaluated := testEval(input)
|
||||
str, ok := evaluated.(*object.String)
|
||||
str, ok := evaluated.(object.String)
|
||||
if !ok {
|
||||
t.Fatalf("object is not String. got=%T (+%v)", evaluated, evaluated)
|
||||
}
|
||||
@@ -495,7 +494,7 @@ func TestBuiltinFunctions(t *testing.T) {
|
||||
case string:
|
||||
testStringObject(t, evaluated, expected)
|
||||
case error:
|
||||
errObj, ok := evaluated.(*object.Error)
|
||||
errObj, ok := evaluated.(object.Error)
|
||||
if !ok {
|
||||
t.Errorf("object is not Error. got=%T (%+v)",
|
||||
evaluated, evaluated)
|
||||
@@ -641,12 +640,12 @@ func TestHashLiterals(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := map[object.HashKey]int64{
|
||||
(&object.String{Value: "one"}).HashKey(): 1,
|
||||
(&object.String{Value: "two"}).HashKey(): 2,
|
||||
(&object.String{Value: "three"}).HashKey(): 3,
|
||||
(&object.Integer{Value: 4}).HashKey(): 4,
|
||||
TRUE.HashKey(): 5,
|
||||
FALSE.HashKey(): 6,
|
||||
(object.String{Value: "one"}).HashKey(): 1,
|
||||
(object.String{Value: "two"}).HashKey(): 2,
|
||||
(object.String{Value: "three"}).HashKey(): 3,
|
||||
(object.Integer{Value: 4}).HashKey(): 4,
|
||||
TRUE.HashKey(): 5,
|
||||
FALSE.HashKey(): 6,
|
||||
}
|
||||
|
||||
if len(result.Pairs) != len(expected) {
|
||||
@@ -672,8 +671,8 @@ func TestHashMerging(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := map[object.HashKey]int64{
|
||||
(&object.String{Value: "a"}).HashKey(): 1,
|
||||
(&object.String{Value: "b"}).HashKey(): 2,
|
||||
(object.String{Value: "a"}).HashKey(): 1,
|
||||
(object.String{Value: "b"}).HashKey(): 2,
|
||||
}
|
||||
|
||||
if len(result.Pairs) != len(expected) {
|
||||
@@ -804,7 +803,7 @@ func testEval(input string) object.Object {
|
||||
}
|
||||
|
||||
func testIntegerObject(t *testing.T, obj object.Object, expected int64) bool {
|
||||
result, ok := obj.(*object.Integer)
|
||||
result, ok := obj.(object.Integer)
|
||||
if !ok {
|
||||
t.Errorf("object is not Integer. got=%T (%+v)", obj, obj)
|
||||
return false
|
||||
@@ -823,7 +822,7 @@ func TestNullExpression(t *testing.T) {
|
||||
}
|
||||
|
||||
func testBooleanObject(t *testing.T, obj object.Object, expected bool) bool {
|
||||
result, ok := obj.(*object.Boolean)
|
||||
result, ok := obj.(object.Boolean)
|
||||
if !ok {
|
||||
t.Errorf("object is not Boolean. got=%T (%+v)", obj, obj)
|
||||
return false
|
||||
@@ -845,7 +844,7 @@ func testNullObject(t *testing.T, obj object.Object) bool {
|
||||
}
|
||||
|
||||
func testStringObject(t *testing.T, obj object.Object, expected string) bool {
|
||||
result, ok := obj.(*object.String)
|
||||
result, ok := obj.(object.String)
|
||||
if !ok {
|
||||
t.Errorf("object is not String. got=%T (%+v)", obj, obj)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user