elvish/pkg/eval/builtin_fn_pred_test.go
2020-10-10 22:47:50 +01:00

45 lines
1.1 KiB
Go

package eval_test
import (
"testing"
. "github.com/elves/elvish/pkg/eval/evaltest"
)
func TestBool(t *testing.T) {
Test(t,
That(`bool $true`).Puts(true),
That(`bool a`).Puts(true),
That(`bool [a]`).Puts(true),
// "Empty" values are also true in Elvish
That(`bool []`).Puts(true),
That(`bool [&]`).Puts(true),
That(`bool 0`).Puts(true),
That(`bool ""`).Puts(true),
// Only errors and $false are false
That(`bool ?(fail x)`).Puts(false),
That(`bool $false`).Puts(false),
That(`not $false`).Puts(true),
That(`not ?(fail x)`).Puts(true),
That(`not $true`).Puts(false),
That(`not 0`).Puts(false),
That(`is 1 1`).Puts(true),
That(`is a b`).Puts(false),
That(`is [] []`).Puts(true),
That(`is [1] [1]`).Puts(false),
That(`eq 1 1`).Puts(true),
That(`eq a b`).Puts(false),
That(`eq [] []`).Puts(true),
That(`eq [1] [1]`).Puts(true),
That(`eq 1 1 2`).Puts(false),
That(`not-eq a b`).Puts(true),
That(`not-eq a a`).Puts(false),
// not-eq is true as long as each adjacent pair is not equal.
That(`not-eq 1 2 1`).Puts(true),
)
}