utf8 support

This commit is contained in:
Chuck Smith
2024-01-22 20:49:06 -05:00
parent 94f7c01396
commit ed4d23de2d
2 changed files with 50 additions and 29 deletions

View File

@@ -330,7 +330,7 @@ func TestStringConcatenation(t *testing.T) {
}
}
func TestBuiltinFunction(t *testing.T) {
func TestBuiltinFunctions(t *testing.T) {
tests := []struct {
input string
expected interface{}
@@ -340,6 +340,20 @@ func TestBuiltinFunction(t *testing.T) {
{`len("hello world")`, 11},
{`len(1)`, "argument to `len` not supported, got INTEGER"},
{`len("one", "two")`, "wrong number of arguments. got=2, want=1"},
{`len("∑")`, 1},
{`len([1, 2, 3])`, 3},
{`len([])`, 0},
{`first([1, 2, 3])`, 1},
{`first([])`, nil},
{`first(1)`, "argument to `first` must be ARRAY, got INTEGER"},
{`last([1, 2, 3])`, 3},
{`last([])`, nil},
{`last(1)`, "argument to `last` must be ARRAY, got INTEGER"},
{`rest([1, 2, 3])`, []int{2, 3}},
{`rest([])`, nil},
{`push([], 1)`, []int{1}},
{`push(1, 1)`, "argument to `push` must be ARRAY, got INTEGER"},
{`puts("Hello World")`, nil},
}
for _, tt := range tests {
@@ -351,11 +365,13 @@ func TestBuiltinFunction(t *testing.T) {
case string:
errObj, ok := evaluated.(*object.Error)
if !ok {
t.Errorf("object is not Error. got=%T (%+v)", evaluated, evaluated)
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)
t.Errorf("wrong error message. expected=%q, got=%q",
expected, errObj.Message)
}
}
}