polserver/testsuite/escript/condexpr/condexpr01.src
Kevin Eady 0ca7912fcd
Add support for conditional operator (#387)
* Grammar update

* AST generation

* Emit instructions

* Add initial tests

* Additional tests

* Rename to ConditionalOperator

* Add docs
2021-03-14 23:20:20 +01:00

29 lines
586 B
Text

function Call(byref val)
return ++val;
endfunction
function DoNotCall()
print("TEST FAILURE");
return error{ errortext := "Called!" };
endfunction
var foo, i := 0;
foo := 1 ? Call(i) : DoNotCall();
print(foo);
foo := 0 ? DoNotCall() : Call(i);
print(foo);
foo := -1 > 0 ? DoNotCall() : Call(i);
print(foo);
foo := -1 > 0 ? DoNotCall() : 0 > 1 ? DoNotCall() : Call(i);
print(foo);
foo := 0 ?: "" ? DoNotCall() : Unpack("u") ?: 0 ? DoNotCall() : Call(i);
print(foo);
var bar := struct{};
foo := bar.+baz := "" ?: "truthty" ? 1 : 0 ? Call(i) : DoNotCall();
print(foo);