Store refactoring
#KT-1213 Fixed
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
class A(val p: String) {
|
||||
val prop: String = throw RuntimeException()
|
||||
}
|
||||
|
||||
class B(val p: String) {
|
||||
val prop: String = if (p == "test") "OK" else throw RuntimeException()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "fail"
|
||||
try {
|
||||
if (A("test").prop != "OK") return "fail 1"
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
result = "OK"
|
||||
}
|
||||
if (result != "OK") return "fail 1: $result"
|
||||
|
||||
|
||||
if (B("test").prop != "OK") return "fail 2"
|
||||
|
||||
|
||||
result = "fail"
|
||||
try {
|
||||
if (B("fail").prop != "OK") return "fail 3"
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
return "fail"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
class A (val p: String, p1: String, p2: String) {
|
||||
|
||||
var cond1 :String = ""
|
||||
|
||||
var cond2 :String = ""
|
||||
|
||||
val prop: String = if (p == "test") p1 else p2
|
||||
|
||||
val prop1 = if (cond1(p)) p1
|
||||
|
||||
val prop2 = if (cond2(p)) else;
|
||||
|
||||
fun cond1(p: String): Boolean {
|
||||
cond1 = "cond1"
|
||||
return p == "test"
|
||||
}
|
||||
|
||||
fun cond2(p: String): Boolean {
|
||||
cond2 = "cond2"
|
||||
return p == "test"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test", "OK", "fail")
|
||||
|
||||
if (a.prop != "OK") return "fail 1"
|
||||
|
||||
if (a.cond1 != "cond1") return "fail 2"
|
||||
|
||||
if (a.cond2 != "cond2") return "fail 3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Shape(var result: String) {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var a : Shape? = Shape("fail");
|
||||
a?.result = "OK";
|
||||
|
||||
return a!!.result
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
var holder = ""
|
||||
|
||||
var mainShape: Shape? = null
|
||||
|
||||
fun getShape(): Shape? {
|
||||
holder += "getShape1()"
|
||||
mainShape = Shape("fail")
|
||||
return mainShape
|
||||
}
|
||||
|
||||
fun getOK(): String {
|
||||
holder += "->OK"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
class Shape(var result: String) {
|
||||
|
||||
var innerShape: Shape? = null
|
||||
|
||||
fun getShape2(): Shape? {
|
||||
holder += "->getShape2()"
|
||||
innerShape = Shape(result)
|
||||
return innerShape
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
getShape()?.getShape2()?.result = getOK();
|
||||
|
||||
if (holder != "getShape1()->getShape2()->OK") return "fail $holder"
|
||||
|
||||
return mainShape!!.innerShape!!.result
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class C {
|
||||
fun calc() : String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String? {
|
||||
val c: C? = C()
|
||||
val arrayList = array(c?.calc(), "")
|
||||
return arrayList[0]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class A (val p: String) {
|
||||
|
||||
val _kind: String = "$p"
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
if (A("OK")._kind != "OK") return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
val p : Int = try{
|
||||
1
|
||||
} catch(e: Exception) {
|
||||
throw RuntimeException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if (A().p != 1) return "fail 1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class A (val p: String) {
|
||||
|
||||
val _kind: String = when {
|
||||
p == "test" -> "OK"
|
||||
else -> "fail"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
if (A("test")._kind != "OK") return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user