type checking and error handling for builtins improved.
This commit is contained in:
@@ -398,24 +398,24 @@ func TestBuiltinFunctions(t *testing.T) {
|
||||
{`len("")`, 0},
|
||||
{`len("four")`, 4},
|
||||
{`len("hello world")`, 11},
|
||||
{`len(1)`, errors.New("argument to `len` not supported, got int")},
|
||||
{`len("one", "two")`, errors.New("wrong number of arguments. got=2, want=1")},
|
||||
{`len(1)`, errors.New("TypeError: object of type 'int' has no len()")},
|
||||
{`len("one", "two")`, errors.New("TypeError: len() takes exactly 1 argument (2 given)")},
|
||||
{`len("∑")`, 1},
|
||||
{`len([1, 2, 3])`, 3},
|
||||
{`len([])`, 0},
|
||||
{`first([1, 2, 3])`, 1},
|
||||
{`first([])`, nil},
|
||||
{`first(1)`, errors.New("argument to `first` must be array, got int")},
|
||||
{`first(1)`, errors.New("TypeError: first() expected argument #1 to be `array` got `int`")},
|
||||
{`last([1, 2, 3])`, 3},
|
||||
{`last([])`, nil},
|
||||
{`last(1)`, errors.New("argument to `last` must be array, got int")},
|
||||
{`last(1)`, errors.New("TypeError: last() expected argument #1 to be `array` got `int`")},
|
||||
{`rest([1, 2, 3])`, []int{2, 3}},
|
||||
{`rest([])`, nil},
|
||||
{`push([], 1)`, []int{1}},
|
||||
{`push(1, 1)`, errors.New("argument to `push` must be array, got int")},
|
||||
{`push(1, 1)`, errors.New("TypeError: push() expected argument #1 to be `array` got `int`")},
|
||||
{`print("Hello World")`, nil},
|
||||
{`input()`, ""},
|
||||
{`pop([])`, errors.New("cannot pop from an empty array")},
|
||||
{`pop([])`, errors.New("IndexError: pop from an empty array")},
|
||||
{`pop([1])`, 1},
|
||||
{`bool(1)`, true},
|
||||
{`bool(0)`, false},
|
||||
|
||||
Reference in New Issue
Block a user