ParserAdapter extends Parser<G> { @Override public AstNode parse(String source) { LocatedText text = new LocatedText(null, source.toCharArray()); return parse(text); } ParserAdapter(Charset charset, G grammar); @Override AstNode parse(String source); @Override AstNode parse(File file); @Override AstNode parse(List<Token> tokens); @Override RuleDefinition getRootRule();  }
@Test public void should_parse_string() { parser.parse("1+1"); }
@Test public void should_not_parse_invalid_string() { thrown.expect(RecognitionException.class); thrown.expectMessage("Parse error"); parser.parse(""); }
@Test public void should_parse_file() throws Exception { File file = temporaryFolder.newFile(); Files.write("1+1", file, StandardCharsets.UTF_8); parser.parse(file); }
@Test public void should_not_parse_invalid_file() { thrown.expect(RecognitionException.class); File file = new File("notfound"); parser.parse(file); }
@Test public void parse_tokens_unsupported() { thrown.expect(UnsupportedOperationException.class); List<Token> tokens = ImmutableList.of(); parser.parse(tokens); }