From 8f4712869318573e5797abc1db320213148b3b44 Mon Sep 17 00:00:00 2001 From: David Dixon-Peugh Date: Wed, 17 Jul 2002 05:10:40 +0000 Subject: [PATCH] Tests location information retrieved from the SimpleNode. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@394 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/ast/SimpleNodeTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 pmd/regress/test/net/sourceforge/pmd/ast/SimpleNodeTest.java diff --git a/pmd/regress/test/net/sourceforge/pmd/ast/SimpleNodeTest.java b/pmd/regress/test/net/sourceforge/pmd/ast/SimpleNodeTest.java new file mode 100644 index 0000000000..3ec6e53cdd --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/ast/SimpleNodeTest.java @@ -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() ); + + } +}