[Tests] Migrate backend-independent tests from native to compiler/testData.
^KT-65979
This commit is contained in:
committed by
Space Team
parent
dd9332d9e1
commit
febac0dd5f
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun advanced_when2(i: Int): Int {
|
||||
var value = 1
|
||||
when (i) {
|
||||
10 -> {val v = 42; value = v}
|
||||
11 -> {val v = 43; value = v}
|
||||
12 -> {val v = 44; value = v}
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = advanced_when2(10)
|
||||
if (res != 42) return "FAIL $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun advanced_when5(i: Int): Int {
|
||||
when (i) {
|
||||
0 -> { val v = 42; return v}
|
||||
1 -> { val v = 42; return v}
|
||||
2 -> { val v = 42; return v}
|
||||
3 -> { val v = 42; return v}
|
||||
4 -> { val v = 42; return v}
|
||||
else -> return 24
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = advanced_when5(5)
|
||||
if (res != 24) return "FAIL $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun if_else(b: Boolean): Int {
|
||||
if (b) return 42
|
||||
else return 24
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = if_else(false)
|
||||
if (res != 24) return "FAIL: $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun when2(i: Int): Int {
|
||||
when (i) {
|
||||
0 -> return 42
|
||||
else -> return 24
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = when2(0)
|
||||
if (res != 42) return "FAIL $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun when5(i: Int): Int {
|
||||
when (i) {
|
||||
0 -> return 42
|
||||
1 -> return 4
|
||||
2 -> return 3
|
||||
3 -> return 2
|
||||
4 -> return 1
|
||||
}
|
||||
return 24
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = when5(5)
|
||||
if (res != 24) return "FAIL $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun when5(i: Int): Int {
|
||||
when (i) {
|
||||
0 -> return 42
|
||||
1 -> return 4
|
||||
2 -> return 3
|
||||
3 -> return 2
|
||||
4 -> return 1
|
||||
else -> return 24
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = when5(2)
|
||||
if (res != 3) return "FAIL $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (true) foo() else foo()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
main(emptyArray())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val b = args.size < 1
|
||||
val x = if (b) Any() else throw Error()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
when (true) {
|
||||
true -> return "OK"
|
||||
false -> return "FAIL"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
foo(0)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun foo(x: Int) {
|
||||
when (x) {
|
||||
0 -> 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun when_through(i: Int): Int {
|
||||
var value = 1
|
||||
when (i) {
|
||||
10 -> value = 42
|
||||
11 -> value = 43
|
||||
12 -> value = 44
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = when_through(2)
|
||||
if (res != 1) return "FAIL $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val res1 = foo(Any())
|
||||
if (res1 != null) return "FAIL 1: $res1"
|
||||
val res2 = foo("zzz")
|
||||
if (res2 != null) return "FAIL 2: $res2"
|
||||
val res3 = foo("42")
|
||||
if (res3 != 42) return "FAIL 3: $res3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun foo(value: Any): Int? {
|
||||
if (value is CharSequence) {
|
||||
try {
|
||||
return value.toString().toInt()
|
||||
} catch (e: NumberFormatException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user