public void testIfStatement() throws CompilerException {
assertParserOutput(
new IfStatement(
new BooleanLiteral(true),
new ExpressionStatement(
new Identifier("foo")
),
null
),
"if (true) foo;"
);
assertParserOutput(
new IfStatement(
new BooleanLiteral(true),
new ExpressionStatement(
new Identifier("foo")
),
new ExpressionStatement(
new Identifier("bar")
)
),
"if (true) foo; else bar;"
);
assertParserOutput(
new IfStatement(
new BooleanLiteral(true),
new IfStatement(
new BooleanLiteral(true),
new ExpressionStatement(
new Identifier("foo")
),
new ExpressionStatement(
new Identifier("bar")
)
),
null
),
"if (true) if (true) foo; else bar;"
);
assertParserOutput(
new IfStatement(
new BooleanLiteral(true),
new IfStatement(
new BooleanLiteral(true),
new ExpressionStatement(
new Identifier("foo")
),
new ExpressionStatement(
new Identifier("bar")
)
),
new ExpressionStatement(
new Identifier("baz")
)
),
"if (true) if (true) foo; else bar; else baz;"
);
}