mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
completion tests refactored
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.completion
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
enum CompletionResult {
|
||||
contain, equal, notContain
|
||||
}
|
||||
+4
-3
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ContentEntry
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
@@ -42,9 +43,9 @@ class GrCompletionWithLibraryTest extends GroovyCompletionTestBase {
|
||||
final String basePath = TestUtils.testDataPath + "groovy/completion/"
|
||||
|
||||
public void testCategoryMethod() {doBasicTest()}
|
||||
public void testCategoryProperty() {doBasicTest('\n')}
|
||||
public void testMultipleCategories() {doBasicTest()}
|
||||
public void testCategoryForArray() {doBasicTest('\n')}
|
||||
public void testCategoryProperty() {doCompletionTest(null, null, '\n', CompletionType.BASIC)}
|
||||
public void testMultipleCategories() {doVariantableTest(null, "", CompletionType.BASIC, CompletionResult.contain, 'getMd5', 'getMd52')}
|
||||
public void testCategoryForArray() {doCompletionTest(null, null, '\n', CompletionType.BASIC)}
|
||||
|
||||
public void testArrayLikeAccessForList() throws Throwable {doBasicTest(); }
|
||||
public void testArrayLikeAccessForMap() throws Throwable {doBasicTest();}
|
||||
|
||||
+14
-7
@@ -191,7 +191,7 @@ public class GroovyCompletionTest extends GroovyCompletionTestBase {
|
||||
}
|
||||
|
||||
public void testThisKeywordCompletionAfterClassName2() {
|
||||
doBasicTest();
|
||||
doVariantableTest(null, "", CompletionType.BASIC, CompletionResult.notContain, "this");
|
||||
}
|
||||
|
||||
public void testWhileInstanceof() { doBasicTest() }
|
||||
@@ -216,7 +216,7 @@ public class GroovyCompletionTest extends GroovyCompletionTestBase {
|
||||
}
|
||||
|
||||
public void testTypeCompletionInVariableDeclaration2() {
|
||||
doBasicTest();
|
||||
doVariantableTest(null, "", CompletionType.BASIC, CompletionResult.notContain, "ArrayList");
|
||||
}
|
||||
|
||||
public void testTypeCompletionInParameter() {
|
||||
@@ -977,7 +977,7 @@ println "abcd"
|
||||
}
|
||||
|
||||
public void testNoModifiersAfterDef() {
|
||||
checkSingleItemCompletion 'def priv<caret>', 'def priv<caret>'
|
||||
doVariantableTest('def priv<caret>', '', CompletionType.BASIC, CompletionResult.notContain, 'private')
|
||||
}
|
||||
|
||||
public void testIfSpace() { checkCompletion 'int iff; if<caret>', ' ', "int iff; if <caret>" }
|
||||
@@ -1425,7 +1425,7 @@ Base<String> b = new Inh<>()<caret>
|
||||
}
|
||||
|
||||
void testDiamondCompletion2() {
|
||||
doSmartTest('''\
|
||||
doCompletionTest('''\
|
||||
interface Base<T>{}
|
||||
|
||||
class Inh<T> implements Base<T>{}
|
||||
@@ -1441,7 +1441,7 @@ class Inh<T> implements Base<T>{}
|
||||
def foo(Base<String> b){}
|
||||
|
||||
foo(new Inh<String>()<caret>)
|
||||
''')
|
||||
''', CompletionType.SMART)
|
||||
}
|
||||
|
||||
void testPropertiesOfBaseClass() {
|
||||
@@ -1468,7 +1468,7 @@ class Inheritor extends Base {
|
||||
}
|
||||
|
||||
void testDiamondCompletionInAssignmentCompletion() {
|
||||
doSmartTest('''\
|
||||
doCompletionTest('''\
|
||||
class Foo<T> {}
|
||||
|
||||
Foo<String> var
|
||||
@@ -1478,7 +1478,7 @@ class Foo<T> {}
|
||||
|
||||
Foo<String> var
|
||||
var = new Foo<>()<caret>
|
||||
''')
|
||||
''', CompletionType.SMART)
|
||||
}
|
||||
|
||||
void testDiamondCompletionInAssignmentCompletion2() {
|
||||
@@ -1572,4 +1572,11 @@ setBarrr(<caret>)
|
||||
void testNewExprDoesntCompleteDef() {
|
||||
doNoVariantsTest('def a = \new <caret>', 'def', 'final')
|
||||
}
|
||||
|
||||
void testThisInScriptCompletion() {
|
||||
doVariantableTest('''\
|
||||
def foo() {}
|
||||
this.<caret>
|
||||
''', "", CompletionType.BASIC, CompletionResult.contain, 'foo')
|
||||
}
|
||||
}
|
||||
+58
-55
@@ -14,96 +14,99 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.completion
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
|
||||
abstract public class GroovyCompletionTestBase extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
protected void doSmartTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy");
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
checkResult();
|
||||
doCompletionTest(CompletionType.SMART)
|
||||
}
|
||||
|
||||
protected void doBasicTest(String before = null, String after = null) {
|
||||
doCompletionTest(before, after, CompletionType.BASIC)
|
||||
}
|
||||
|
||||
protected void doSmartTest(String before, String after) {
|
||||
myFixture.configureByText('_a.groovy', before)
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
assertNull(myFixture.lookupElements)
|
||||
myFixture.checkResult(after)
|
||||
doCompletionTest(before, after, CompletionType.SMART)
|
||||
}
|
||||
|
||||
protected void checkResult() {
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.groovy", true);
|
||||
}
|
||||
|
||||
protected void doBasicTest(String type = "") {
|
||||
myFixture.testCompletionTyping(getTestName(false) + ".groovy", type, getTestName(false) + "_after.groovy");
|
||||
protected void doCompletionTest(String before = null, String after = null, String type = "", CompletionType ct) {
|
||||
if (before == null) {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy")
|
||||
}
|
||||
else {
|
||||
myFixture.configureByText(getTestName(false) + ".groovy", before)
|
||||
}
|
||||
|
||||
myFixture.complete(ct)
|
||||
type.each { myFixture.type(it) }
|
||||
|
||||
assertNull(myFixture.lookupElements)
|
||||
if (after == null) {
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.groovy", true)
|
||||
}
|
||||
else {
|
||||
myFixture.checkResult(after, true)
|
||||
}
|
||||
}
|
||||
|
||||
protected void doBasicTest(String before, String after) {
|
||||
myFixture.configureByText('_a.groovy', before)
|
||||
myFixture.completeBasic()
|
||||
assertNull(myFixture.lookupElements)
|
||||
myFixture.checkResult(after)
|
||||
protected void doVariantableTest(String before = null, String type = "", CompletionType ct, CompletionResult testType = CompletionResult.equal, String... variants) {
|
||||
if (before == null) {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy")
|
||||
}
|
||||
else {
|
||||
myFixture.configureByText(getTestName(false) + ".groovy", before)
|
||||
}
|
||||
|
||||
myFixture.complete(ct)
|
||||
type.each { myFixture.type(it) }
|
||||
|
||||
assertNotNull(myFixture.lookupElements)
|
||||
|
||||
final actual = myFixture.lookupElementStrings
|
||||
switch (testType) {
|
||||
case CompletionResult.contain:
|
||||
assertTrue(actual.containsAll(variants))
|
||||
break
|
||||
case CompletionResult.equal:
|
||||
assertOrderedEquals(actual, variants)
|
||||
break
|
||||
case CompletionResult.notContain:
|
||||
variants.each {
|
||||
assertFalse(actual.contains(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void doVariantableTest(String... variants) {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy");
|
||||
myFixture.complete(CompletionType.BASIC);
|
||||
assertOrderedEquals(myFixture.lookupElementStrings, variants);
|
||||
doVariantableTest(CompletionType.BASIC, variants)
|
||||
}
|
||||
|
||||
public void doHasVariantsTest(String... variants) {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy");
|
||||
myFixture.complete(CompletionType.BASIC);
|
||||
if (!myFixture.lookupElementStrings.containsAll(variants)) {
|
||||
assertOrderedEquals(myFixture.lookupElementStrings, variants)
|
||||
}
|
||||
doVariantableTest(null, "", CompletionType.BASIC, CompletionResult.contain, variants)
|
||||
}
|
||||
|
||||
public void doSmartCompletion(String... variants) {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy");
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
final List<String> list = myFixture.lookupElementStrings;
|
||||
assertNotNull(list);
|
||||
assertOrderedEquals(list, variants);
|
||||
doVariantableTest(CompletionType.SMART, variants)
|
||||
}
|
||||
|
||||
void doSmartVariantableTest(String before, String... variants) {
|
||||
myFixture.configureByText(getTestName(false) + ".groovy", before);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
final List<String> list = myFixture.lookupElementStrings;
|
||||
assertNotNull(list);
|
||||
assertOrderedEquals(list, variants);
|
||||
}
|
||||
|
||||
|
||||
public void checkCompletion(String before, String type, String after) {
|
||||
myFixture.configureByText("a.groovy", before);
|
||||
myFixture.completeBasic();
|
||||
myFixture.type(type);
|
||||
myFixture.checkResult(after);
|
||||
doCompletionTest(before, after, type, CompletionType.BASIC)
|
||||
}
|
||||
|
||||
public void checkSingleItemCompletion(String before, String after) {
|
||||
myFixture.configureByText("a.groovy", before);
|
||||
assert !myFixture.completeBasic();
|
||||
myFixture.checkResult(after);
|
||||
doCompletionTest(before, after, CompletionType.BASIC)
|
||||
}
|
||||
|
||||
public void doNoVariantsTest(String before, String... excludedVariants) {
|
||||
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, before)
|
||||
myFixture.completeBasic()
|
||||
final excluded = ContainerUtil.newHashSet(excludedVariants)
|
||||
for (String lookup : myFixture.lookupElementStrings) {
|
||||
assertFalse(lookup, excluded.contains(lookup))
|
||||
}
|
||||
doVariantableTest(before, "", CompletionType.BASIC, CompletionResult.notContain, excludedVariants)
|
||||
}
|
||||
|
||||
protected static def caseSensitiveNone() {
|
||||
|
||||
+2
-4
@@ -43,7 +43,7 @@ public class GroovySmartCompletionTest extends GroovyCompletionTestBase {
|
||||
|
||||
public void testSmartAfterNewInCall() throws Throwable { doSmartTest(); }
|
||||
|
||||
public void testInnerClassInStaticMethodCompletion() throws Throwable { doSmartTest(); }
|
||||
public void testInnerClassInStaticMethodCompletion() throws Throwable { doVariantableTest(null, "", CompletionType.SMART, CompletionResult.notContain, 'Inner'); }
|
||||
|
||||
public void testSmartCompletionInAssignmentExpression() throws Throwable { doSmartTest(); }
|
||||
|
||||
@@ -82,9 +82,7 @@ public class GroovySmartCompletionTest extends GroovyCompletionTestBase {
|
||||
public void testEnumMembersInAssignmentInsideEnum() {doSmartCompletion "IN_STOCK", "NOWHERE", "ORDERED", "next", "previous" }
|
||||
|
||||
public void testPreferVarargElement() {
|
||||
doSmartCompletion "Foo", "Foo"
|
||||
myFixture.type('\n')
|
||||
checkResult()
|
||||
doCompletionTest(null, null, '\n', CompletionType.SMART)
|
||||
}
|
||||
|
||||
public void testGlobalStaticMembers() {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
Map<String, Intger> map=["2":2, "3":3];
|
||||
Map<String, Integer> map=["2":2, "3":3];
|
||||
map.each{
|
||||
key, value->
|
||||
key.codePoint<caret>
|
||||
key.codePointA<caret>
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
Map<String, Intger> map=["2":2, "3":3];
|
||||
Map<String, Integer> map=["2":2, "3":3];
|
||||
map.each{
|
||||
key, value->
|
||||
key.codePoint<caret>
|
||||
key.codePointAt(<caret>)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
class StringCategory {
|
||||
static String getMd5(String s) {
|
||||
return "MD5Value";//suppose to be some code that generate md5
|
||||
}
|
||||
}
|
||||
|
||||
class StringCategory2 {
|
||||
static String getMd52(String s) {
|
||||
return "MD5Value";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
use(StringCategory, StringCategory2) {
|
||||
println "hello world".getMd5<caret>
|
||||
}
|
||||
|
||||
Vendored
-10
@@ -1,10 +0,0 @@
|
||||
class A{
|
||||
class Inner {
|
||||
|
||||
}
|
||||
|
||||
static def foo() {
|
||||
Inner i=new
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user