2017-12-17 11:41:25 +08:00
|
|
|
package eval
|
|
|
|
|
2017-12-22 04:32:14 +08:00
|
|
|
var builtinFnTests = []Test{
|
2017-12-17 13:44:48 +08:00
|
|
|
{"nop", wantNothing},
|
|
|
|
{"nop a b", wantNothing},
|
|
|
|
{"nop &k=v", wantNothing},
|
|
|
|
{"nop a b &k=v", wantNothing},
|
2017-12-17 11:41:25 +08:00
|
|
|
|
|
|
|
{"kind-of bare 'str' [] [&] []{ }",
|
|
|
|
want{out: strs("string", "string", "list", "map", "fn")}},
|
|
|
|
|
2017-12-17 13:42:30 +08:00
|
|
|
{`bool $true`, wantTrue},
|
|
|
|
{`bool a`, wantTrue},
|
|
|
|
{`bool [a]`, wantTrue},
|
|
|
|
// "Empty" values are also true in Elvish
|
|
|
|
{`bool []`, wantTrue},
|
|
|
|
{`bool [&]`, wantTrue},
|
|
|
|
{`bool 0`, wantTrue},
|
|
|
|
{`bool ""`, wantTrue},
|
|
|
|
// Only errors and $false are false
|
|
|
|
{`bool ?(fail x)`, wantFalse},
|
|
|
|
{`bool $false`, wantFalse},
|
|
|
|
|
|
|
|
{`not $false`, wantTrue},
|
2017-12-19 04:28:33 +08:00
|
|
|
{`not ?(fail x)`, wantTrue},
|
2017-12-17 13:42:30 +08:00
|
|
|
{`not $true`, wantFalse},
|
2017-12-19 04:28:33 +08:00
|
|
|
{`not 0`, wantFalse},
|
2017-12-17 13:42:30 +08:00
|
|
|
|
2017-12-17 13:43:57 +08:00
|
|
|
{`is 1 1`, wantTrue},
|
2017-12-19 04:28:33 +08:00
|
|
|
{`is a b`, wantFalse},
|
2017-12-17 13:43:57 +08:00
|
|
|
{`is [] []`, wantTrue},
|
|
|
|
{`is [1] [1]`, wantFalse},
|
|
|
|
{`eq 1 1`, wantTrue},
|
2017-12-19 04:28:33 +08:00
|
|
|
{`eq a b`, wantFalse},
|
2017-12-17 13:43:57 +08:00
|
|
|
{`eq [] []`, wantTrue},
|
2017-12-19 04:28:33 +08:00
|
|
|
{`eq [1] [1]`, wantTrue},
|
|
|
|
{`not-eq a b`, wantTrue},
|
2017-12-17 13:43:57 +08:00
|
|
|
|
2017-12-17 13:20:03 +08:00
|
|
|
{`f=(constantly foo); $f; $f`, want{out: strs("foo", "foo")}},
|
|
|
|
{`(constantly foo) bad`, want{err: errAny}},
|
2017-12-17 11:41:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
addToEvalTests(builtinFnTests)
|
|
|
|
}
|