01: package test.net.sourceforge.pmd.ast;
02:
03: import static org.junit.Assert.assertEquals;
04: import net.sourceforge.pmd.PMD;
05: import net.sourceforge.pmd.TargetJDK1_4;
06: import net.sourceforge.pmd.ast.ASTCompilationUnit;
07: import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration;
08: import net.sourceforge.pmd.ast.JavaParser;
09:
10: import org.junit.Test;
11:
12: import test.net.sourceforge.pmd.testframework.ParserTst;
13:
14: import java.io.StringReader;
15:
16: public class ASTLocalVariableDeclarationTest extends ParserTst {
17:
18: @Test
19: public void testSingleDimArray() {
20: JavaParser parser = (new TargetJDK1_4())
21: .createParser(new StringReader(TEST1));
22: ASTCompilationUnit cu = parser.CompilationUnit();
23: ASTLocalVariableDeclaration node = cu.findChildrenOfType(
24: ASTLocalVariableDeclaration.class).get(0);
25: assertEquals(1, node.getArrayDepth());
26: }
27:
28: @Test
29: public void testMultDimArray() {
30: JavaParser parser = (new TargetJDK1_4())
31: .createParser(new StringReader(TEST2));
32: ASTCompilationUnit cu = parser.CompilationUnit();
33: ASTLocalVariableDeclaration node = cu.findChildrenOfType(
34: ASTLocalVariableDeclaration.class).get(0);
35: assertEquals(2, node.getArrayDepth());
36: }
37:
38: @Test
39: public void testMultDimArraySplitBraces() {
40: JavaParser parser = (new TargetJDK1_4())
41: .createParser(new StringReader(TEST3));
42: ASTCompilationUnit cu = parser.CompilationUnit();
43: ASTLocalVariableDeclaration node = cu.findChildrenOfType(
44: ASTLocalVariableDeclaration.class).get(0);
45: assertEquals(3, node.getArrayDepth());
46: }
47:
48: private static final String TEST1 = "class Foo {" + PMD.EOL
49: + " void bar() {int x[] = null;}" + PMD.EOL + "}";
50:
51: private static final String TEST2 = "class Foo {" + PMD.EOL
52: + " void bar() {int x[][] = null;}" + PMD.EOL + "}";
53:
54: private static final String TEST3 = "class Foo {" + PMD.EOL
55: + " void bar() {int[] x[][] = null;}" + PMD.EOL + "}";
56:
57: public static junit.framework.Test suite() {
58: return new junit.framework.JUnit4TestAdapter(
59: ASTLocalVariableDeclarationTest.class);
60: }
61: }
|