01: package test.net.sourceforge.pmd.symboltable;
02:
03: import static org.junit.Assert.assertEquals;
04: import net.sourceforge.pmd.PMD;
05: import net.sourceforge.pmd.ast.ASTCompilationUnit;
06: import net.sourceforge.pmd.symboltable.ClassNameDeclaration;
07: import net.sourceforge.pmd.symboltable.Scope;
08:
09: import org.junit.Test;
10:
11: import java.util.Map;
12:
13: public class GlobalScopeTest extends STBBaseTst {
14:
15: @Test
16: public void testClassDeclAppears() {
17: parseCode(TEST1);
18: ASTCompilationUnit decl = acu.findChildrenOfType(
19: ASTCompilationUnit.class).get(0);
20: Scope scope = decl.getScope();
21: Map m = scope.getClassDeclarations();
22: ClassNameDeclaration classNameDeclaration = (ClassNameDeclaration) m
23: .keySet().iterator().next();
24: assertEquals(classNameDeclaration.getImage(), "Foo");
25: }
26:
27: @Test
28: public void testEnums() {
29: parseCode15(TEST2);
30: }
31:
32: private static final String TEST1 = "public class Foo {}" + PMD.EOL;
33:
34: private static final String TEST2 = "public enum Bar {" + PMD.EOL
35: + " FOO1 { " + PMD.EOL
36: + " private static final String FIELD_NAME = \"\";"
37: + PMD.EOL + " }," + PMD.EOL + " FOO2 { "
38: + PMD.EOL
39: + " private static final String FIELD_NAME = \"\";"
40: + PMD.EOL + " }" + PMD.EOL + "}" + PMD.EOL;
41:
42: public static junit.framework.Test suite() {
43: return new junit.framework.JUnit4TestAdapter(
44: GlobalScopeTest.class);
45: }
46: }
|