Tests location information retrieved from the SimpleNode.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@394 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
76
pmd/regress/test/net/sourceforge/pmd/ast/SimpleNodeTest.java
Normal file
76
pmd/regress/test/net/sourceforge/pmd/ast/SimpleNodeTest.java
Normal file
@ -0,0 +1,76 @@
|
||||
package test.net.sourceforge.pmd.ast;
|
||||
|
||||
import net.sourceforge.pmd.ast.*;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SimpleNodeTest
|
||||
extends ParserTst
|
||||
{
|
||||
public SimpleNodeTest( String name ) {
|
||||
super( name );
|
||||
}
|
||||
|
||||
public void testMethodDiffLines()
|
||||
throws Throwable
|
||||
{
|
||||
String javaCode = "public class Test {\n";
|
||||
javaCode += " public void helloWorld() \n"; // Line 2, Col 3
|
||||
javaCode += " { System.err.println(\"Hello World\"); \n";
|
||||
javaCode += " } \n"; // Line 4, Col 2
|
||||
javaCode += "}";
|
||||
|
||||
Set methods = getNodes( ASTMethodDeclaration.class,
|
||||
javaCode );
|
||||
Iterator iter = methods.iterator();
|
||||
assertTrue( iter.hasNext() );
|
||||
verifyNode( (SimpleNode) iter.next(),
|
||||
2, 3, 4, 2 );
|
||||
}
|
||||
|
||||
public void testMethodSameColumn()
|
||||
throws Throwable
|
||||
{
|
||||
String javaCode = "public class Test {\n";
|
||||
javaCode += "public void helloWorld() {\n"; // Line 2, Col 1
|
||||
javaCode += "} \n"; // Line 3, Col 1
|
||||
javaCode += "}\n";
|
||||
|
||||
Set methods = getNodes( ASTMethodDeclaration.class,
|
||||
javaCode );
|
||||
Iterator iter = methods.iterator();
|
||||
assertTrue( iter.hasNext() );
|
||||
verifyNode( (SimpleNode) iter.next(),
|
||||
2, 1, 3, 1 );
|
||||
}
|
||||
|
||||
public void testMethodSameLine()
|
||||
throws Throwable
|
||||
{
|
||||
String javaCode = "public class Test {\n";
|
||||
javaCode += " public void helloWorld() {}\n"; // 2, 3 -> 2, 29
|
||||
javaCode += "}\n";
|
||||
|
||||
Set methods = getNodes( ASTMethodDeclaration.class,
|
||||
javaCode );
|
||||
Iterator iter = methods.iterator();
|
||||
assertTrue( iter.hasNext() );
|
||||
verifyNode( (SimpleNode) iter.next(),
|
||||
2, 3, 2, 29 );
|
||||
}
|
||||
|
||||
public void verifyNode( SimpleNode node,
|
||||
int beginLine, int beginCol,
|
||||
int endLine, int endCol ) {
|
||||
assertEquals( "Wrong Line Number provided for Start: ",
|
||||
beginLine, node.getBeginLine() );
|
||||
assertEquals( "Wrong Column provided for Begin: ",
|
||||
beginCol, node.getBeginColumn() );
|
||||
assertEquals( "Wrong Line Number provided for End: ",
|
||||
endLine, node.getEndLine() );
|
||||
assertEquals( "Wrong Column provide for End: ",
|
||||
endCol, node.getEndColumn() );
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user