use of php.runtime.env.Context in project jphp by jphp-compiler.
the class TokenizerTest method testSimple.
@Test
public void testSimple() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context(""));
assertNull(tokenizer.nextToken());
assertEquals("", tokenizer.getCode());
tokenizer = new Tokenizer(new Context(" "));
assertNull(tokenizer.nextToken());
tokenizer = new Tokenizer(new Context(" "));
assertNull(tokenizer.nextToken());
tokenizer = new Tokenizer(new Context("\t"));
assertNull(tokenizer.nextToken());
tokenizer = new Tokenizer(new Context("\n"));
assertNull(tokenizer.nextToken());
tokenizer = new Tokenizer(new Context("\r"));
assertNull(tokenizer.nextToken());
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class CommentsTest method testBug154.
@Test
public void testBug154() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("/*// */"));
Token token = tokenizer.nextToken();
assertTrue(token instanceof CommentToken);
assertEquals(CommentToken.Kind.BLOCK, ((CommentToken) token).getKind());
assertEquals("// ", ((CommentToken) token).getComment());
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class TokenizerTest method testMagicString.
@Test
public void testMagicString() throws IOException {
Token token;
Tokenizer tokenizer = new Tokenizer(new Context("\"\\.{$foo}\""));
token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals(".{$foo}", ((StringExprToken) token).getValue());
assertEquals(1, ((StringExprToken) token).getSegments().size());
StringExprToken.Segment segment = ((StringExprToken) token).getSegments().get(0);
assertEquals(1, segment.from);
assertEquals(7, segment.to);
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class SyntaxAnalyzerTest method testUnexpectedEnd.
@Test(expected = ErrorException.class)
public void testUnexpectedEnd() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("foobar"));
environment.scope.setLangMode(LangMode.DEFAULT);
new SyntaxAnalyzer(environment, tokenizer);
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class AbstractSyntaxTestCase method getSyntaxTree.
protected List<Token> getSyntaxTree(String code) {
Tokenizer tokenizer = null;
try {
tokenizer = new Tokenizer(new Context(code));
environment.scope.setLangMode(LangMode.DEFAULT);
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
return analyzer.getTree();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations