Пример #1
0
  public void testLinenoFunctionCall() {
    AstNode root = parse("\nfoo.\n" + "bar.\n" + "baz(1);");

    ExpressionStatement stmt = (ExpressionStatement) root.getFirstChild();
    FunctionCall fc = (FunctionCall) stmt.getExpression();
    // Line number should get closest to the actual paren.
    assertEquals(3, fc.getLineno());
  }
Пример #2
0
  public void testRegexpLocation() {
    AstNode root = parse("\nvar path =\n" + "      replace(\n" + "/a/g," + "'/');\n");

    VariableDeclaration firstVarDecl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = firstVarDecl.getVariables();
    VariableInitializer firstInitializer = vars1.get(0);
    Name firstVarName = (Name) firstInitializer.getTarget();
    FunctionCall callNode = (FunctionCall) firstInitializer.getInitializer();
    AstNode fnName = callNode.getTarget();
    List<AstNode> args = callNode.getArguments();
    RegExpLiteral regexObject = (RegExpLiteral) args.get(0);
    AstNode aString = args.get(1);

    assertEquals(1, firstVarDecl.getLineno());
    assertEquals(1, firstVarName.getLineno());
    assertEquals(2, callNode.getLineno());
    assertEquals(2, fnName.getLineno());
    assertEquals(3, regexObject.getLineno());
    assertEquals(3, aString.getLineno());
  }