use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class IfSyntaxTest method testShortly.
@Test
public void testShortly() {
List<Token> tree = getSyntaxTree("if (true) 'string'; 123;");
Assert.assertTrue(tree.size() == 2);
Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
Assert.assertNotNull(token.getBody());
Assert.assertNotNull(token.getCondition());
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class IfSyntaxTest method testNested.
@Test
public void testNested() {
List<Token> tree = getSyntaxTree("if (true){ " + "'string'; " + "if(false){ " + "1234; " + "} " + "}");
Assert.assertTrue(tree.size() == 1);
Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
Assert.assertNotNull(token.getBody());
Assert.assertTrue(token.getBody().getInstructions().size() == 2);
Assert.assertTrue(token.getBody().getInstructions().get(1).getTokens().size() == 1);
Assert.assertTrue(token.getBody().getInstructions().get(1).getTokens().get(0) instanceof IfStmtToken);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class IfSyntaxTest method testAlternative.
@Test
public void testAlternative() {
List<Token> tree = getSyntaxTree("if (true): 123; endif");
Assert.assertTrue(tree.size() == 1);
Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
Assert.assertNotNull(token.getBody());
Assert.assertNotNull(token.getCondition());
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class IfSyntaxTest method testSimple.
@Test
public void testSimple() {
List<Token> tree = getSyntaxTree("if (true) { } ");
Assert.assertTrue(tree.size() == 1);
Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
Assert.assertNotNull(token.getBody());
Assert.assertNotNull(token.getCondition());
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class NamedFunctionTest method testSimple.
@Test
public void testSimple() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("function myFunc($x, &$y, $z = 33){ } $x = 10;"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
ListIterator<Token> iterator = analyzer.getTree().listIterator();
Token token;
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue((token = iterator.next()) instanceof FunctionStmtToken);
FunctionStmtToken func = (FunctionStmtToken) token;
Assert.assertFalse(func.isReturnReference());
List<ArgumentStmtToken> arguments = func.getArguments();
Assert.assertTrue(arguments != null && arguments.size() == 3);
Assert.assertFalse(arguments.get(0).isReference());
Assert.assertTrue(arguments.get(1).isReference());
Assert.assertNotNull(arguments.get(2).getValue());
Assert.assertEquals("myFunc", func.getName().getName());
Assert.assertNotNull(func.getBody());
Assert.assertFalse(func.isInterfacable());
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next() instanceof ExprStmtToken);
Assert.assertFalse(iterator.hasNext());
}
Aggregations