mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
this allows selects where the condiotion is a boolean and you can choose the true or false branch.
49 lines
796 B
Plaintext
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";
|
|
|; |