Search in sources :

Example 1 with ValueIfElseToken

use of org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken in project jphp by jphp-compiler.

the class SimpleExprTest method testIfElse.

@Test
public void testIfElse() {
    List<Token> tokens = getSyntaxTree("call(1, true ? 1 : 2, 'foobar');");
    Assert.assertEquals(1, tokens.size());
    Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tokens.get(0)).getLast() instanceof CallExprToken);
    CallExprToken call = (CallExprToken) ((ExprStmtToken) tokens.get(0)).getLast();
    Assert.assertEquals(3, call.getParameters().size());
    Assert.assertTrue(call.getParameters().get(0).getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(call.getParameters().get(1).getTokens().get(1) instanceof ValueIfElseToken);
    ValueIfElseToken ifElse = (ValueIfElseToken) call.getParameters().get(1).getTokens().get(1);
    Assert.assertTrue(ifElse.getValue().getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(ifElse.getAlternative().getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(call.getParameters().get(2).getSingle() instanceof StringExprToken);
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) Token(org.develnext.jphp.core.tokenizer.token.Token) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) MinusExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken) Test(org.junit.Test)

Aggregations

Token (org.develnext.jphp.core.tokenizer.token.Token)1 MinusExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken)1 ValueIfElseToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken)1 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)1 Test (org.junit.Test)1