ExtractionTest: Change test data layout

This commit is contained in:
Alexey Sedunov
2014-04-10 19:27:32 +04:00
parent 24d8557a5a
commit 4dec0508a6
57 changed files with 218 additions and 282 deletions
@@ -1,9 +1,3 @@
fun f(list: List<String>) {
val value = list[<selection>1 + 2</selection>]
}
/*
fun f(list: List<String>) {
val i = 1 + 2
val value = list[i]
}
*/
}
@@ -0,0 +1,4 @@
fun f(list: List<String>) {
val i = 1 + 2
val value = list[i]
}
@@ -1,9 +1,3 @@
open class A {
val x = <selection>1</selection>
}
/*
open class A {
val i = 1
val x = i
}
*/
}
@@ -0,0 +1,4 @@
open class A {
val i = 1
val x = i
}
@@ -2,13 +2,4 @@ open class A() {
{
do <selection>1</selection> while (true)
}
}
/*
open class A() {
{
do {
val i = 1
} while (true)
}
}
*/
}
@@ -0,0 +1,7 @@
open class A() {
{
do {
val i = 1
} while (true)
}
}
@@ -2,14 +2,4 @@ open class A() {
{
do println(<selection>1</selection>) while (true)
}
}
/*
open class A() {
{
do {
val i = 1
println(i)
} while (true)
}
}
*/
}
@@ -0,0 +1,8 @@
open class A() {
{
do {
val i = 1
println(i)
} while (true)
}
}
@@ -2,12 +2,4 @@ fun a() {
1
1
if (true) <selection>1</selection>
}
/*
fun a() {
val i = 1
i
i
if (true) i
}
*/
}
@@ -0,0 +1,6 @@
fun a() {
val i = 1
i
i
if (true) i
}
@@ -1,6 +1 @@
fun x(): Int = <selection>1</selection>
/*
fun x(): Int {
val i = 1
}
*/
fun x(): Int = <selection>1</selection>
@@ -0,0 +1,3 @@
fun x(): Int {
val i = 1
}
@@ -1,7 +1 @@
fun x(): Int = println(<selection>1</selection>)
/*
fun x(): Int {
val i = 1
println(i)
}
*/
fun x(): Int = println(<selection>1</selection>)
@@ -0,0 +1,4 @@
fun x(): Int {
val i = 1
println(i)
}
@@ -1,9 +1,3 @@
fun foo(c : Collection<String>){
c.filter<selection>{it; false}</selection>
}
/*
fun foo(c : Collection<String>){
val function = { it; false }
c.filter(function)
}
*/
}
@@ -0,0 +1,4 @@
fun foo(c : Collection<String>){
val function = { it; false }
c.filter(function)
}
@@ -4,14 +4,4 @@ class A {
fun apply(x: (A) -> Int) = 2
fun test() {
apply<selection>{it.foo()}</selection>
}
/*
class A {
fun foo() = 1
}
fun apply(x: (A) -> Int) = 2
fun test() {
val function: (A) -> Int = { it.foo() }
apply(function)
}
*/
}
@@ -0,0 +1,8 @@
class A {
fun foo() = 1
}
fun apply(x: (A) -> Int) = 2
fun test() {
val function: (A) -> Int = { it.foo() }
apply(function)
}
@@ -1,11 +1,4 @@
fun a() {
if (<selection>true</selection>) 2
else 1
}
/*
fun a() {
val b = true
if (b) 2
else 1
}
*/
}
@@ -0,0 +1,5 @@
fun a() {
val b = true
if (b) 2
else 1
}
@@ -1,12 +1,4 @@
fun a() {
if (true) 2
else <selection>1</selection>
}
/*
fun a() {
if (true) 2
else {
val i = 1
}
}
*/
}
@@ -0,0 +1,6 @@
fun a() {
if (true) 2
else {
val i = 1
}
}
@@ -1,13 +1,4 @@
fun a() {
if (true) 2
else println(<selection>1</selection>)
}
/*
fun a() {
if (true) 2
else {
val i = 1
println(i)
}
}
*/
}
@@ -0,0 +1,7 @@
fun a() {
if (true) 2
else {
val i = 1
println(i)
}
}
@@ -1,11 +1,4 @@
fun a() {
if (true) <selection>1</selection>
else 2
}
/*
fun a() {
if (true) {
val i = 1
} else 2
}
*/
}
@@ -0,0 +1,5 @@
fun a() {
if (true) {
val i = 1
} else 2
}
@@ -1,12 +1,4 @@
fun a() {
if (true) println(<selection>1</selection>)
else 2
}
/*
fun a() {
if (true) {
val i = 1
println(i)
} else 2
}
*/
}
@@ -0,0 +1,6 @@
fun a() {
if (true) {
val i = 1
println(i)
} else 2
}
@@ -4,13 +4,4 @@ fun b() {
a {
<selection>it</selection>
}
}
/*
fun a(op: (Int) -> Int) {}
fun b() {
a {it}
a {
val i = it
}
}
*/
}
@@ -0,0 +1,7 @@
fun a(op: (Int) -> Int) {}
fun b() {
a {it}
a {
val i = it
}
}
@@ -1,9 +1,3 @@
fun a() {
for (a in <selection>1..2</selection>) {}
}
/*
fun a() {
val intRange = 1..2
for (a in intRange) {}
}
*/
}
@@ -0,0 +1,4 @@
fun a() {
val intRange = 1..2
for (a in intRange) {}
}
@@ -8,18 +8,4 @@ fun a() {
<selection>1</selection>
}
}
}
/*
fun a() {
val i = 1
if (true) {
if (true) {
i
}
} else {
if (true) {
i
}
}
}
*/
}
@@ -0,0 +1,12 @@
fun a() {
val i = 1
if (true) {
if (true) {
i
}
} else {
if (true) {
i
}
}
}
@@ -12,22 +12,4 @@ fun a() {
1
}
}
}
/*
fun a() {
val i = 1
if (true) {
i
}
if (true) {
i
}
if (true) {
i
} else {
if (true) {
i
}
}
}
*/
}
@@ -0,0 +1,16 @@
fun a() {
val i = 1
if (true) {
i
}
if (true) {
i
}
if (true) {
i
} else {
if (true) {
i
}
}
}
@@ -1,11 +1,4 @@
fun a(x: Int) {}
fun b() {
a(<selection>1</selection>)
}
/*
fun a(x: Int) {}
fun b() {
val i = 1
a(i)
}
*/
}
@@ -0,0 +1,5 @@
fun a(x: Int) {}
fun b() {
val i = 1
a(i)
}
@@ -1,8 +1,3 @@
fun a() {
<selection>1</selection>
}
/*
fun a() {
val i = 1
}
*/
}
@@ -0,0 +1,3 @@
fun a() {
val i = 1
}
@@ -1,8 +1,3 @@
fun a() {
<selection>1</selection>
}
/*
fun a() {
val i = 1
}
*/
}
@@ -0,0 +1,3 @@
fun a() {
val i = 1
}
@@ -1,9 +1,3 @@
fun a() {
"it's a number ${<selection>1</selection>}"
}
/*
fun a() {
val i = 1
"it's a number ${i}"
}
*/
}
@@ -0,0 +1,4 @@
fun a() {
val i = 1
"it's a number ${i}"
}
@@ -2,13 +2,4 @@ fun a() {
when (1) {
is 1 -> <selection>2</selection>
}
}
/*
fun a() {
when (1) {
is 1 -> {
val i = 2
}
}
}
*/
}
@@ -0,0 +1,7 @@
fun a() {
when (1) {
is 1 -> {
val i = 2
}
}
}
@@ -2,14 +2,4 @@ fun a() {
when (1) {
is 1 -> println(<selection>2</selection>)
}
}
/*
fun a() {
when (1) {
is 1 -> {
val i = 2
println(i)
}
}
}
*/
}
@@ -0,0 +1,8 @@
fun a() {
when (1) {
is 1 -> {
val i = 2
println(i)
}
}
}
@@ -3,13 +3,4 @@ fun a() {
is 3 -> 1
is 4 -> <selection>1</selection>
}
}
/*
fun a() {
val i = 1
when (i) {
is 3 -> i
is 4 -> i
}
}
*/
}
@@ -0,0 +1,7 @@
fun a() {
val i = 1
when (i) {
is 3 -> i
is 4 -> i
}
}
@@ -2,13 +2,4 @@ open class A() {
{
while (true) <selection>1</selection>
}
}
/*
open class A() {
{
while (true) {
val i = 1
}
}
}
*/
}
@@ -0,0 +1,7 @@
open class A() {
{
while (true) {
val i = 1
}
}
}
@@ -2,14 +2,4 @@ open class A() {
{
while (true) println(<selection>1</selection>)
}
}
/*
open class A() {
{
while (true) {
val i = 1
println(i)
}
}
}
*/
}
@@ -0,0 +1,8 @@
open class A() {
{
while (true) {
val i = 1
println(i)
}
}
}
@@ -1,9 +1,3 @@
fun a() {
while (<selection>true</selection>) {}
}
/*
fun a() {
val b = true
while (b) {}
}
*/
}
@@ -0,0 +1,4 @@
fun a() {
val b = true
while (b) {}
}
@@ -17,16 +17,14 @@
package org.jetbrains.jet.plugin.refactoring.introduce.introduceVariable
import com.intellij.ide.DataManager
import com.intellij.psi.PsiElement
import com.intellij.refactoring.RefactoringActionHandler
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.jet.JetTestCaseBuilder
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.plugin.refactoring.extractFunction.ExtractKotlinFunctionHandler
import java.io.File
import junit.framework.TestCase
import kotlin.test.assertEquals
import org.jetbrains.jet.JetTestUtils
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
public abstract class AbstractJetExtractionTest() : LightCodeInsightFixtureTestCase() {
protected fun doIntroduceVariableTest(path: String) {
@@ -35,33 +33,27 @@ public abstract class AbstractJetExtractionTest() : LightCodeInsightFixtureTestC
protected fun doTest(path: String, handler: RefactoringActionHandler) {
val mainFile = File(path)
val afterFile = File("$path.after")
val conflictFile = File("$path.conflicts")
myFixture.setTestDataPath("${JetTestCaseBuilder.getHomeDirectory()}/${mainFile.getParent()}")
val file = myFixture.configureByFile(mainFile.getName()) as JetFile
val lastChild = file.getLastChild()
assert(lastChild != null)
try {
handler.invoke(
getProject(),
myFixture.getEditor(),
file,
DataManager.getInstance().getDataContext(myFixture.getEditor().getComponent())
)
val expectedResultText =
when (lastChild!!.getNode()!!.getElementType()) {
JetTokens.BLOCK_COMMENT -> {
val lastChildText = lastChild.getText()
lastChildText!!.substring(2, lastChildText.length() - 2).trim()
}
JetTokens.EOL_COMMENT -> {
lastChild.getText()!!.substring(2).trim()
}
else -> null
}
assert(expectedResultText != null)
handler.invoke(
getProject(), myFixture.getEditor(), file, DataManager.getInstance().getDataContext(myFixture.getEditor().getComponent()))
val endOffset = file.getLastChild()!!.getTextRange()!!.getStartOffset()
assertEquals(expectedResultText, file.getText()!!.substring(0, endOffset).trim())
assert(!conflictFile.exists())
JetTestUtils.assertEqualsToFile(afterFile, file.getText()!!)
}
catch(e: Exception) {
val message = if (e is ConflictsInTestsException) e.getMessages().sort().makeString(" ") else e.getMessage()
JetTestUtils.assertEqualsToFile(conflictFile, message?.replace("\n", " ") ?: e.javaClass.getName())
}
}
}