public void testTryWithoutCatchLocation() { AstNode root = parse("\ntry {\n" + " var x = 1;\n" + "} finally {\n" + " var y = 2;\n" + "}\n"); TryStatement tryStmt = (TryStatement) root.getFirstChild(); AstNode tryBlock = tryStmt.getTryBlock(); List<CatchClause> catchBlocks = tryStmt.getCatchClauses(); Scope finallyBlock = (Scope) tryStmt.getFinallyBlock(); AstNode finallyStmt = (AstNode) finallyBlock.getFirstChild(); assertEquals(1, tryStmt.getLineno()); assertEquals(1, tryBlock.getLineno()); assertEquals(3, finallyBlock.getLineno()); assertEquals(4, finallyStmt.getLineno()); }
public void testTryWithoutFinallyLocation() { AstNode root = parse("\ntry {\n" + " var x = 1;\n" + "} catch (ex) {\n" + " var y = 2;\n" + "}\n"); TryStatement tryStmt = (TryStatement) root.getFirstChild(); Scope tryBlock = (Scope) tryStmt.getTryBlock(); List<CatchClause> catchBlocks = tryStmt.getCatchClauses(); CatchClause catchClause = catchBlocks.get(0); AstNode catchStmt = catchClause.getBody(); AstNode exceptionVar = catchClause.getVarName(); AstNode varDecl = (AstNode) catchStmt.getFirstChild(); assertEquals(1, tryStmt.getLineno()); assertEquals(1, tryBlock.getLineno()); assertEquals(3, catchClause.getLineno()); assertEquals(3, catchStmt.getLineno()); assertEquals(3, exceptionVar.getLineno()); assertEquals(4, varDecl.getLineno()); }