f38280c2924c28efb2d50b579e0bbd1ed76978a2
[idea/community.git] / plugins / groovy / test / org / jetbrains / plugins / groovy / lang / GroovyHighlightingTest.java
1 /*
2  * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
3  * Use is subject to license terms.
4  */
5 package org.jetbrains.plugins.groovy.lang;
6
7 import com.intellij.codeInspection.LocalInspectionTool;
8 import com.intellij.openapi.module.Module;
9 import com.intellij.openapi.roots.ContentEntry;
10 import com.intellij.openapi.roots.ModifiableRootModel;
11 import com.intellij.openapi.roots.OrderRootType;
12 import com.intellij.openapi.roots.libraries.Library;
13 import com.intellij.openapi.vfs.JarFileSystem;
14 import com.intellij.openapi.vfs.VirtualFile;
15 import com.intellij.testFramework.LightProjectDescriptor;
16 import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
17 import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
18 import org.jetbrains.annotations.NotNull;
19 import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection;
20 import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection;
21 import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyResultOfObjectAllocationIgnoredInspection;
22 import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection;
23 import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection;
24 import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection;
25 import org.jetbrains.plugins.groovy.codeInspection.unassignedVariable.UnassignedVariableAccessInspection;
26 import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUnresolvedAccessInspection;
27 import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUntypedAccessInspection;
28 import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection;
29 import org.jetbrains.plugins.groovy.util.TestUtils;
30
31 import java.io.IOException;
32
33 /**
34  * @author peter
35  */
36 public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
37   public static final DefaultLightProjectDescriptor GROOVY_17_PROJECT_DESCRIPTOR = new DefaultLightProjectDescriptor() {
38     @Override
39     public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
40       final Library.ModifiableModel modifiableModel = model.getModuleLibraryTable().createLibrary("GROOVY").getModifiableModel();
41       final VirtualFile groovyJar =
42         JarFileSystem.getInstance().refreshAndFindFileByPath(TestUtils.getMockGroovy1_7LibraryName()+"!/");
43       modifiableModel.addRoot(groovyJar, OrderRootType.CLASSES);
44       modifiableModel.commit();
45     }
46   };
47
48   @Override
49   protected String getBasePath() {
50     return TestUtils.getTestDataPath() + "highlighting/";
51   }
52
53   @NotNull
54   @Override
55   protected LightProjectDescriptor getProjectDescriptor() {
56     return GROOVY_17_PROJECT_DESCRIPTOR;
57   }
58
59   public void testDuplicateClosurePrivateVariable() throws Throwable {
60     doTest();
61   }
62
63   public void testClosureRedefiningVariable() throws Throwable {
64     doTest();
65   }
66
67   private void doTest(LocalInspectionTool... tools) throws Exception {
68     myFixture.enableInspections(tools);
69     myFixture.testHighlighting(true, false, false, getTestName(false) + ".groovy");
70   }
71
72   public void testCircularInheritance() throws Throwable {
73     doTest();
74   }
75
76   public void testEmptyTupleType() throws Throwable {
77     doTest();
78   }
79
80   public void testMapDeclaration() throws Throwable {
81     doTest();
82   }
83
84   public void testShouldntImplementGroovyObjectMethods() throws Throwable {
85     addGroovyObject();
86     myFixture.addFileToProject("Foo.groovy", "class Foo {}");
87     myFixture.testHighlighting(false, false, false, getTestName(false) + ".java");
88   }
89
90   public void testJavaClassImplementingGroovyInterface() throws Throwable {
91     addGroovyObject();
92     myFixture.addFileToProject("Foo.groovy", "interface Foo {}");
93     myFixture.testHighlighting(false, false, false, getTestName(false) + ".java");
94   }
95
96   private void addGroovyObject() throws IOException {
97     myFixture.addClass("package groovy.lang;" +
98                        "public interface GroovyObject  {\n" +
99                        "    java.lang.Object invokeMethod(java.lang.String s, java.lang.Object o);\n" +
100                        "    java.lang.Object getProperty(java.lang.String s);\n" +
101                        "    void setProperty(java.lang.String s, java.lang.Object o);\n" +
102                        "    groovy.lang.MetaClass getMetaClass();\n" +
103                        "    void setMetaClass(groovy.lang.MetaClass metaClass);\n" +
104                        "}");
105   }
106
107   public void testDuplicateFields() throws Throwable {
108     doTest();
109   }
110
111   public void testNoDuplicationThroughClosureBorder() throws Throwable {
112     myFixture.addClass("package groovy.lang; public interface Closure {}");
113     doTest();
114   }
115
116   public void testRecursiveMethodTypeInference() throws Throwable {
117     doTest();
118   }
119
120   public void testSuperClassNotExists() throws Exception {
121     doTest();
122   }
123   public void testDontSimplifyString() throws Throwable { doTest(new GroovyTrivialIfInspection(), new GroovyTrivialConditionalInspection()); }
124
125   public void testRawMethodAccess() throws Throwable { doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
126
127   public void testRawFieldAccess() throws Throwable { doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
128
129   public void testRawArrayStyleAccess() throws Throwable { doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
130
131   public void testRawArrayStyleAccessToMap() throws Throwable { doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
132
133   public void testRawArrayStyleAccessToList() throws Throwable { doTest(new GroovyUncheckedAssignmentOfMemberOfRawTypeInspection()); }
134
135   public void testIncompatibleTypesAssignments() throws Throwable { doTest(new GroovyAssignabilityCheckInspection()); }
136
137   public void testAnonymousClassConstructor() throws Throwable {doTest();}
138   public void testAnonymousClassAbstractMethod() throws Throwable {doTest();}
139   public void testAnonymousClassStaticMethod() throws Throwable {doTest();}
140   public void testAnonymousClassShoudImplementMethods() throws Throwable {doTest();}
141
142
143   public void testDefaultMapConstructorNamedArgs() throws Throwable {doTest();}
144   public void testDefaultMapConstructorNamedArgsError() throws Throwable {doTest();}
145   public void testDefaultMapConstructorWhenDefConstructorExists() throws Throwable {doTest();}
146
147   public void testSingleAllocationInClosure() throws Throwable {doTest(new GroovyResultOfObjectAllocationIgnoredInspection());}
148
149   public void testUnresolvedLhsAssignment() throws Throwable { doTest(new GroovyUnresolvedAccessInspection()); }
150
151   public void testUnresolvedMethodCallWithTwoDeclarations() throws Throwable{
152     doTest();
153   }
154
155   public void testUnresolvedAccess() throws Exception { doTest(new GroovyUnresolvedAccessInspection()); }
156   public void testUntypedAccess() throws Exception { doTest(new GroovyUntypedAccessInspection()); }
157
158   public void testUnassigned1() throws Exception { doTest(new UnassignedVariableAccessInspection()); }
159   public void testUnassigned2() throws Exception { doTest(new UnassignedVariableAccessInspection()); }
160   public void testUnassigned3() throws Exception { doTest(new UnassignedVariableAccessInspection()); }
161   public void testUnassignedTryFinally() throws Exception { doTest(new UnassignedVariableAccessInspection()); }
162
163   public void testUnusedVariable() throws Exception { doTest(new UnusedDefInspection()); }
164   public void testDefinitionUsedInClosure() throws Exception { doTest(new UnusedDefInspection()); }
165   public void testDefinitionUsedInClosure2() throws Exception { doTest(new UnusedDefInspection()); }
166   public void testDuplicateInnerClass() throws Throwable{doTest();}
167
168   public void testThisInStaticContext() throws Throwable {doTest();}
169   public void testSuperWithNotEnclosingClass() throws Throwable {doTest();}
170   public void testThisWithWrongQualifier() throws Throwable {doTest();}
171
172   public void testModifiersInPackageAndImportStatements() throws Throwable {
173     myFixture.copyFileToProject(getTestName(false) + ".groovy", "x/"+getTestName(false)+".groovy");
174     myFixture.testHighlighting(true, false, false, "x/"+getTestName(false)+".groovy");
175   }
176
177   public void testBreakOutside() throws Exception {doTest();}
178   public void testUndefinedLabel() throws Exception {doTest();}
179   public void testUsedLabel() throws Exception {doTest();}
180
181   public void testNestedMethods() throws Throwable {
182     doTest();
183   }
184
185   public void testRawOverridedMethod() throws Exception {doTest();}
186
187   public void testFQNJavaClassesUsages() throws Exception {
188     doTest();
189   }
190
191   public void testGstringAssignableToString() throws Exception{doTest();} 
192   public void testGstringAssignableToStringInClosureParameter() throws Exception{doTest();}
193   public void testEverythingAssignableToString() throws Exception {doTest(new GroovyAssignabilityCheckInspection());}
194
195   public void testEachOverRange() throws Exception {doTest();}
196
197   public void testMethodCallWithDefaultParameters() throws Exception {doTest();}
198   public void testClosureWithDefaultParameters() throws Exception {doTest();}
199   public void testClosureCallMethodWithInapplicableArguments() throws Exception {doTest();}
200
201   public void testOverlyLongMethodInspection() throws Exception {
202     doTest(new GroovyOverlyLongMethodInspection());
203   }
204
205   public void testStringAndGStringUpperBound() throws Exception {doTest();}
206
207   public void testWithMethod() throws Exception {doTest();}
208   public void testByteArrayArgument() throws Exception {doTest();}
209
210   public void testForLoopWithNestedEndlessLoop() throws Exception {doTest(new UnassignedVariableAccessInspection());}
211   public void testIfIncrementElseReturn() throws Exception {doTest(new UnusedDefInspection()); }
212
213   public void testArrayLikeAccess() throws Exception {doTest();}
214
215   public void testSetInitializing() throws Exception {doTest();}
216
217   public void testEmptyTupleAssignability() throws Exception {doTest();}
218
219   public void testGrDefFieldsArePrivateInJavaCode() throws Exception {
220     myFixture.configureByText("X.groovy", "public class X{def x=5}");
221     myFixture.testHighlighting(true, false, false, getTestName(false) + ".java");
222   }
223
224   public void testSuperConstructorInvocation() throws Exception {doTest();}
225 }