int() bool() and str()
This commit is contained in:
@@ -411,12 +411,36 @@ func TestBuiltinFunctions(t *testing.T) {
|
||||
{`input()`, ""},
|
||||
{`pop([])`, errors.New("cannot pop from an empty array")},
|
||||
{`pop([1])`, 1},
|
||||
{`bool(1)`, true},
|
||||
{`bool(0)`, false},
|
||||
{`bool(true)`, true},
|
||||
{`bool(false)`, false},
|
||||
{`bool(null)`, false},
|
||||
{`bool("")`, false},
|
||||
{`bool("foo")`, true},
|
||||
{`bool([])`, false},
|
||||
{`bool([1, 2, 3])`, true},
|
||||
{`bool({})`, false},
|
||||
{`bool({"a": 1})`, true},
|
||||
{`int(true)`, 1},
|
||||
{`int(false)`, 0},
|
||||
{`int(1)`, 1},
|
||||
{`int("10")`, 10},
|
||||
{`str(null)`, "null"},
|
||||
{`str(true)`, "true"},
|
||||
{`str(false)`, "false"},
|
||||
{`str(10)`, "10"},
|
||||
{`str("foo")`, "foo"},
|
||||
{`str([1, 2, 3])`, "[1, 2, 3]"},
|
||||
{`str({"a": 1})`, "{\"a\": 1}"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
evaluated := testEval(tt.input)
|
||||
|
||||
switch expected := tt.expected.(type) {
|
||||
case bool:
|
||||
testBooleanObject(t, evaluated, expected)
|
||||
case int:
|
||||
testIntegerObject(t, evaluated, int64(expected))
|
||||
case string:
|
||||
|
||||
Reference in New Issue
Block a user