public void testLinenoInfix() { AstRoot root = parse( "\nvar d = a\n" + " + \n" + " b;\n" + "var\n" + " e =\n" + " a +\n" + " c;\n" + "var f = b\n" + " / c;\n"); VariableDeclaration stmt1 = (VariableDeclaration) root.getFirstChild(); List<VariableInitializer> vars1 = stmt1.getVariables(); VariableInitializer var1 = vars1.get(0); Name firstVarName = (Name) var1.getTarget(); InfixExpression var1Add = (InfixExpression) var1.getInitializer(); VariableDeclaration stmt2 = (VariableDeclaration) stmt1.getNext(); List<VariableInitializer> vars2 = stmt2.getVariables(); VariableInitializer var2 = vars2.get(0); Name secondVarName = (Name) var2.getTarget(); InfixExpression var2Add = (InfixExpression) var2.getInitializer(); VariableDeclaration stmt3 = (VariableDeclaration) stmt2.getNext(); List<VariableInitializer> vars3 = stmt3.getVariables(); VariableInitializer var3 = vars3.get(0); Name thirdVarName = (Name) var3.getTarget(); InfixExpression thirdVarDiv = (InfixExpression) var3.getInitializer(); ReturnStatement returnStmt = (ReturnStatement) stmt3.getNext(); assertEquals(1, var1.getLineno()); assertEquals(1, firstVarName.getLineno()); assertEquals(1, var1Add.getLineno()); assertEquals(1, var1Add.getLeft().getLineno()); assertEquals(3, var1Add.getRight().getLineno()); // var directive with name on next line wrong -- // should be 6. assertEquals(5, var2.getLineno()); assertEquals(5, secondVarName.getLineno()); assertEquals(6, var2Add.getLineno()); assertEquals(6, var2Add.getLeft().getLineno()); assertEquals(7, var2Add.getRight().getLineno()); assertEquals(8, var3.getLineno()); assertEquals(8, thirdVarName.getLineno()); assertEquals(8, thirdVarDiv.getLineno()); assertEquals(8, thirdVarDiv.getLeft().getLineno()); assertEquals(9, thirdVarDiv.getRight().getLineno()); }
public void testLinenoLiteral() { AstRoot root = parse( "\nvar d =\n" + " \"foo\";\n" + "var e =\n" + " 1;\n" + "var f = \n" + " 1.2;\n" + "var g = \n" + " 2e5;\n" + "var h = \n" + " 'bar';\n"); VariableDeclaration stmt1 = (VariableDeclaration) root.getFirstChild(); List<VariableInitializer> vars1 = stmt1.getVariables(); VariableInitializer firstVar = vars1.get(0); Name firstVarName = (Name) firstVar.getTarget(); AstNode firstVarLiteral = firstVar.getInitializer(); VariableDeclaration stmt2 = (VariableDeclaration) stmt1.getNext(); List<VariableInitializer> vars2 = stmt2.getVariables(); VariableInitializer secondVar = vars2.get(0); Name secondVarName = (Name) secondVar.getTarget(); AstNode secondVarLiteral = secondVar.getInitializer(); VariableDeclaration stmt3 = (VariableDeclaration) stmt2.getNext(); List<VariableInitializer> vars3 = stmt3.getVariables(); VariableInitializer thirdVar = vars3.get(0); Name thirdVarName = (Name) thirdVar.getTarget(); AstNode thirdVarLiteral = thirdVar.getInitializer(); VariableDeclaration stmt4 = (VariableDeclaration) stmt3.getNext(); List<VariableInitializer> vars4 = stmt4.getVariables(); VariableInitializer fourthVar = vars4.get(0); Name fourthVarName = (Name) fourthVar.getTarget(); AstNode fourthVarLiteral = fourthVar.getInitializer(); VariableDeclaration stmt5 = (VariableDeclaration) stmt4.getNext(); List<VariableInitializer> vars5 = stmt5.getVariables(); VariableInitializer fifthVar = vars5.get(0); Name fifthVarName = (Name) fifthVar.getTarget(); AstNode fifthVarLiteral = fifthVar.getInitializer(); assertEquals(2, firstVarLiteral.getLineno()); assertEquals(4, secondVarLiteral.getLineno()); assertEquals(6, thirdVarLiteral.getLineno()); assertEquals(8, fourthVarLiteral.getLineno()); assertEquals(10, fifthVarLiteral.getLineno()); }