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:
@@ -1,10 +1,21 @@
|
||||
|
||||
//test basic truth ternaries
|
||||
{
|
||||
var t = astype [int];
|
||||
var arr: t = [1, 2, 3.14];
|
||||
assert true ? true : false, "Basic true ternary failed";
|
||||
assert false ? false : true, "Basic false ternary failed";
|
||||
}
|
||||
|
||||
|
||||
//test nesting
|
||||
{
|
||||
var t = astype [string:int];
|
||||
var dict: t = ["one": 1, "two": 2, "pi": 3.14];
|
||||
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";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user