Output for While wrong defined

So i Wrote some tests to figure out the outputs of the AST. The Specification states the following:

The while statement is printed as While_loopbound?[cond, body, invariant?, termination?].
If no loop bound and termination but an invariant is given, the syntax would be
While[cond, body, invariant].

This suggest, that a condition and a body are always given and the three other are optional.
However i get this output on one of my tests:

expected:<While[_'<characterconstant>'][Const_1,Block[],Con...> but was:<While[][Const_1,Block[],Con...>

i give “1” as the condition, an empty block as the body, the char “i” as invariant, a token as the bound and only the termination should be null.

So why exactly is the correct implementation not printing "_'<characterconstant>'" where I expect it?

Because having a loop bound variable without a termination function does not make sense. Such a statement can not be created by the parser and thus is “undefined behavior” since the general contract for the ASTFactory is that it is only invoked in ways indistinguishable from the parser.

Similarly, having a termination function/loop bound binder without an invariant can also not happen.

In other words, your test is wrong :slightly_smiling_face:

Hope this helps,

so it is not needed to change my method in such a way. I wrote more "undefined behavior " tests but I guess it does not really matter was my AST .toString() prints in these cases.(or even if i get an AST in the first place)

Indeed. UB = We do not test for this, here.