int() bool() and str()
Some checks failed
Build / build (push) Successful in 9m45s
Test / build (push) Failing after 16m25s

This commit is contained in:
Chuck Smith
2024-03-21 15:19:48 -04:00
parent 43362475f9
commit d3471af03d
7 changed files with 138 additions and 3 deletions

View File

@@ -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: