Move some tests from boxWithStdlib/ to box/

Move those tests which do not require neither stdlib nor reflect
This commit is contained in:
Alexander Udalov
2016-03-05 18:39:20 +03:00
committed by Alexander Udalov
parent 54a615fcd3
commit 20e36438e2
217 changed files with 1561 additions and 1397 deletions
@@ -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"
}
+34
View File
@@ -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 else false
val prop2 = if (cond2(p)) true else false
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"
}
+31
View File
@@ -0,0 +1,31 @@
var holder = ""
var globalA: A = A(-1)
get(): A {
holder += "getA"
return field
}
class A(val p: Int) {
var prop = this
operator fun inc(): A {
return A(p+1)
}
}
fun box(): String {
var a = A(1)
++a
if (a.p != 2) return "fail 1: ${a.p} $holder"
globalA = A(1)
++(globalA.prop)
val holderValue = holder;
if (globalA.p != 1 || globalA.prop.p != 2 || holderValue != "getA") return "fail 2: ${a.p} ${a.prop.p} ${holderValue}"
return "OK"
}
@@ -0,0 +1,7 @@
fun box(): String {
if (!(1 < 2)) {
return "fail"
}
return "OK"
}
@@ -0,0 +1,7 @@
fun box(): String {
if (!false) {
return "OK"
} else {
return "fail"
}
}
@@ -0,0 +1,8 @@
fun box(): String {
var p = 2 < 1;
if (!p) {
return "OK"
} else {
return "fail"
}
}
@@ -0,0 +1,8 @@
fun box(): String {
val p = 2 < 1;
if (!!!!!p) {
return "OK"
} else {
return "fail"
}
}
@@ -0,0 +1,9 @@
val p: Int? = 1;
val z: Int? = 2;
fun box(): String {
if (!(p!! == z!!)) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,9 @@
val p: Int? = 1;
val z: Int? = 2;
fun box(): String {
if (!(p!! < z!!)) {
return "fail"
}
return "OK"
}
@@ -0,0 +1,7 @@
fun box(): String {
if (!true) {
return "fail"
} else {
return "OK"
}
}
@@ -0,0 +1,8 @@
fun box(): String {
var p = 1 < 2;
if (!p) {
return "fail"
} else {
return "OK"
}
}
@@ -0,0 +1,28 @@
class A
class B
var holder = 0
operator fun A.not(): A {
holder++
return this;
}
operator fun B.not(): Boolean {
holder++
return false;
}
fun box(): String {
!!!!!A()
if (holder != 5) return "fail 1"
holder = 0;
if (!!!B() || holder != 1) return "fail 2"
if (!B() != false) return "fail 3"
if (!!B() != true) return "fail 4"
return "OK"
}
+10
View File
@@ -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 = arrayOf(c?.calc(), "")
return arrayList[0]
}
+12
View File
@@ -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"
}
+15
View File
@@ -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"
}