🐐 short circuit evaluation
This commit is contained in:
29
tests.py
29
tests.py
@@ -698,6 +698,9 @@ error_tests = [
|
||||
("DEFINI f () VT { REDI(I) }\nINVOCA f (I)", CentvrionError), # args to zero-param function
|
||||
("SI NVLLVS TVNC { DESIGNA r VT I }", CentvrionError), # NVLLVS cannot be used as boolean
|
||||
("NVLLVS AVT VERITAS", CentvrionError), # NVLLVS cannot be used as boolean in AVT
|
||||
("FALSITAS AVT NVLLVS", CentvrionError), # no short-circuit: right side evaluated, NVLLVS not boolean
|
||||
("VERITAS ET NVLLVS", CentvrionError), # no short-circuit: right side evaluated, NVLLVS not boolean
|
||||
("NVLLVS ET VERITAS", CentvrionError), # NVLLVS cannot be used as boolean in ET
|
||||
('"hello" + " world"', CentvrionError), # use & for string concatenation, not +
|
||||
("[I, II][III]", CentvrionError), # index too high
|
||||
("CVM SVBNVLLA\n[I, II][-I]", CentvrionError), # negative index
|
||||
@@ -1612,6 +1615,32 @@ et_avt_tests = [
|
||||
("SI FALSITAS AVT FALSITAS TVNC { DESIGNA r VT I } ALIVD { DESIGNA r VT II }\nr",
|
||||
Program([], [SiStatement(BinOp(Bool(False), Bool(False), "KEYWORD_AVT"), [Designa(ID("r"), Numeral("I"))], [Designa(ID("r"), Numeral("II"))]), ExpressionStatement(ID("r"))]),
|
||||
ValInt(2)),
|
||||
# short-circuit: right side not evaluated when result is determined
|
||||
("VERITAS AVT NVLLVS",
|
||||
Program([], [ExpressionStatement(BinOp(Bool(True), Nullus(), "KEYWORD_AVT"))]),
|
||||
ValBool(True)),
|
||||
("FALSITAS ET NVLLVS",
|
||||
Program([], [ExpressionStatement(BinOp(Bool(False), Nullus(), "KEYWORD_ET"))]),
|
||||
ValBool(False)),
|
||||
# short-circuit with side-effect-prone expressions
|
||||
("DESIGNA x VT NVLLVS\nSI x EST NVLLVS AVT [I, II][x] EST I TVNC { DESIGNA r VT I } ALIVD { DESIGNA r VT II }\nr",
|
||||
Program([], [
|
||||
Designa(ID("x"), Nullus()),
|
||||
SiStatement(
|
||||
BinOp(BinOp(ID("x"), Nullus(), "KEYWORD_EST"), BinOp(ArrayIndex(DataArray([Numeral("I"), Numeral("II")]), ID("x")), Numeral("I"), "KEYWORD_EST"), "KEYWORD_AVT"),
|
||||
[Designa(ID("r"), Numeral("I"))],
|
||||
[Designa(ID("r"), Numeral("II"))]),
|
||||
ExpressionStatement(ID("r"))]),
|
||||
ValInt(1)),
|
||||
("DESIGNA x VT NVLLVS\nSI x DISPAR NVLLVS ET [I, II][x] EST I TVNC { DESIGNA r VT I } ALIVD { DESIGNA r VT II }\nr",
|
||||
Program([], [
|
||||
Designa(ID("x"), Nullus()),
|
||||
SiStatement(
|
||||
BinOp(BinOp(ID("x"), Nullus(), "KEYWORD_DISPAR"), BinOp(ArrayIndex(DataArray([Numeral("I"), Numeral("II")]), ID("x")), Numeral("I"), "KEYWORD_EST"), "KEYWORD_ET"),
|
||||
[Designa(ID("r"), Numeral("I"))],
|
||||
[Designa(ID("r"), Numeral("II"))]),
|
||||
ExpressionStatement(ID("r"))]),
|
||||
ValInt(2)),
|
||||
]
|
||||
|
||||
class TestEtAvt(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user