feature/issue-1: built out the core libraries #3

Merged
lmika merged 8 commits from feature/issue-1 into main 2024-09-06 23:38:05 +00:00
1 changed files with 32 additions and 0 deletions
Showing only changes of commit 1b4b1a339c - Show all commits

View File

@ -1198,3 +1198,35 @@ func TestBuiltins_AndOrNot(t *testing.T) {
})
}
}
func TestBuiltins_Cat(t *testing.T) {
tests := []struct {
desc string
expr string
want any
}{
{desc: "cat 1", expr: `cat "hello, " "world"`, want: "hello, world"},
{desc: "cat 2", expr: `cat "hello, " "world " "and stuff"`, want: "hello, world and stuff"},
{desc: "cat 3", expr: `cat "int = " 123`, want: "int = 123"},
{desc: "cat 4", expr: `cat "bool = " $true`, want: "bool = true"},
{desc: "cat 5", expr: `cat "array = " []`, want: "array = []"},
{desc: "cat 6", expr: `cat "array = " [1 3 2 4]`, want: "array = [1 3 2 4]"},
{desc: "cat 7", expr: `cat 1 $true 3 [4]`, want: "1true3[4]"},
{desc: "cat 8", expr: `cat`, want: ""},
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx := context.Background()
outW := bytes.NewBuffer(nil)
inst := New(WithOut(outW), WithTestBuiltin())
inst.SetVar("true", true)
inst.SetVar("false", false)
eqRes, err := inst.Eval(ctx, tt.expr)
assert.NoError(t, err)
assert.Equal(t, tt.want, eqRes)
})
}
}