()
| 307 | } |
| 308 | |
| 309 | @Test |
| 310 | public void testAST() throws IOException, RecognitionException { |
| 311 | CharStream input = new QueryParserFileStream( "test/org/apache/pig/parser/TestAST.pig" ); |
| 312 | QueryLexer lexer = new QueryLexer(input); |
| 313 | CommonTokenStream tokens = new CommonTokenStream(lexer); |
| 314 | |
| 315 | QueryParser parser = new QueryParser(tokens); |
| 316 | QueryParser.query_return result = parser.query(); |
| 317 | |
| 318 | Tree ast = (Tree)result.getTree(); |
| 319 | |
| 320 | System.out.println( ast.toStringTree() ); |
| 321 | TreePrinter.printTree( (CommonTree)ast, 0 ); |
| 322 | Assert.assertEquals( 0, lexer.getNumberOfSyntaxErrors() ); |
| 323 | Assert.assertEquals( 0, parser.getNumberOfSyntaxErrors() ); |
| 324 | |
| 325 | Assert.assertEquals( "QUERY", ast.getText() ); |
| 326 | Assert.assertEquals( 5, ast.getChildCount() ); |
| 327 | |
| 328 | for( int i = 0; i < ast.getChildCount(); i++ ) { |
| 329 | Tree c = ast.getChild( i ); |
| 330 | Assert.assertEquals( "STATEMENT", c.getText() ); |
| 331 | } |
| 332 | |
| 333 | Tree stmt = ast.getChild( 0 ); |
| 334 | Assert.assertEquals( "A", stmt.getChild( 0 ).getText() ); // alias |
| 335 | Assert.assertTrue( "LOAD".equalsIgnoreCase( stmt.getChild( 1 ).getText() ) ); |
| 336 | |
| 337 | stmt = ast.getChild( 1 ); |
| 338 | Assert.assertEquals( "B", stmt.getChild( 0 ).getText() ); // alias |
| 339 | Assert.assertTrue( "FOREACH".equalsIgnoreCase( stmt.getChild( 1 ).getText() ) ); |
| 340 | |
| 341 | stmt = ast.getChild( 2 ); |
| 342 | Assert.assertEquals( "C", stmt.getChild( 0 ).getText() ); // alias |
| 343 | Assert.assertTrue( "FILTER".equalsIgnoreCase( stmt.getChild( 1 ).getText() ) ); |
| 344 | |
| 345 | stmt = ast.getChild( 3 ); |
| 346 | Assert.assertEquals( "D", stmt.getChild( 0 ).getText() ); // alias |
| 347 | Assert.assertTrue( "LIMIT".equalsIgnoreCase( stmt.getChild( 1 ).getText() ) ); |
| 348 | |
| 349 | stmt = ast.getChild( 4 ); |
| 350 | Assert.assertTrue( "STORE".equalsIgnoreCase( stmt.getChild( 0 ).getText() ) ); |
| 351 | } |
| 352 | |
| 353 | @Test |
| 354 | public void testMultilineFunctionArguments() throws RecognitionException, IOException { |
nothing calls this directly
no test coverage detected