2018-08-20 23:05:34 -05:00
|
|
|
let goodwant = "door1";
|
|
|
|
let badwant = "door4";
|
|
|
|
|
|
|
|
let got = select goodwant, "OOPS", {
|
|
|
|
door1 = "grand prize",
|
|
|
|
door2 = "you lose",
|
|
|
|
};
|
|
|
|
|
|
|
|
let defaultgot = select badwant, "OOPS", {
|
|
|
|
door1 = "grand prize",
|
|
|
|
door2 = "you lose",
|
|
|
|
};
|
|
|
|
|
2019-01-08 20:32:16 -06:00
|
|
|
assert {
|
|
|
|
ok = got == "grand prize",
|
|
|
|
desc = "got == \"grand prize\"",
|
|
|
|
};
|
|
|
|
assert {
|
|
|
|
ok = defaultgot == "OOPS",
|
|
|
|
desc = "defaultgot == \"OOPS\"",
|
|
|
|
};
|
2018-08-20 23:05:34 -05:00
|
|
|
|
2019-01-24 20:04:40 -06:00
|
|
|
// select inside a function
|
2018-08-20 23:05:34 -05:00
|
|
|
|
2019-01-24 20:04:40 -06:00
|
|
|
let condfunc = func (arg) => {
|
2018-08-20 23:05:34 -05:00
|
|
|
output = select arg, NULL, {
|
|
|
|
opt1 = "yay",
|
|
|
|
opt2 = "boo",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-01-24 20:04:40 -06:00
|
|
|
let result = condfunc("opt1");
|
2018-08-20 23:05:34 -05:00
|
|
|
|
2019-01-08 20:32:16 -06:00
|
|
|
assert {
|
2019-01-24 20:04:40 -06:00
|
|
|
ok = condfunc("opt1") == {output = "yay"},
|
|
|
|
desc = "condfunc(\"opt1\") == {output = \"yay\"}",
|
2019-01-08 20:32:16 -06:00
|
|
|
};
|
|
|
|
assert {
|
2019-01-24 20:04:40 -06:00
|
|
|
ok = condfunc("opt2") == {output = "boo"},
|
|
|
|
desc = "condfunc(\"opt2\") == {output = \"boo\"}",
|
2019-01-08 20:32:16 -06:00
|
|
|
};
|
|
|
|
assert {
|
2019-01-24 20:04:40 -06:00
|
|
|
ok = condfunc("invalid") == {output = NULL},
|
|
|
|
desc = "condfunc(\"invalid\") == {output = NULL}",
|
2019-01-08 20:32:16 -06:00
|
|
|
};
|
2018-11-26 23:03:11 -06:00
|
|
|
|
|
|
|
let iflike = select true, "default", {
|
|
|
|
true = "I was true",
|
|
|
|
false = "I was false",
|
|
|
|
};
|
|
|
|
|
2019-01-08 20:32:16 -06:00
|
|
|
assert {
|
|
|
|
ok = iflike == "I was true",
|
|
|
|
desc = "iflike == \"I was true\"",
|
|
|
|
};
|