use of org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken in project jphp by jphp-compiler.
the class TokenizerTest method testStmt.
@Test
public void testStmt() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("class function private public protected static final try catch for if foreach switch while " + "default return declare case do else elseif endif endfor endforeach endwhile endswitch " + "abstract use namespace finally extends implements global"));
assertTrue(tokenizer.nextToken() instanceof ClassStmtToken);
assertTrue(tokenizer.nextToken() instanceof FunctionStmtToken);
assertTrue(tokenizer.nextToken() instanceof PrivateStmtToken);
assertTrue(tokenizer.nextToken() instanceof PublicStmtToken);
assertTrue(tokenizer.nextToken() instanceof ProtectedStmtToken);
assertTrue(tokenizer.nextToken() instanceof StaticExprToken);
assertTrue(tokenizer.nextToken() instanceof FinalStmtToken);
assertTrue(tokenizer.nextToken() instanceof TryStmtToken);
assertTrue(tokenizer.nextToken() instanceof CatchStmtToken);
assertTrue(tokenizer.nextToken() instanceof ForStmtToken);
assertTrue(tokenizer.nextToken() instanceof IfStmtToken);
assertTrue(tokenizer.nextToken() instanceof ForeachStmtToken);
assertTrue(tokenizer.nextToken() instanceof SwitchStmtToken);
assertTrue(tokenizer.nextToken() instanceof WhileStmtToken);
assertTrue(tokenizer.nextToken() instanceof DefaultStmtToken);
assertTrue(tokenizer.nextToken() instanceof ReturnStmtToken);
assertTrue(tokenizer.nextToken() instanceof DeclareStmtToken);
assertTrue(tokenizer.nextToken() instanceof CaseStmtToken);
assertTrue(tokenizer.nextToken() instanceof DoStmtToken);
assertTrue(tokenizer.nextToken() instanceof ElseStmtToken);
assertTrue(tokenizer.nextToken() instanceof ElseIfStmtToken);
assertTrue(tokenizer.nextToken() instanceof EndifStmtToken);
assertTrue(tokenizer.nextToken() instanceof EndforStmtToken);
assertTrue(tokenizer.nextToken() instanceof EndforeachStmtToken);
assertTrue(tokenizer.nextToken() instanceof EndwhileStmtToken);
assertTrue(tokenizer.nextToken() instanceof EndswitchStmtToken);
assertTrue(tokenizer.nextToken() instanceof AbstractStmtToken);
assertTrue(tokenizer.nextToken() instanceof NamespaceUseStmtToken);
assertTrue(tokenizer.nextToken() instanceof NamespaceStmtToken);
assertTrue(tokenizer.nextToken() instanceof FinallyStmtToken);
assertTrue(tokenizer.nextToken() instanceof ExtendsStmtToken);
assertTrue(tokenizer.nextToken() instanceof ImplementsStmtToken);
assertTrue(tokenizer.nextToken() instanceof GlobalStmtToken);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken in project jphp by jphp-compiler.
the class NamedFunctionTest method testNoArguments.
@Test
public void testNoArguments() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("function myFunc(){}"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().get(0) instanceof FunctionStmtToken);
FunctionStmtToken func = (FunctionStmtToken) analyzer.getTree().listIterator().next();
Assert.assertTrue(func.getArguments().size() == 0);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken 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());
}
use of org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken in project jphp by jphp-compiler.
the class NamedFunctionTest method testInterfacable.
@Test
public void testInterfacable() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("function myFunc();"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().get(0) instanceof FunctionStmtToken);
FunctionStmtToken func = (FunctionStmtToken) analyzer.getTree().listIterator().next();
Assert.assertTrue(func.isInterfacable());
}
Aggregations