Some tests for override action has been added.

This commit is contained in:
Sergey Lukjanov
2012-04-04 11:53:48 +04:00
parent 70169409dc
commit 23e368cba4
22 changed files with 268 additions and 25 deletions
@@ -0,0 +1,9 @@
open class Base<A, B, C>() {
open val method : (A?) -> A = { it!! }
open fun foo(value : B) : B = value
open fun bar(value : () -> C) : (String) -> C = { value() }
}
class C : Base<String, C, Unit>() {
<caret>
}
@@ -0,0 +1,16 @@
open class Base<A, B, C>() {
open val method : (A?) -> A = { it!! }
open fun foo(value : B) : B = value
open fun bar(value : () -> C) : (String) -> C = { value() }
}
class C : Base<String, C, Unit>() {
override fun bar(value : () -> Unit) : (String) -> Unit {
return super<Base>.bar(value)
}
override fun foo(value : C) : C {
return super<Base>.foo(value)
}
override val method : (String?) -> String = ?
}
@@ -4,5 +4,5 @@ trait A {
}
fun some() : A {
return object A {<caret>}
}
return object : A {<caret>}
}
@@ -4,7 +4,7 @@ trait A {
}
fun some() : A {
return object A {
return object : A {
override val method : () -> Unit? = ?
}
}
}
@@ -0,0 +1,8 @@
trait A {
fun foo(value : String) : Int = 0
fun bar() : String = "hello"
}
class C : A {
<caret>
}
@@ -0,0 +1,14 @@
trait A {
fun foo(value : String) : Int = 0
fun bar() : String = "hello"
}
class C : A {
override fun bar() : String {
return super<A>.bar()
}
override fun foo(value : String) : Int {
return super<A>.foo(value)
}
}
@@ -0,0 +1,7 @@
open class A() {
open val method : () -> Unit? = {println("hello")}
}
fun some() : A {
return object : A() {<caret>}
}
@@ -0,0 +1,9 @@
open class A() {
open val method : () -> Unit? = {println("hello")}
}
fun some() : A {
return object : A() {
override val method : () -> Unit? = ?
}
}
@@ -0,0 +1,7 @@
trait A<T> {
fun foo(value : T) : Unit = println(value)
}
class C : A<C> {
<caret>
}
@@ -0,0 +1,10 @@
trait A<T> {
fun foo(value : T) : Unit = println(value)
}
class C : A<C> {
override fun foo(value : C) {
super<A>.foo(value)
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2010-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 foo;
class A {
int getAnswer(String[] array, int number, Object value) {
return 42;
}
}
@@ -0,0 +1,5 @@
import foo.A
class C : A() {
<caret>
}
@@ -0,0 +1,8 @@
import foo.A
class C : A() {
override fun getAnswer(array : Array<String?>?, number : Int, value : Any?) : Int {
return super<A>.getAnswer(array, number, value)
}
}
@@ -0,0 +1,7 @@
trait A {
fun foo(value : String) : Int = 0
}
class C : A {
<caret>
}
@@ -0,0 +1,10 @@
trait A {
fun foo(value : String) : Int = 0
}
class C : A {
override fun foo(value : String) : Int {
return super<A>.foo(value)
}
}
@@ -0,0 +1,16 @@
open class A() {
open fun foo(value : Int) : Unit = println(value)
open val bar : Int = 0
}
class C : A() {
val constant = 42
// Some comment
<caret>
/*
Some another comment
*/
fun someAnotherFunction() {
}
}
@@ -0,0 +1,20 @@
open class A() {
open fun foo(value : Int) : Unit = println(value)
open val bar : Int = 0
}
class C : A() {
val constant = 42
// Some comment
override val bar : Int = 0
override fun foo(value : Int) {
super<A>.foo(value)
}
/*
Some another comment
*/
fun someAnotherFunction() {
}
}
@@ -0,0 +1,7 @@
trait A {
fun foo(value : String) : Unit = 0
}
class C : A {
<caret>
}
@@ -0,0 +1,10 @@
trait A {
fun foo(value : String) : Unit = 0
}
class C : A {
override fun foo(value : String) {
super<A>.foo(value)
}
}
@@ -35,6 +35,7 @@ import java.util.Set;
/**
* @author yole
* @author slukjanov aka Frostman
*/
public class OverrideImplementTest extends LightCodeInsightFixtureTestCase {
@NotNull
@@ -50,69 +51,125 @@ public class OverrideImplementTest extends LightCodeInsightFixtureTestCase {
}
public void testFunctionMethod() {
doFileTest();
doImplementFileTest();
}
public void testFunctionProperty() {
doFileTest();
doImplementFileTest();
}
public void testJavaInterfaceMethod() {
doDirectoryTest();
doImplementDirectoryTest();
}
public void testJavaParameters() {
doDirectoryTest();
doImplementDirectoryTest();
}
public void testGenericMethod() {
doFileTest();
doImplementFileTest();
}
public void testProperty() {
doFileTest();
doImplementFileTest();
}
public void testTraitGenericOverride() {
doFileTest();
public void testTraitGenericImplement() {
doImplementFileTest();
}
public void testRespectCaretPosition() {
doMultiFileTest();
doMultiImplementFileTest();
}
public void testGenerateMulti() {
doMultiFileTest();
doMultiImplementFileTest();
}
public void testTraitNullableFunction() {
doFileTest();
doImplementFileTest();
}
private void doFileTest() {
public void testOverrideUnitFunction() {
doOverrideFileTest();
}
public void testOverrideNonUnitFunction() {
doOverrideFileTest();
}
public void testOverrideFunctionProperty() {
doOverrideFileTest();
}
public void testOverrideGenericFunction() {
doOverrideFileTest();
}
public void testMultiOverride() {
doMultiOverrideFileTest();
}
public void testComplexMultiOverride() {
doMultiOverrideFileTest();
}
public void testOverrideRespectCaretPosition() {
doMultiOverrideFileTest();
}
public void testOverrideJavaMethod() {
doOverrideDirectoryTest();
}
private void doImplementFileTest() {
doFileTest(new ImplementMethodsHandler());
}
private void doOverrideFileTest() {
doFileTest(new OverrideMethodsHandler());
}
private void doMultiImplementFileTest() {
doMultiFileTest(new ImplementMethodsHandler());
}
private void doMultiOverrideFileTest() {
doMultiFileTest(new OverrideMethodsHandler());
}
private void doImplementDirectoryTest() {
doDirectoryTest(new ImplementMethodsHandler());
}
private void doOverrideDirectoryTest() {
doDirectoryTest(new OverrideMethodsHandler());
}
private void doFileTest(OverrideImplementMethodsHandler handler) {
myFixture.configureByFile(getTestName(true) + ".kt");
doImplement();
doOverrideImplement(handler);
myFixture.checkResultByFile(getTestName(true) + ".kt.after");
}
private void doMultiFileTest() {
private void doMultiFileTest(OverrideImplementMethodsHandler handler) {
myFixture.configureByFile(getTestName(true) + ".kt");
doMultiImplement();
doMultiOverrideImplement(handler);
myFixture.checkResultByFile(getTestName(true) + ".kt.after");
}
private void doDirectoryTest() {
private void doDirectoryTest(OverrideImplementMethodsHandler handler) {
myFixture.copyDirectoryToProject(getTestName(true), "");
myFixture.configureFromTempProjectFile("foo/Impl.kt");
doImplement();
doOverrideImplement(handler);
myFixture.checkResultByFile(getTestName(true) + "/foo/Impl.kt.after");
}
private void doImplement() {
private void doOverrideImplement(OverrideImplementMethodsHandler handler) {
final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
final JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class);
assertNotNull("Caret should be inside class or object", classOrObject);
final Set<CallableMemberDescriptor> descriptors = new ImplementMethodsHandler().collectMethodsToGenerate(classOrObject);
final Set<CallableMemberDescriptor> descriptors = handler.collectMethodsToGenerate(classOrObject);
assertEquals("Invalid number of available descriptors for override", 1, descriptors.size());
new WriteCommandAction(myFixture.getProject(), myFixture.getFile()) {
@Override
@@ -124,11 +181,11 @@ public class OverrideImplementTest extends LightCodeInsightFixtureTestCase {
}.execute();
}
private void doMultiImplement() {
private void doMultiOverrideImplement(OverrideImplementMethodsHandler handler) {
final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
final JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class);
assertNotNull("Caret should be inside class or object", classOrObject);
final Set<CallableMemberDescriptor> descriptors = new ImplementMethodsHandler().collectMethodsToGenerate(classOrObject);
final Set<CallableMemberDescriptor> descriptors = handler.collectMethodsToGenerate(classOrObject);
final ArrayList<CallableMemberDescriptor> descriptorsList = new ArrayList<CallableMemberDescriptor>(descriptors);
Collections.sort(descriptorsList, new Comparator<CallableMemberDescriptor>() {