issue-1: added tests for cat
All checks were successful
Test / build (push) Successful in 42s

This commit is contained in:
Leon Mika 2024-09-07 09:30:22 +10:00
parent 08c645a70f
commit 1b4b1a339c

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)
})
}
}