[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,58 @@
|
||||
/*
|
||||
* 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.boxing.box_cache0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun <T> areSame(arg1: T, arg2: T): Boolean {
|
||||
return arg1 === arg2
|
||||
}
|
||||
|
||||
fun Boolean.oneIfTrueElseZero(): Int {
|
||||
return if (this) 1 else 0
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
var acc = 0
|
||||
val range = 1000
|
||||
|
||||
for (i in arrayOf(false, true)) {
|
||||
for (j in arrayOf(false, true)) {
|
||||
acc += areSame(i, j).oneIfTrueElseZero()
|
||||
}
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
|
||||
acc += areSame(i, i).oneIfTrueElseZero()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
|
||||
acc += areSame(i, i).oneIfTrueElseZero()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in 0.toChar()..range.toChar()) {
|
||||
acc += areSame(i, i).oneIfTrueElseZero()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in -range..range) {
|
||||
acc += areSame(i, i).oneIfTrueElseZero()
|
||||
}
|
||||
println(acc)
|
||||
|
||||
acc = 0
|
||||
for (i in -range.toLong()..range.toLong()) {
|
||||
acc += areSame(i, i).oneIfTrueElseZero()
|
||||
}
|
||||
println(acc)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
2
|
||||
256
|
||||
256
|
||||
256
|
||||
256
|
||||
256
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Box<T>(t: T) {
|
||||
var value = t
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val box: Box<Int> = Box<Int>(17)
|
||||
println(box.value)
|
||||
val nonConst = 17
|
||||
val box2: Box<Int> = Box<Int>(nonConst)
|
||||
println(box2.value)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
17
|
||||
17
|
||||
@@ -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.boxing.boxing1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(arg: Any) {
|
||||
println(arg.toString())
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1)
|
||||
foo(2u)
|
||||
foo(false)
|
||||
foo("Hello")
|
||||
val nonConstInt = 1
|
||||
val nonConstUInt = 2u
|
||||
val nonConstBool = false
|
||||
val nonConstString = "Hello"
|
||||
foo(nonConstInt)
|
||||
foo(nonConstUInt)
|
||||
foo(nonConstBool)
|
||||
foo(nonConstString)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
1
|
||||
2
|
||||
false
|
||||
Hello
|
||||
1
|
||||
2
|
||||
false
|
||||
Hello
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing10
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val FALSE: Boolean? = false
|
||||
|
||||
if (FALSE != null) {
|
||||
do {
|
||||
println("Ok")
|
||||
} while (FALSE)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing11
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
|
||||
class Foo(val value: Int?) {
|
||||
fun foo() {
|
||||
printInt(if (value != null) value else 42)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
Foo(17).foo()
|
||||
Foo(null).foo()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
17
|
||||
42
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing12
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(x: Number) {
|
||||
println(x.toByte())
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(18)
|
||||
val nonConst = 18
|
||||
foo(nonConst)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
18
|
||||
18
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing13
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun is42(x: Any?) {
|
||||
println(x == 42)
|
||||
println(42 == x)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
is42(16)
|
||||
is42(42)
|
||||
is42("42")
|
||||
val nonConst16 = 16
|
||||
val nonConst42 = 42
|
||||
val nonConst42String = "42"
|
||||
is42(nonConst16)
|
||||
is42(nonConst42)
|
||||
is42(nonConst42String)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
false
|
||||
false
|
||||
true
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
true
|
||||
false
|
||||
false
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing14
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
42.println()
|
||||
val nonConst = 42
|
||||
nonConst.println()
|
||||
}
|
||||
|
||||
fun <T> T.println() = println(this.toString())
|
||||
@@ -0,0 +1,2 @@
|
||||
42
|
||||
42
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing15
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo(17))
|
||||
val nonConst = 17
|
||||
println(foo(nonConst))
|
||||
}
|
||||
|
||||
fun <T : Int> foo(x: T): Int = x
|
||||
@@ -0,0 +1,2 @@
|
||||
17
|
||||
17
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.boxing.boxing2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
fun printBoolean(x: Boolean) = println(x)
|
||||
fun printUInt(x: UInt) = println(x)
|
||||
|
||||
fun foo(arg: Any) {
|
||||
if (arg is Int)
|
||||
printInt(arg)
|
||||
else if (arg is Boolean)
|
||||
printBoolean(arg)
|
||||
else if (arg is UInt)
|
||||
printUInt(arg)
|
||||
else
|
||||
println("other")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1)
|
||||
foo(2u)
|
||||
foo(true)
|
||||
foo("Hello")
|
||||
val nonConstInt = 1
|
||||
val nonConstUInt = 2u
|
||||
val nonConstBool = true
|
||||
val nonConstString = "Hello"
|
||||
foo(nonConstInt)
|
||||
foo(nonConstUInt)
|
||||
foo(nonConstBool)
|
||||
foo(nonConstString)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
1
|
||||
2
|
||||
true
|
||||
other
|
||||
1
|
||||
2
|
||||
true
|
||||
other
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
|
||||
fun foo(arg: Int?) {
|
||||
if (arg != null)
|
||||
printInt(arg)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(42)
|
||||
val nonConst = 42
|
||||
foo(nonConst)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
42
|
||||
42
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.boxing.boxing4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
|
||||
fun foo(arg: Any?) {
|
||||
if (arg is Int? && arg != null)
|
||||
printInt(arg)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(16)
|
||||
val nonConst = 16
|
||||
foo(nonConst)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
16
|
||||
16
|
||||
@@ -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.boxing.boxing5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
|
||||
fun foo(arg: Int?) {
|
||||
printInt(arg ?: 16)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(null)
|
||||
foo(42)
|
||||
val nonConstNull = null
|
||||
val nonConstInt = 42
|
||||
foo(nonConstNull)
|
||||
foo(nonConstInt)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
16
|
||||
42
|
||||
16
|
||||
42
|
||||
@@ -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.boxing.boxing6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
|
||||
fun foo(arg: Any) {
|
||||
printInt(arg as? Int ?: 16)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(42)
|
||||
foo("Hello")
|
||||
val nonConstInt = 42
|
||||
val nonConstString = "Hello"
|
||||
foo(nonConstInt)
|
||||
foo(nonConstString)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
42
|
||||
16
|
||||
42
|
||||
16
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.boxing.boxing7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun printInt(x: Int) = println(x)
|
||||
|
||||
fun foo(arg: Any) {
|
||||
val argAsInt = try {
|
||||
arg as Int
|
||||
} catch (e: ClassCastException) {
|
||||
0
|
||||
}
|
||||
printInt(argAsInt)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1)
|
||||
foo("Hello")
|
||||
val nonConstInt = 1
|
||||
val nonConstString = "Hello"
|
||||
foo(nonConstInt)
|
||||
foo(nonConstString)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
@@ -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.boxing.boxing8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(vararg args: Any?) {
|
||||
for (arg in args) {
|
||||
println(arg.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo(1, null, true, "Hello")
|
||||
val nonConstInt = 1
|
||||
val nonConstNull = null
|
||||
val nonConstBool = true
|
||||
val nonConstString = "Hello"
|
||||
foo(nonConstInt, nonConstNull, nonConstBool, nonConstString)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
1
|
||||
null
|
||||
true
|
||||
Hello
|
||||
1
|
||||
null
|
||||
true
|
||||
Hello
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.boxing.boxing9
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(vararg args: Any?) {
|
||||
for (arg in args) {
|
||||
println(arg.toString())
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(vararg args: Any?) {
|
||||
foo(1, *args, 2, *args, 3)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
bar(null, true, "Hello")
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
1
|
||||
null
|
||||
true
|
||||
Hello
|
||||
2
|
||||
null
|
||||
true
|
||||
Hello
|
||||
3
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package codegen.boxing.kt53100_casts
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// Reproducer is copied from FloatingPointParser.unaryMinus()
|
||||
inline fun <reified T> unaryMinus(value: T): T {
|
||||
return when (value) {
|
||||
is Float -> -value as T
|
||||
is Double -> -value as T
|
||||
else -> throw NumberFormatException()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest(){
|
||||
println(unaryMinus(0.0))
|
||||
println(unaryMinus(0.0f))
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
-0.0
|
||||
-0.0
|
||||
Reference in New Issue
Block a user