This commit is contained in:
parent
58195738ba
commit
4ab94410b7
|
@ -283,7 +283,7 @@ func notBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return BoolObject(!args.args[0].Truthy()), nil
|
return BoolObject(!isTruthy(args.args[0])), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var errObjectsNotEqual = errors.New("objects not equal")
|
var errObjectsNotEqual = errors.New("objects not equal")
|
||||||
|
|
|
@ -1766,6 +1766,35 @@ func TestBuiltins_Cat(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuiltins_Not(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
desc string
|
||||||
|
expr string
|
||||||
|
want any
|
||||||
|
}{
|
||||||
|
{desc: "not 1", expr: `not 1`, want: false},
|
||||||
|
{desc: "not 2", expr: `not 0`, want: true},
|
||||||
|
{desc: "not 3", expr: `not ()`, want: true},
|
||||||
|
{desc: "not 4", expr: `not $true`, want: false},
|
||||||
|
{desc: "not 5", expr: `not $false`, want: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
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.EvalString(ctx, tt.expr)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, tt.want, eqRes)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuiltins_NotNil(t *testing.T) {
|
func TestBuiltins_NotNil(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
|
|
Loading…
Reference in a new issue