Extract Function: Add test data

This commit is contained in:
Alexey Sedunov
2014-04-10 20:09:13 +04:00
parent 4dec0508a6
commit 0d90dcf010
111 changed files with 1596 additions and 13 deletions
@@ -0,0 +1,4 @@
fun foo(a: Int): Int {
val b: Int = 1
return <selection>a + b</selection>*a
}
@@ -0,0 +1 @@
Cannot perform refactoring without an expression
@@ -0,0 +1,9 @@
fun foo(a: Int): Int {
val b: Int = 1
val c: Int = 1
<selection>println(a)
println(b)
println</selection>(c)
return a + b*c
}
@@ -0,0 +1 @@
Cannot perform refactoring without an expression
@@ -0,0 +1,11 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>if (a + b > 0) break
println(a - b)
if (a - b > 0) break
println(a + b)</selection>
}
return 1
}
@@ -0,0 +1,16 @@
// NEXT_SIBLING:
fun b(a: Int, b: Int): Boolean {
if (a + b > 0) return true
println(a - b)
if (a - b > 0) return true
println(a + b)
return false
}
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
if (b(a, b)) break
}
return 1
}
@@ -0,0 +1,13 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>if (a + b > 0) break
else {
println(a - b)
if (a - b > 0) break else println(a + b)
}
</selection>
}
return 1
}
@@ -0,0 +1,18 @@
// NEXT_SIBLING:
fun b(a: Int, b: Int): Boolean {
if (a + b > 0) return true
else {
println(a - b)
if (a - b > 0) return true else println(a + b)
}
return false
}
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
if (b(a, b)) break
}
return 1
}
@@ -0,0 +1,12 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>when {
a + b > 0 -> break
a - b > 0 -> break
else -> println(0)
}</selection>
}
return 1
}
@@ -0,0 +1,17 @@
// NEXT_SIBLING:
fun b(a: Int, b: Int): Boolean {
when {
a + b > 0 -> return true
a - b > 0 -> return true
else -> println(0)
}
return false
}
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
if (b(a, b)) break
}
return 1
}
@@ -0,0 +1,7 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>if (a + b > 0) return 0
println(a - b)</selection>
return 1
}
@@ -0,0 +1,12 @@
// NEXT_SIBLING:
fun b(a: Int, b: Int): Boolean {
if (a + b > 0) return true
println(a - b)
return false
}
fun foo(a: Int): Int {
val b: Int = 1
if (b(a, b)) return 0
return 1
}
@@ -0,0 +1,8 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>if (a + b > 0) return 0
else if (a - b < 0) println(a - b)
else println(0)</selection>
return 1
}
@@ -0,0 +1,13 @@
// NEXT_SIBLING:
fun b(a: Int, b: Int): Boolean {
if (a + b > 0) return true
else if (a - b < 0) println(a - b)
else println(0)
return false
}
fun foo(a: Int): Int {
val b: Int = 1
if (b(a, b)) return 0
return 1
}
@@ -0,0 +1,11 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>when (a + b) {
0 -> return 0
1 -> println(1)
else -> println(2)
}
</selection>
return 1
}
@@ -0,0 +1,16 @@
// NEXT_SIBLING:
fun b(a: Int, b: Int): Boolean {
when (a + b) {
0 -> return true
1 -> println(1)
else -> println(2)
}
return false
}
fun foo(a: Int): Int {
val b: Int = 1
if (b(a, b)) return 0
return 1
}
@@ -0,0 +1,10 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>if (a + b > 0) break
println(a - b)
break</selection>
}
return 1
}
@@ -0,0 +1,15 @@
// NEXT_SIBLING:
fun unit(a: Int, b: Int) {
if (a + b > 0) return
println(a - b)
return
}
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
unit(a, b)
break
}
return 1
}
@@ -0,0 +1,12 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>if (a + b > 0) break
else {
println(a - b)
break
}</selection>
}
return 1
}
@@ -0,0 +1,17 @@
// NEXT_SIBLING:
fun unit(a: Int, b: Int) {
if (a + b > 0) return
else {
println(a - b)
return
}
}
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
unit(a, b)
break
}
return 1
}
@@ -0,0 +1,15 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>when {
a + b > 0 -> break
a - b > 0 -> break
else -> {
println(0)
break
}
}</selection>
}
return 1
}
@@ -0,0 +1,20 @@
// NEXT_SIBLING:
fun unit(a: Int, b: Int) {
when {
a + b > 0 -> return
a - b > 0 -> return
else -> {
println(0)
return
}
}
}
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
unit(a, b)
break
}
return 1
}
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun foo(a: Int) {
val b: Int = 1
<selection>if(a > 0) {
println(a)
}
println(b)</selection>
}
@@ -0,0 +1,13 @@
// NEXT_SIBLING:
fun unit(a: Int, b: Int) {
if (a > 0) {
println(a)
}
println(b)
}
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
}
@@ -0,0 +1,12 @@
// NEXT_SIBLING:
fun foo(a: Int) {
val b: Int = 1
<selection>var t = a
while(t > 0) {
if (t == 2) continue
println(t)
if (t == 1) break
t--
}</selection>
}
@@ -0,0 +1,16 @@
// NEXT_SIBLING:
fun unit(a: Int) {
var t = a
while (t > 0) {
if (t == 2) continue
println(t)
if (t == 1) break
t--
}
}
fun foo(a: Int) {
val b: Int = 1
unit(a)
}
@@ -0,0 +1,7 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>if (a + b > 0) return 1
else if (a - b < 0) return 2
else return b</selection>
}
@@ -0,0 +1,11 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
if (a + b > 0) return 1
else if (a - b < 0) return 2
else return b
}
fun foo(a: Int): Int {
val b: Int = 1
return i(a, b)
}
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>when (a + b) {
0 -> return b
1 -> return -b
else -> return a - b
}</selection>
}
@@ -0,0 +1,13 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
when (a + b) {
0 -> return b
1 -> return -b
else -> return a - b
}
}
fun foo(a: Int): Int {
val b: Int = 1
return i(a, b)
}
@@ -0,0 +1,5 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>return a + b</selection>
}
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
return a + b
}
fun foo(a: Int): Int {
val b: Int = 1
return i(a, b)
}
@@ -0,0 +1,5 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return <selection>if (a + b > 0) 1 else if (a - b < 0) 2 else b </selection>
}
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
return if (a + b > 0) 1 else if (a - b < 0) 2 else b
}
fun foo(a: Int): Int {
val b: Int = 1
return i(a, b)
}
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return <selection>when (a + b) {
0 -> b
1 -> -b
else -> a - b
}</selection>
}
@@ -0,0 +1,13 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
return when (a + b) {
0 -> b
1 -> -b
else -> a - b
}
}
fun foo(a: Int): Int {
val b: Int = 1
return i(a, b)
}
@@ -0,0 +1,5 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return <selection>a + b</selection>
}
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
return a + b
}
fun foo(a: Int): Int {
val b: Int = 1
return i(a, b)
}
@@ -0,0 +1,12 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
var c: Int = 1
<selection>b += a
c -= a
println(b)
println(c)</selection>
return b
}
@@ -0,0 +1 @@
Selected code fragment has multiple output values: b c
@@ -0,0 +1,16 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
var c: Int = 1
<selection>if (a > 0) {
b += a
}
else {
c -= a
}
println(b)
println(c)</selection>
return b
}
@@ -0,0 +1 @@
Selected code fragment has multiple output values: b c
@@ -0,0 +1,18 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
var c: Int = 1
<selection>when {
a > 0 -> {
b += a
}
else -> {
c -= a
}
}
println(b)
println(c)</selection>
return b
}
@@ -0,0 +1 @@
Selected code fragment has multiple output values: b c
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection>b += a
println(b)</selection>
return b
}
@@ -0,0 +1,15 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
var b1 = b
b1 += a
println(b1)
return b1
}
fun foo(a: Int): Int {
var b: Int = 1
b = i(a, b)
return b
}
@@ -0,0 +1,11 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection>if (a > 0) {
b = b + 1
}
println(b)</selection>
return b
}
@@ -0,0 +1,17 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
var b1 = b
if (a > 0) {
b1 = b1 + 1
}
println(b1)
return b1
}
fun foo(a: Int): Int {
var b: Int = 1
b = i(a, b)
return b
}
@@ -0,0 +1,17 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection>if (a > 0) {
b = b + 1
}
else if (a < 0) {
b--
}
else {
b = a
}
println(b)</selection>
return b
}
@@ -0,0 +1,21 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
var b1 = b
if (a > 0) {
b1 = b1 + 1
} else if (a < 0) {
b1--
} else {
b1 = a
}
println(b1)
return b1
}
fun foo(a: Int): Int {
var b: Int = 1
b = i(a, b)
return b
}
@@ -0,0 +1,16 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection> when {
a > 0 -> {
b = b + 1
}
a < 0 -> {
b = b - 1
}
}
println(b)</selection>
return b
}
@@ -0,0 +1,22 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
var b1 = b
when {
a > 0 -> {
b1 = b1 + 1
}
a < 0 -> {
b1 = b1 - 1
}
}
println(b1)
return b1
}
fun foo(a: Int): Int {
var b: Int = 1
b = i(a, b)
return b
}
@@ -0,0 +1,19 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection> when {
a > 0 -> {
b = b + 1
}
a < 0 -> {
b = b - 1
}
else -> {
b = a
}
}
println(b)</selection>
return b
}
@@ -0,0 +1,25 @@
// NEXT_SIBLING:
fun i(a: Int, b: Int): Int {
var b1 = b
when {
a > 0 -> {
b1 = b1 + 1
}
a < 0 -> {
b1 = b1 - 1
}
else -> {
b1 = a
}
}
println(b1)
return b1
}
fun foo(a: Int): Int {
var b: Int = 1
b = i(a, b)
return b
}
@@ -0,0 +1,15 @@
trait Callable<T> {
fun call(): T
}
fun foo(a: Int): Int {
// NEXT_SIBLING:
val o = <selection>object: Callable<Int> {
val b: Int = 1
override fun call(): Int {
return a + b
}
}</selection>
return o.call()
}
@@ -0,0 +1 @@
Cannot extract method since following types are not denotable in the target scope: foo.&lt;no name provided&gt;
@@ -0,0 +1,7 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
val t = <selection>if (a > 0) return a else a + b</selection>
return t
}
@@ -0,0 +1 @@
Selected code fragment has multiple exit points
@@ -0,0 +1,7 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
val t = <selection>if (a > 0) throw Exception("") else a + b</selection>
return t
}
@@ -0,0 +1 @@
Selected code fragment has multiple exit points
@@ -0,0 +1,11 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>if (a + b > 0) break
println(a - b)
if (a - b > 0) return 0
println(a + b)</selection>
}
return 1
}
@@ -0,0 +1 @@
Selected code fragment has multiple exit points
@@ -0,0 +1,11 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
<selection>if (a + b > 0) break
println(a - b)
if (a - b > 0) continue
println(a + b)</selection>
}
return 1
}
@@ -0,0 +1 @@
Selected code fragment has multiple exit points
@@ -0,0 +1,10 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
<selection>if (a > 0) return a
if (a < 0) return b
</selection>
return t
}
@@ -0,0 +1 @@
Selected code fragment has multiple exit points
@@ -0,0 +1,15 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
val t = <selection>if (a > 0) {
b += a
b
}
else {
a
}</selection>
println(b)
return t
}
@@ -0,0 +1 @@
Selected code fragment has output values as well as alternative exit points
@@ -0,0 +1,8 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection>b += a
println(b)
return b</selection>
}
@@ -0,0 +1 @@
Selected code fragment has output values as well as alternative exit points
@@ -0,0 +1,9 @@
// NEXT_SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
<selection>if (n == 10) throw Exception("")
b++</selection>
return b
}
@@ -0,0 +1 @@
Selected code fragment has output values as well as alternative exit points
@@ -0,0 +1,6 @@
// NEXT_SIBLING:
fun foo(t: Int): Int {
<selection>val x = t + 1
if (x > 0) return x</selection>
return 0
}
@@ -0,0 +1 @@
Following declarations won't be available outside of extracted function body: x
@@ -0,0 +1,12 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
fun foo(): Int {
<selection>return a + super<Z>@A.z</selection>
}
}
@@ -0,0 +1,15 @@
public open class Z {
fun zzz() {
}
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
fun foo(): Int {
<selection>super.zzz()
return a + 1</selection>
}
}
@@ -0,0 +1 @@
Cannot extract super-call
@@ -0,0 +1,15 @@
public open class Z {
fun zzz() {
}
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
fun foo(): Int {
<selection>super@A.zzz()
return a + 1</selection>
}
}
@@ -0,0 +1,12 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
fun foo(): Int {
<selection>return a + super.z</selection>
}
}
@@ -0,0 +1 @@
Cannot extract super-call
@@ -0,0 +1,16 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return <selection>this@A.a + this@B.b + this@A.z + this@B.z</selection>
}
}
}
@@ -0,0 +1,20 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
fun i(a1: A, b1: A.B): Int {
return a1.a + b1.b + a1.z + b1.z
}
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return i(this@A, this@B)
}
}
}
@@ -0,0 +1,6 @@
class Z(val a: Int)
// NEXT_SIBLING:
fun Z.foo(): Int {
return <selection>this.a</selection> + 1
}
@@ -0,0 +1,10 @@
class Z(val a: Int)
// NEXT_SIBLING:
fun Z.i(): Int {
return a
}
fun Z.foo(): Int {
return i() + 1
}
@@ -0,0 +1,16 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return <selection>a + this.b + this.z</selection>
}
}
}
@@ -0,0 +1,20 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
fun i(a1: A, b1: A.B): Int {
return a1.a + b1.b + b1.z
}
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return i(this@A, this)
}
}
}
@@ -0,0 +1,16 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return <selection>a + b + this@A.z + this@B.z</selection>
}
}
}
@@ -0,0 +1,20 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
fun i(a1: A, b1: A.B): Int {
return a1.a + b1.b + a1.z + b1.z
}
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return i(this@A, this@B)
}
}
}
@@ -0,0 +1,6 @@
class Z(val a: Int)
// NEXT_SIBLING:
fun Z.foo(): Int {
return <selection>this.a + a</selection> + 1
}
@@ -0,0 +1,10 @@
class Z(val a: Int)
// NEXT_SIBLING:
fun Z.i(): Int {
return a + a
}
fun Z.foo(): Int {
return i() + 1
}
@@ -0,0 +1,6 @@
class Z(val a: Int)
// NEXT_SIBLING:
fun Z.foo(): Int {
return <selection>a</selection> + 1
}
@@ -0,0 +1,10 @@
class Z(val a: Int)
// NEXT_SIBLING:
fun Z.i(): Int {
return a
}
fun Z.foo(): Int {
return i() + 1
}
@@ -0,0 +1,16 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return <selection>a + b + z</selection>
}
}
}
@@ -0,0 +1,20 @@
public open class Z {
val z: Int = 0
}
// NEXT_SIBLING:
fun i(a1: A, b1: A.B): Int {
return a1.a + b1.b + b1.z
}
public class A(): Z() {
var a: Int = 1
public inner class B(): Z() {
var b: Int = 1
fun foo(): Int {
return i(this@A, this@B)
}
}
}
@@ -0,0 +1,15 @@
// NEXT_SIBLING:
class MyClass {
fun test(): Int {
<selection>coFun()
return coProp + 10</selection>
}
class object {
val coProp = 1
fun coFun() {
}
}
}
@@ -0,0 +1,19 @@
// NEXT_SIBLING:
fun i(): Int {
MyClass.coFun()
return MyClass.coProp + 10
}
class MyClass {
fun test(): Int {
return i()
}
class object {
val coProp = 1
fun coFun() {
}
}
}
@@ -0,0 +1,19 @@
// NEXT_SIBLING:
class A {
class B {
fun test(): Int {
<selection>coFun()
return coProp + 10</selection>
}
class object {
val coProp = 1
fun coFun() {
}
}
}
}
@@ -0,0 +1,23 @@
// NEXT_SIBLING:
fun i(): Int {
A.B.coFun()
return A.B.coProp + 10
}
class A {
class B {
fun test(): Int {
return i()
}
class object {
val coProp = 1
fun coFun() {
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More