mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added ternary operator, resolved #46
This commit is contained in:
21
test/scripts/ternary-expressions.toy
Normal file
21
test/scripts/ternary-expressions.toy
Normal file
@@ -0,0 +1,21 @@
|
||||
//test basic truth ternaries
|
||||
{
|
||||
assert true ? true : false, "Basic true ternary failed";
|
||||
assert false ? false : true, "Basic false ternary failed";
|
||||
}
|
||||
|
||||
|
||||
//test nesting
|
||||
{
|
||||
fn least(a, b, c) {
|
||||
return a < b ? a : b < c ? b : c;
|
||||
}
|
||||
|
||||
assert least(1, 2, 3) == 1, "Least 1, 2, 3 failed";
|
||||
assert least(10, 5, 7) == 5, "Least 10, 5, 7 failed";
|
||||
assert least(9, 7, 5) == 5, "Least 9, 7, 5 failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
|
||||
@@ -196,7 +196,8 @@ int main() {
|
||||
"long-dictionary.toy",
|
||||
"long-literals.toy",
|
||||
"native-functions.toy",
|
||||
"panic-within-functions.toy",
|
||||
"panic-within-functions.toy",
|
||||
"ternary-expressions.toy",
|
||||
"types.toy",
|
||||
NULL
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user