[K/N][Tests] Move some codegen tests to new infra: annotations..coroutines
^KT-61259
This commit is contained in:
committed by
Space Team
parent
a1d13f54cb
commit
a5f3d5b737
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.advanced_when2
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (advanced_when2(10) != 42) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.advanced_when5
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (advanced_when5(5) != 24) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.if_else
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun if_else(b: Boolean): Int {
|
||||
if (b) return 42
|
||||
else return 24
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (if_else(false) != 24) throw Error()
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun when2(i: Int): Int {
|
||||
when (i) {
|
||||
0 -> return 42
|
||||
else -> return 24
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (when2(0) != 42) throw Error()
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when4
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when5
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (when5(2) != 3) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (true) foo() else foo()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
main(emptyArray())
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val b = args.size < 1
|
||||
val x = if (b) Any() else throw Error()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
when (true) {
|
||||
true -> println("true")
|
||||
false -> println("false")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
true
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when9
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(0)
|
||||
println("Ok")
|
||||
}
|
||||
|
||||
fun foo(x: Int) {
|
||||
when (x) {
|
||||
0 -> 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Ok
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when_through
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (when_through(2) != 1) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.branching.when_with_try1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo(Any()))
|
||||
println(foo("zzz"))
|
||||
println(foo("42"))
|
||||
}
|
||||
|
||||
fun foo(value: Any): Int? {
|
||||
if (value is CharSequence) {
|
||||
try {
|
||||
return value.toString().toInt()
|
||||
} catch (e: NumberFormatException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
null
|
||||
null
|
||||
42
|
||||
Reference in New Issue
Block a user