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!!
}
@@ -0,0 +1,19 @@
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
inline fun test(noinline foo: () -> String, noinline bar: () -> String): String {
var vfoo = foo
var vbar = bar
var vres = foo
for (i in 1 .. 4) {
vres = vbar
vbar = vfoo
vfoo = vres
}
return vres()
}
// FILE: 2.kt
fun box(): String =
test({ "OK" }, { "wrong lambda" })
@@ -0,0 +1,25 @@
// FILE: 1.kt
inline fun cycle(p: String): String {
var z = p
var x = z
for (i in 1..4) {
z = x
x = z
}
return z
}
inline fun test(crossinline foo: String.() -> String): String {
val cycle = cycle("123");
{
cycle.foo()
}()
return cycle.foo()
}
// FILE: 2.kt
fun box(): String = test { "OK" }
@@ -0,0 +1,7 @@
// FILE: 1.kt
inline fun alwaysOk(s: String, fn: (String) -> String): String {
return fn(return "OK")
}
// FILE: 2.kt
fun box() = alwaysOk("what?") { it }
@@ -0,0 +1,7 @@
// FILE: 1.kt
inline fun alwaysOk(s: String, fn: (String) -> String): String {
try { return fn(return "fail") } finally { fn(return "OK") }
}
// FILE: 2.kt
fun box() = alwaysOk("what?") { it }
@@ -0,0 +1,15 @@
// FILE: 1.kt
inline fun alwaysOk(s: String, fn: (String) -> String): String {
try {
throw Exception()
}
catch(e: Exception) {
fn(return "fail")
}
finally {
fn(return "OK")
}
}
// FILE: 2.kt
fun box() = alwaysOk("what?") { it }
+1 -1
View File
@@ -20,6 +20,6 @@ minMacOsVersion = 10.11
remoteRoot=konan_tests
#kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-SNAPSHOT
# Download artifacts of https://teamcity.jetbrains.com/viewType.html?buildTypeId=bt345
testDataVersion=1050294:id
testDataVersion=1053418:id
kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-20170426.212805-507
konanVersion=0.1