diff options
Diffstat (limited to 'evaluator/evaluator_test.go')
| -rw-r--r-- | evaluator/evaluator_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index 9738d9e..22fd80a 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -345,3 +345,35 @@ func TestStringConcatenation(t *testing.T) { t.Errorf("String has wrong value. got=%q", str.Value) } } + +func TestBuiltinFunctions(t *testing.T) { + tests := []struct { + input string + expected interface{} + }{ + {`len("")`, 0}, + {`len("four")`, 4}, + {`len("hello world")`, 11}, + {`len(1)`, "argument to `len` not supported, got INTEGER"}, + {`len("one", "two")`, "wrong number of arguments. got=2, want=1"}, + } + + for _, tt := range tests { + evaluated := testEval(tt.input) + + switch expected := tt.expected.(type) { + case int: + testIntegerObject(t, evaluated, int64(expected)) + case string: + errObj, ok := evaluated.(*object.Error) + if !ok { + t.Errorf("object is not Error. got=%T (%+v)", evaluated, evaluated) + continue + } + + if errObj.Message != expected { + t.Errorf("wrong error message. expected=%q, got=%q", expected, errObj.Message) + } + } + } +} |
