ucg/integration_tests/select_expressions_test.ucg
Jeremy Wall fe4bb1c9d7 FEATURE: allow tuples to have true or false as field names.
this allows selects where the condiotion is a boolean and you can choose
the true or false branch.
2018-11-26 23:08:14 -06:00

49 lines
796 B
Plaintext

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",
};
assert |
got == "grand prize";
|;
assert |
defaultgot == "OOPS";
|;
// select inside a macro
let condmacro = macro(arg) => {
output = select arg, NULL, {
opt1 = "yay",
opt2 = "boo",
},
};
let result = condmacro("opt1");
assert |
condmacro("opt1") == {output = "yay"};
|;
assert |
condmacro("opt2") == {output = "boo"};
|;
assert |
condmacro("invalid") == {output = NULL};
|;
let iflike = select true, "default", {
true = "I was true",
false = "I was false",
};
assert |
iflike == "I was true";
|;