tests: Update box tests (1053418:id)

This commit is contained in:
Ilya Matveev
2017-04-27 15:19:22 +07:00
committed by ilmat192
parent 0859abbb9d
commit 55c3b79786
21 changed files with 255 additions and 5 deletions
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
fun equals1(a: Double, b: Double) = a.equals(b)
@@ -0,0 +1,30 @@
//WITH_RUNTIME
class Test {
data class Style(
val color: Int? = null,
val underlined: Boolean? = null,
val separator: String = ""
)
init {
var flag: Boolean? = null
val receiver: String = "123"
try {
receiver.let { a2 ->
flag = false
}
} finally {
receiver.hashCode()
}
val style = Style(null, flag, "123")
}
}
fun box(): String {
Test()
return "OK"
}
@@ -0,0 +1,26 @@
fun returnNullable(): String? = null
inline fun Array<String>.matchAll(fn: (String) -> Unit) {
for (string in this) {
fn(returnNullable() ?: continue)
}
}
fun Array<String>.matchAll2(fn: (String) -> Unit) {
matchAll(fn)
}
inline fun Array<String>.matchAll3(crossinline fn: (String) -> Unit) {
matchAll2 { fn(it) }
}
fun test(a: Array<String>) {
a.matchAll {}
a.matchAll2 {}
a.matchAll3 {}
}
fun box(): String {
test(arrayOf(""))
return "OK"
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun box(): String {
var s = ""
for (c in StringBuilder("OK")) {
s += c
}
return s
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
fun box(): String {
var clist = listOf('1', '2', '3', '4')
var res1 = ""
for (ch in clist) {
res1 += ch
clist = listOf()
}
var s = "1234"
var res2 = ""
for (ch in s) {
res2 += ch
s = ""
}
return if (res1 == res2) "OK" else "'$res1' != '$res2'"
}
@@ -0,0 +1,7 @@
fun zap(s: String): String? = s
inline fun tryZap(s: String, fn: (String) -> String): String {
return fn(zap(s) ?: return "null")
}
fun box() = tryZap("OK") { it }
@@ -0,0 +1,10 @@
fun foo(x: Any?, y: Any?) = 0L
inline fun test(value: Any?): Long {
return foo(null, value ?: return 1L)
}
fun box(): String {
val t = test(null)
return if (t == 1L) "OK" else "fail: t=$t"
}
@@ -0,0 +1,6 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: (String) -> String) =
fn(try { zap(string) } catch (e: Exception) { "" })
fun box(): String = tryZap("OK") { it }
@@ -0,0 +1,9 @@
fun zap(s: String) = s
inline fun tryZap(s1: String, s2: String, fn: (String, String) -> String) =
fn(
try { zap(s1) } catch (e: Exception) { "" },
try { zap(s2) } catch (e: Exception) { "" }
)
fun box(): String = tryZap("O", "K") { a, b -> a + b }
@@ -0,0 +1,9 @@
fun zap(s: String) = s
inline fun tryZap(s1: String, s2: String, fn: String.(String) -> String) =
fn(
try { zap(s1) } catch (e: Exception) { "" },
try { zap(s2) } catch (e: Exception) { "" }
)
fun box(): String = tryZap("O", "K") { this + it }
@@ -0,0 +1,6 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: String.() -> String) =
fn(try { zap(string) } catch (e: Exception) { "" })
fun box(): String = tryZap("OK") { this }
@@ -0,0 +1,13 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: (String) -> String) =
fn(
try {
try {
zap(string)
}
catch (e: Exception) { "" }
} catch (e: Exception) { "" }
)
fun box(): String = tryZap("OK") { it }
@@ -0,0 +1,6 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: (String) -> String) =
fn(try { zap(string) } finally {})
fun box(): String = tryZap("OK") { it }
@@ -0,0 +1,17 @@
fun zap(s: String) = s
inline fun tryZap1(string: String, fn: (String) -> String) =
fn(
try { zap(string) } finally {
try { zap(string) } finally { }
}
)
inline fun tryZap2(string: String, fn: (String) -> String) =
fn(
try { zap(string) } finally {
try { zap(string) } catch (e: Exception) { }
}
)
fun box(): String = tryZap1("O") { it } + tryZap2("K") { it }
@@ -18,8 +18,17 @@ inline fun <reified T> typeLiteral(): TypeLiteral<T> = object : TypeLiteral<T>()
fun box(): String {
assertEquals("java.lang.String", (typeLiteral<String>().type as Class<*>).canonicalName)
assertEquals("java.util.List<?>", typeLiteral<List<*>>().type.toString())
assertEquals("java.lang.String[]", (typeLiteral<Array<String>>().type as Class<*>).canonicalName)
assertEquals("java.lang.Integer[]", (typeLiteral<Array<Int>>().type as Class<*>).canonicalName)
assertEquals("java.lang.String[][]", (typeLiteral<Array<Array<String>>>().type as Class<*>).canonicalName)
//note that 'type' implementation for next cases is different on jdk 6 and 8: GenericArrayType and Class
assertEquals("java.lang.String[]", typeLiteral<Array<String>>().type.canonicalName)
assertEquals("java.lang.Integer[]", typeLiteral<Array<Int>>().type.canonicalName)
assertEquals("java.lang.String[][]", typeLiteral<Array<Array<String>>>().type.canonicalName)
return "OK"
}
}
val Type.canonicalName: String
get() = when (this) {
is Class<*> -> this.canonicalName
is java.lang.reflect.GenericArrayType -> this.getGenericComponentType().canonicalName + "[]"
else -> null!!
}