Smart completion handlers tests made generated

This commit is contained in:
Valentin Kipyatkov
2013-12-26 16:17:49 +04:00
parent 39f07b8354
commit 259d9fb891
39 changed files with 285 additions and 38 deletions
@@ -82,6 +82,7 @@ import org.jetbrains.jet.j2k.test.AbstractJavaToKotlinConverterPluginTest
import org.jetbrains.jet.j2k.test.AbstractJavaToKotlinConverterBasicTest
import org.jetbrains.jet.plugin.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest
import org.jetbrains.jet.shortenRefs.AbstractShortenRefsTest
import org.jetbrains.jet.completion.handlers.AbstractSmartCompletionHandlerTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -268,6 +269,10 @@ fun main(args: Array<String>) {
model("completion/basic/custom", recursive = false)
}
testClass(javaClass<AbstractSmartCompletionHandlerTest>()) {
model("completion/handlers/smart")
}
testClass(javaClass<AbstractGotoSuperTest>()) {
model("navigation/gotoSuper", extension = "test")
}
@@ -1,3 +1,5 @@
trait Foo
var a : Foo = <caret>
//ELEMENT: object
@@ -1,3 +1,5 @@
trait Foo
var a : Foo = object: Foo {<caret>}
//ELEMENT: object
@@ -1,3 +1,5 @@
abstract class Foo
var a : Foo = <caret>
//ELEMENT: object
@@ -1,3 +1,5 @@
abstract class Foo
var a : Foo = object: Foo() {<caret>}
//ELEMENT: object
@@ -1 +1,3 @@
var r : Runnable = <caret>
//ELEMENT: object
@@ -3,3 +3,5 @@ var r : Runnable = object: Runnable {
throw UnsupportedOperationException()
}
}
//ELEMENT: object
@@ -1 +1,3 @@
val c: java.io.Closeable = <caret>
val c: java.io.Closeable = <caret>
//ELEMENT: object
@@ -4,4 +4,6 @@ val c: java.io.Closeable = object: Closeable {
override fun close() {
throw UnsupportedOperationException()
}
}
}
//ELEMENT: object
@@ -9,3 +9,5 @@ class K {
fun foo(){
val k : K = <caret>
}
// ELEMENT: K.bar
@@ -9,3 +9,5 @@ class K {
fun foo(){
val k : K = K.bar()<caret>
}
// ELEMENT: K.bar
@@ -9,3 +9,5 @@ class K {
fun foo(){
val k : K = <caret>
}
// ELEMENT: K.bar
@@ -9,3 +9,5 @@ class K {
fun foo(){
val k : K = K.bar(<caret>)
}
// ELEMENT: K.bar
@@ -6,3 +6,5 @@ enum class Foo {
fun foo(){
val f : Foo = <caret>
}
// ELEMENT: Foo.X
@@ -6,3 +6,5 @@ enum class Foo {
fun foo(){
val f : Foo = Foo.X<caret>
}
// ELEMENT: Foo.X
@@ -1,3 +1,5 @@
fun foo(){
val e : java.lang.annotation.ElementType = <caret>
}
// ELEMENT: ElementType.FIELD
@@ -3,3 +3,5 @@ import java.lang.annotation.ElementType
fun foo(){
val e : java.lang.annotation.ElementType = ElementType.FIELD<caret>
}
// ELEMENT: ElementType.FIELD
@@ -3,3 +3,5 @@ import java.util.Locale
fun foo(){
var l : Locale = <caret>
}
// ELEMENT: Locale.ENGLISH
@@ -3,3 +3,5 @@ import java.util.Locale
fun foo(){
var l : Locale = Locale.ENGLISH<caret>
}
// ELEMENT: Locale.ENGLISH
@@ -1,3 +1,5 @@
fun foo(){
var l : java.util.Locale = <caret>
}
// ELEMENT: Locale.ENGLISH
@@ -3,3 +3,5 @@ import java.util.Locale
fun foo(){
var l : java.util.Locale = Locale.ENGLISH<caret>
}
// ELEMENT: Locale.ENGLISH
@@ -1,3 +1,5 @@
fun foo(){
val l : java.lang.Thread = <caret>
}
// ELEMENT: Thread.currentThread
@@ -1,3 +1,5 @@
fun foo(){
val l : java.lang.Thread = Thread.currentThread()<caret>
}
// ELEMENT: Thread.currentThread
@@ -1,3 +1,6 @@
fun foo(){
val l : java.util.Calendar = <caret>
}
// ELEMENT: Calendar.getInstance
// TAIL_TEXT: (TimeZone)
@@ -3,3 +3,6 @@ import java.util.Calendar
fun foo(){
val l : java.util.Calendar = Calendar.getInstance(<caret>)
}
// ELEMENT: Calendar.getInstance
// TAIL_TEXT: (TimeZone)
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(sss: String) {
foo(<caret>x.y())
}
//ELEMENT: sss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(sss: String) {
foo(sss<caret>)
}
//ELEMENT: sss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(sss: String) {
foo(<caret>1 + x)
}
//ELEMENT: sss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(sss: String) {
foo(sss<caret>)
}
//ELEMENT: sss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(sss: String) {
foo(<caret>x().y.z())
}
//ELEMENT: sss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(sss: String) {
foo(sss<caret>)
}
//ELEMENT: sss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(ss: String) {
foo(<caret>xxx)
}
//ELEMENT: ss
//CHAR: \t
@@ -3,3 +3,6 @@ fun foo(s: String){ }
fun bar(ss: String) {
foo(ss<caret>)
}
//ELEMENT: ss
//CHAR: \t
@@ -6,3 +6,6 @@ val c: String = ""
fun bar() {
if (b1 && <caret>b2 && b3) {}
}
//ELEMENT: b3
//CHAR: \t
@@ -6,3 +6,6 @@ val c: String = ""
fun bar() {
if (b1 && b3 && b3) {}
}
//ELEMENT: b3
//CHAR: \t
@@ -32,33 +32,30 @@ import org.junit.Assert
import com.intellij.openapi.application.Result
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
import kotlin.properties.Delegates
import org.jetbrains.jet.InTextDirectivesUtils
abstract class AbstractSmartCompletionHandlerTest() : CompletionHandlerTestBase() {
private val INVOCATION_COUNT_PREFIX = "INVOCATION_COUNT:"
private val LOOKUP_STRING_PREFIX = "ELEMENT:"
private val TAIL_TEXT_PREFIX = "TAIL_TEXT:"
private val COMPLETION_CHAR_PREFIX = "CHAR:"
public class SmartCompletionHandlerTest() : CompletionHandlerTestBase() {
override val completionType: CompletionType = CompletionType.SMART
override val testDataRelativePath: String = "/completion/handlers/smart"
fun testConstructor() = doTest()
fun testConstructorWithParameters() = doTest()
fun testConstructorForNullable() = doTest()
fun testConstructorForJavaClass() = doTest()
fun testConstructorForGenericType() = doTest()
fun testConstructorInsertsImport() = doTest()
fun testConstructorInsertsImport2() = doTest()
fun testJavaStaticMethod() = doTest(1, "Thread.currentThread", null, '\n')
fun testJavaStaticMethodInsertsImport() = doTest(1, "Calendar.getInstance", "(TimeZone)", '\n')
fun testClassObjectMethod1() = doTest(1, "K.bar", null, '\n')
fun testClassObjectMethod2() = doTest(1, "K.bar", null, '\n')
fun testEnumMember() = doTest(1, "Foo.X", null, '\n')
fun testJavaEnumMemberInsertsImport() = doTest(1, "ElementType.FIELD", null, '\n')
fun testJavaStaticField() = doTest(1, "Locale.ENGLISH", null, '\n')
fun testJavaStaticFieldInsertImport() = doTest(1, "Locale.ENGLISH", null, '\n')
fun testTabReplaceIdentifier() = doTest(1, "ss", null, '\t')
fun testTabReplaceExpression() = doTest(1, "sss", null, '\t')
fun testTabReplaceExpression2() = doTest(1, "sss", null, '\t')
fun testTabReplaceExpression3() = doTest(1, "sss", null, '\t')
fun testTabReplaceOperand() = doTest(1, "b3", null, '\t')
fun testAnonymousObject1() = doTest(1, "object", null, '\t')
fun testAnonymousObject2() = doTest(1, "object", null, '\t')
fun testAnonymousObject3() = doTest(1, "object", null, '\t')
fun testAnonymousObjectInsertsImport() = doTest(1, "object", null, '\t')
protected fun doTest(testPath: String) {
fixture.configureByFile(testPath)
val fileText = fixture.getFile()!!.getText()
val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
val completionCharString = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_CHAR_PREFIX)
val completionChar = when(completionCharString) {
"\\n", null -> '\n'
"\\t" -> '\t'
else -> error("Uknown completion char")
}
doTestWithTextLoaded(invocationCount, lookupString, tailText, completionChar)
}
}
@@ -47,8 +47,12 @@ public abstract class CompletionHandlerTestBase() : JetLightCodeInsightFixtureTe
protected fun doTest() : Unit = doTest(2, null, null, '\n')
protected fun doTest(time : Int, lookupString : String?, tailText : String?, completionChar : Char) : Unit {
protected fun doTest(time : Int, lookupString : String?, tailText : String?, completionChar : Char) {
fixture.configureByFile(fileName())
doTestWithTextLoaded(time, lookupString, tailText, completionChar)
}
protected fun doTestWithTextLoaded(time : Int, lookupString : String?, tailText : String?, completionChar : Char) {
if (lookupString != null || tailText != null) {
fixture.complete(completionType, time)
val item = getExistentLookupElement(lookupString, tailText)
@@ -0,0 +1,159 @@
/*
* Copyright 2010-2013 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.jet.completion.handlers;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.completion.handlers.AbstractSmartCompletionHandlerTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/completion/handlers/smart")
public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletionHandlerTest {
public void testAllFilesPresentInSmart() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/completion/handlers/smart"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("AnonymousObject1.kt")
public void testAnonymousObject1() throws Exception {
doTest("idea/testData/completion/handlers/smart/AnonymousObject1.kt");
}
@TestMetadata("AnonymousObject2.kt")
public void testAnonymousObject2() throws Exception {
doTest("idea/testData/completion/handlers/smart/AnonymousObject2.kt");
}
@TestMetadata("AnonymousObject3.kt")
public void testAnonymousObject3() throws Exception {
doTest("idea/testData/completion/handlers/smart/AnonymousObject3.kt");
}
@TestMetadata("AnonymousObjectInsertsImport.kt")
public void testAnonymousObjectInsertsImport() throws Exception {
doTest("idea/testData/completion/handlers/smart/AnonymousObjectInsertsImport.kt");
}
@TestMetadata("ClassObjectMethod1.kt")
public void testClassObjectMethod1() throws Exception {
doTest("idea/testData/completion/handlers/smart/ClassObjectMethod1.kt");
}
@TestMetadata("ClassObjectMethod2.kt")
public void testClassObjectMethod2() throws Exception {
doTest("idea/testData/completion/handlers/smart/ClassObjectMethod2.kt");
}
@TestMetadata("Constructor.kt")
public void testConstructor() throws Exception {
doTest("idea/testData/completion/handlers/smart/Constructor.kt");
}
@TestMetadata("ConstructorForGenericType.kt")
public void testConstructorForGenericType() throws Exception {
doTest("idea/testData/completion/handlers/smart/ConstructorForGenericType.kt");
}
@TestMetadata("ConstructorForJavaClass.kt")
public void testConstructorForJavaClass() throws Exception {
doTest("idea/testData/completion/handlers/smart/ConstructorForJavaClass.kt");
}
@TestMetadata("ConstructorForNullable.kt")
public void testConstructorForNullable() throws Exception {
doTest("idea/testData/completion/handlers/smart/ConstructorForNullable.kt");
}
@TestMetadata("ConstructorInsertsImport.kt")
public void testConstructorInsertsImport() throws Exception {
doTest("idea/testData/completion/handlers/smart/ConstructorInsertsImport.kt");
}
@TestMetadata("ConstructorInsertsImport2.kt")
public void testConstructorInsertsImport2() throws Exception {
doTest("idea/testData/completion/handlers/smart/ConstructorInsertsImport2.kt");
}
@TestMetadata("ConstructorWithParameters.kt")
public void testConstructorWithParameters() throws Exception {
doTest("idea/testData/completion/handlers/smart/ConstructorWithParameters.kt");
}
@TestMetadata("EnumMember.kt")
public void testEnumMember() throws Exception {
doTest("idea/testData/completion/handlers/smart/EnumMember.kt");
}
@TestMetadata("JavaEnumMemberInsertsImport.kt")
public void testJavaEnumMemberInsertsImport() throws Exception {
doTest("idea/testData/completion/handlers/smart/JavaEnumMemberInsertsImport.kt");
}
@TestMetadata("JavaStaticField.kt")
public void testJavaStaticField() throws Exception {
doTest("idea/testData/completion/handlers/smart/JavaStaticField.kt");
}
@TestMetadata("JavaStaticFieldInsertImport.kt")
public void testJavaStaticFieldInsertImport() throws Exception {
doTest("idea/testData/completion/handlers/smart/JavaStaticFieldInsertImport.kt");
}
@TestMetadata("JavaStaticMethod.kt")
public void testJavaStaticMethod() throws Exception {
doTest("idea/testData/completion/handlers/smart/JavaStaticMethod.kt");
}
@TestMetadata("JavaStaticMethodInsertsImport.kt")
public void testJavaStaticMethodInsertsImport() throws Exception {
doTest("idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt");
}
@TestMetadata("TabReplaceExpression.kt")
public void testTabReplaceExpression() throws Exception {
doTest("idea/testData/completion/handlers/smart/TabReplaceExpression.kt");
}
@TestMetadata("TabReplaceExpression2.kt")
public void testTabReplaceExpression2() throws Exception {
doTest("idea/testData/completion/handlers/smart/TabReplaceExpression2.kt");
}
@TestMetadata("TabReplaceExpression3.kt")
public void testTabReplaceExpression3() throws Exception {
doTest("idea/testData/completion/handlers/smart/TabReplaceExpression3.kt");
}
@TestMetadata("TabReplaceIdentifier.kt")
public void testTabReplaceIdentifier() throws Exception {
doTest("idea/testData/completion/handlers/smart/TabReplaceIdentifier.kt");
}
@TestMetadata("TabReplaceOperand.kt")
public void testTabReplaceOperand() throws Exception {
doTest("idea/testData/completion/handlers/smart/TabReplaceOperand.kt");
}
}
@@ -27,19 +27,21 @@ import org.jetbrains.jet.InTextDirectivesUtils;
import java.io.File;
public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsightFixtureTestCase {
LightProjectDescriptor projectDescriptor = null;
LightProjectDescriptor projectDescriptor = JetLightProjectDescriptor.INSTANCE;
@Override
protected void setUp() throws Exception {
String fileText = FileUtil.loadFile(new File(getTestDataPath(), fileName()));
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) {
projectDescriptor = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
}
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "JS")) {
projectDescriptor = JetStdJSProjectDescriptor.INSTANCE;
}
else {
projectDescriptor = JetLightProjectDescriptor.INSTANCE;
if (!getTestName(false).startsWith("AllFilesPresentIn")) {
String fileText = FileUtil.loadFile(new File(getTestDataPath(), fileName()));
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) {
projectDescriptor = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
}
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "JS")) {
projectDescriptor = JetStdJSProjectDescriptor.INSTANCE;
}
else {
projectDescriptor = JetLightProjectDescriptor.INSTANCE;
}
}
super.setUp();