[Tests] Migrate backend-independent tests from native to compiler/testData.

^KT-65979
This commit is contained in:
Vladimir Sukharev
2024-02-25 18:25:58 +01:00
committed by Space Team
parent dd9332d9e1
commit febac0dd5f
640 changed files with 68168 additions and 6313 deletions
@@ -1,22 +0,0 @@
/*
* 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.
*/
// FILE: 1.kt
import kotlin.test.*
@SerialInfo
annotation class Foo(val x: Int, val y: String)
fun box(): String {
val foo = @Suppress("ANNOTATION_CLASS_CONSTRUCTOR_CALL") Foo(42, "OK")
assertEquals(foo.x, 42)
return foo.y
}
// FILE: 2.kt
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class SerialInfo
@@ -1,12 +0,0 @@
import kotlin.test.*
fun box(): String {
assertEquals(97.0, 'a'.toDouble())
assertEquals(-1, Char.MAX_VALUE.toShort())
assertEquals(32768, Short.MIN_VALUE.toChar().toInt())
assertEquals(-1, Char.MAX_VALUE.toByte())
assertEquals(65408, Byte.MIN_VALUE.toChar().toInt())
assertEquals(0, Float.MIN_VALUE.toChar().toInt())
return "OK"
}
@@ -1,20 +0,0 @@
import kotlin.test.*
private fun charCornersMinus(): Int {
val a: Char = 0xFFFF.toChar()
val b: Char = 0.toChar()
return a - b
}
private fun charCornersComparison(): Boolean {
val a = 0xFFFF.toChar()
val b = 0.toChar()
return a < b
}
fun box(): String {
assertEquals(65535, charCornersMinus())
assertFalse(charCornersComparison())
return "OK"
}
@@ -1,8 +0,0 @@
import kotlin.test.*
fun box(): String {
assertEquals(1, 0.compareTo(-0.0f))
assertEquals(0, 0.compareTo(+0.0f))
return "OK"
}
@@ -1,14 +0,0 @@
import kotlin.test.*
fun box(): String {
assertEquals(1, 0f.compareTo(-0f))
assertEquals(1, 0.0.compareTo(-0.0))
assertEquals(1.0, Double.fromBits(1.0.toBits()))
assertEquals(1.0f, Float.fromBits(1.0f.toBits()))
assertEquals(Double.NaN, Double.fromBits((0 / 0.0).toBits()))
assertEquals(Float.NaN, Float.fromBits((0 / 0f).toBits()))
return "OK"
}
@@ -1,17 +0,0 @@
import kotlin.test.*
fun box(): String {
assertEquals(9.223372E18f, Long.MAX_VALUE.toFloat())
assertEquals(-9.223372E18f, Long.MIN_VALUE.toFloat())
assertEquals(-2.147483648E9, Int.MIN_VALUE.toDouble())
assertEquals(2.147483647E9, Int.MAX_VALUE.toDouble())
assertEquals(2147483647, Double.MAX_VALUE.toInt())
assertEquals(0, Float.MIN_VALUE.toLong())
assertEquals(9223372036854775807, Float.MAX_VALUE.toLong())
assertEquals(0, Double.MIN_VALUE.toInt())
return "OK"
}
@@ -1,8 +0,0 @@
import kotlin.test.*
fun box(): String {
val two = 2.0
assertEquals(2, two.toInt())
return "OK"
}
@@ -1,13 +0,0 @@
import kotlin.test.*
// Check that compiler doesn't optimize it to `true`
fun selfCmp1(x: Int) = x + 1 > x
fun selfCmp2(x: Int) = x - 1 < x
fun box(): String {
assertFalse(selfCmp1(Int.MAX_VALUE))
assertFalse(selfCmp2(Int.MIN_VALUE))
return "OK"
}
@@ -1,11 +0,0 @@
import kotlin.test.*
fun box(): String {
assertEquals(-2147483648, 1 shl -1)
assertEquals(0, 1 shr -1)
assertEquals(1, 1 shl 32)
assertEquals(1073741823, -1 ushr 2)
assertEquals(-1, -1 shr 2)
return "OK"
}
@@ -1,7 +0,0 @@
import kotlin.test.*
fun box(): String {
assertEquals(UInt.MAX_VALUE, UInt.MIN_VALUE - 1u)
return "OK"
}
@@ -1,10 +0,0 @@
import kotlin.test.*
fun box(): String {
assertFailsWith(ArithmeticException::class, { 5 / 0 })
assertFailsWith(ArithmeticException::class, { 5 % 0 })
assertEquals(1, 5 / try { 0 / 0; 1 } catch (e: ArithmeticException) { 5 })
assertEquals(Double.NaN, 0.0 / 0.0)
return "OK"
}
@@ -1,25 +0,0 @@
import kotlin.test.*
object RGBA {
fun packFast(r: Int, g: Int, b: Int, a: Int) = (r shl 0) or (g shl 8) or (b shl 16) or (a shl 24)
fun getFastR(v: Int): Int = (v ushr 0) and 0xFF
fun getFastG(v: Int): Int = (v ushr 8) and 0xFF
fun getFastB(v: Int): Int = (v ushr 16) and 0xFF
fun getFastA(v: Int): Int = (v ushr 24) and 0xFF
fun premultiplyFastInt(v: Int): Int {
val A = getFastA(v) + 1
val RB = (((v and 0x00FF00FF) * A) ushr 8) and 0x00FF00FF
val G = (((v and 0x0000FF00) * A) ushr 8) and 0x0000FF00
return (v and 0x00FFFFFF.inv()) or RB or G
}
}
fun box(): String {
val source = listOf(0xFFFFFFFF.toInt(), 0xFFFFFF77.toInt(), 0x777777FF.toInt(), 0x77777777.toInt())
val expect = listOf(-1, -137, 2000107383, 2000107319)
assertEquals(expect, source.map { RGBA.premultiplyFastInt(it) })
return "OK"
}
@@ -1,16 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
foo().hashCode()
return "OK"
}
fun foo(): Any {
return Array<Any?>(0, { i -> null })
}
@@ -1,41 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
interface I<U, T> {
fun foo(a: U): T
fun qux(a: T): U
}
//-----------------------------------------------------------------------------//
class A1
class A2
//-----------------------------------------------------------------------------//
class A : I<A1, A2> {
override fun foo(a: A1): A2 { sb.appendLine("A:foo"); return A2() }
override fun qux(a: A2): A1 { sb.appendLine("A:qux"); return A1() }
}
//-----------------------------------------------------------------------------//
fun <U, V> baz(i: I<U, V>, u: U, v:V) {
i.foo(u)
i.qux(v)
}
//-----------------------------------------------------------------------------//
fun box(): String {
baz<A1, A2>(A(), A1(), A2())
assertEquals("A:foo\nA:qux\n", sb.toString())
return "OK"
}
@@ -1,55 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
testCast(null, false)
testCastToNullable(null, true)
testCastToNullable(TestKlass(), true)
testCastToNullable("", false)
testCastNotNullableToNullable(TestKlass(), true)
testCastNotNullableToNullable("", false)
return "OK"
}
class TestKlass
fun ensure(b: Boolean) {
if (!b) {
throw Error("Error")
}
}
fun testCast(x: Any?, expectSuccess: Boolean) {
try {
x as TestKlass
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun testCastToNullable(x: Any?, expectSuccess: Boolean) {
try {
x as TestKlass?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun testCastNotNullableToNullable(x: Any, expectSuccess: Boolean) {
try {
x as TestKlass?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
@@ -1,23 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
open class A() {}
class B(): A() {}
fun castSimple(o: Any) : A = o as A
fun castTest(): Boolean {
val b = B()
castSimple(b)
return true
}
fun box(): String {
if (!castTest()) throw Error()
return "OK"
}
@@ -1,46 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
interface I
class A() : I {}
class B() {}
//-----------------------------------------------------------------------------//
fun isTypeOf(a: Any?) : Boolean {
return a is A
}
//-----------------------------------------------------------------------------//
fun isTypeNullableOf(a: Any?) : Boolean {
return a is A?
}
//-----------------------------------------------------------------------------//
fun isNotTypeOf(a: Any) : Boolean {
return a !is A
}
//-----------------------------------------------------------------------------//
fun isTypeOfInterface(a: Any) : Boolean {
return a is I
}
//-----------------------------------------------------------------------------//
fun box(): String {
if (!isTypeOf(A())) return "FAIL !isTypeOf(A())"
if (isTypeOf(null)) return "FAIL isTypeOf(null)"
if (!isTypeNullableOf(A())) return "FAIL !isTypeNullableOf(A())"
if (!isTypeNullableOf(null)) return "FAIL !isTypeNullableOf(null)"
if (!isNotTypeOf(B())) return "FAIL !isNotTypeOf(B())"
if (!isTypeOfInterface(A())) return "FAIL !isTypeOfInterface(A())"
return "OK"
}
@@ -1,12 +0,0 @@
/*
* 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.
*/
class A {
companion object {
fun foo() = "OK"
}
}
fun box() = A.foo()
@@ -1,19 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
val s = "world"
val i = 1
val res1 = "Hello $s $i ${2 * i}"
if (res1 != "Hello world 1 2") return "FAIL 1: $res1"
val a = "a"
val res2 = "Hello, $a"
if (res2 != "Hello, a") return "FAIL 2: $res2"
return "OK"
}
@@ -1,20 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
//Original issue here https://youtrack.jetbrains.com/issue/KT-37212
@Suppress("DIVISION_BY_ZERO")
const val fpInfConst = 1.0F / 0.0F
@Suppress("DIVISION_BY_ZERO")
val fpInfVal = 1.0F / 0.0F
fun box(): String {
assertEquals(fpInfConst, Float.POSITIVE_INFINITY)
assertEquals(fpInfVal, Float.POSITIVE_INFINITY)
assertEquals(fpInfConst, fpInfVal)
return "OK"
}
@@ -1,20 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun foo() {
Any() as String
}
fun box(): String {
try {
foo()
} catch (e: Throwable) {
return "OK"
}
return "Fail"
}
-36
View File
@@ -1,36 +0,0 @@
import kotlin.test.*
fun box(): String {
assertTrue(Reproducer().repro() > 0)
return "OK"
}
// Based on https://youtrack.jetbrains.com/issue/KT-42000#focus=Comments-27-4404934.0-0
val Int.isEven get() = this % 2 == 0
inline operator fun <reified T : Number> T.plus(other: T): T = when (T::class) {
Double::class -> (this as Double) + (other as Double)
Int::class -> (this as Int) + (other as Int)
Long::class -> (this as Long) + (other as Long)
else -> TODO()
} as T
inline fun <reified T : Number> Collection<T>.median(): Double {
val sorted = this.sortedBy {
it.toDouble()
}
return if (size.isEven || size == 1) {
sorted[size / 2]
} else {
sorted[size / 2] + sorted[size / 2 + 1]
}.toDouble()
}
class Reproducer {
private var someListOfLongs = mutableListOf<Long>(1L)
fun repro() = someListOfLongs.median()
}
-13
View File
@@ -1,13 +0,0 @@
import kotlin.test.*
// https://youtrack.jetbrains.com/issue/KT-42000
fun box(): String {
assertFailsWith<Error> {
when (1) {
else -> throw Error()
} as String
}
return "OK"
}
@@ -1,17 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun local_variable(a: Int) : Int {
var b = 0
b = a + 11
return b
}
fun box(): String {
if (local_variable(3) != 14) throw Error()
return "OK"
}
@@ -1,39 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
//--- Test "eqeq" -------------------------------------------------------------//
fun check_eqeq(a: Any?) = a == null
fun null_check_eqeq1() : Boolean {
return check_eqeq(Any())
}
fun null_check_eqeq2() : Boolean {
return check_eqeq(null)
}
//--- Test "eqeqeq" -----------------------------------------------------------//
fun check_eqeqeq(a: Any?) = a === null
fun null_check_eqeqeq1() : Boolean {
return check_eqeqeq(Any())
}
fun null_check_eqeqeq2() : Boolean {
return check_eqeqeq(null)
}
fun box(): String {
if (null_check_eqeq1()) return "FAIL null_check_eqeq1()"
if (!null_check_eqeq2()) return "FAIL !null_check_eqeq2()"
if (null_check_eqeqeq1()) return "FAIL null_check_eqeqeq1()"
if (!null_check_eqeqeq2()) return "FAIL !null_check_eqeqeq2()"
return "OK"
}
@@ -1,31 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
open class A
class B : A()
class C
fun foo(a: Any) : A? = a as? A
fun safe_cast_positive(): Boolean {
val b = B()
return foo(b) === b
}
fun safe_cast_negative(): Boolean {
val c = C()
return foo(c) == null
}
fun box(): String {
val safeCastPositive = safe_cast_positive().toString()
val safeCastNegative = safe_cast_negative().toString()
if (safeCastPositive != "true") return "FAIL safeCastPositive"
if (safeCastNegative != "true") return "FAIL safeCastNegative"
return "OK"
}
@@ -1,23 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
val list0 = _arrayOf("K", "o", "t", "l", "i", "n")
val list1 = _arrayOf("l", "a","n", "g", "u", "a", "g", "e")
val list = foo(list0, list1)
val expected = listOf("K", "o", "t", "l", "i", "n", " ", "i", "s", " ", "c", "o", "o", "l", " ", "l", "a", "n", "g", "u", "a", "g", "e")
if (list != expected)
return "FAIL: $list"
return "OK"
}
fun foo(a:Array<out String>, b:Array<out String>) = listOf(*a," ", "i", "s", " ", "c", "o", "o", "l", " ", *b)
fun _arrayOf(vararg arg:String) = arg
@@ -1,45 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun simple() {
var a = 238
a++
sb.appendLine(a)
--a
sb.appendLine(a)
}
class Foo() {
val j = 2
var i = 29
fun more() {
i++
}
fun less() {
--i
}
}
fun fields() {
val foo = Foo()
foo.more()
sb.appendLine(foo.i)
foo.less()
sb.appendLine(foo.i)
}
fun box(): String {
simple()
fields()
assertEquals("239\n238\n30\n29\n", sb.toString())
return "OK"
}
@@ -1,30 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
open class C {
open fun f() = "<fun:C>"
}
class C1: C() {
override fun f() = super<C>.f() + "<fun:C1>"
}
open class C2: C() {
}
class C3: C2() {
override fun f() = super<C2>.f() + "<fun:C3>"
}
fun box(): String {
val c1f = C1().f()
if (c1f != "<fun:C><fun:C1>") return "FAIL 1: $c1f"
val c3f = C3().f()
if (c3f != "<fun:C><fun:C3>") return "FAIL 2: $c3f"
return "OK"
}
@@ -1,30 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
open class C {
open val p1 = "<prop:C>"
}
class C1: C() {
override val p1 = super<C>.p1 + "<prop:C1>"
}
open class C2: C() {
}
class C3: C2() {
override val p1 = super<C2>.p1 + "<prop:C3>"
}
fun box(): String {
val c1p1 = C1().p1
if (c1p1 != "<prop:C><prop:C1>") return "FAIL 1: $c1p1"
val c3p1 = C3().p1
if (c3p1 != "<prop:C><prop:C3>") return "FAIl 2: $c3p1"
return "OK"
}
@@ -1,43 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
open class C {
open var p2 = "<prop:C>"
set(value) { field = "<prop:C>" + value }
}
class C1: C() {
override var p2 = super<C>.p2 + "<prop:C1>"
set(value) {
super<C>.p2 = value
field = "<prop:C1>" + super<C>.p2
}
}
open class C2: C() {
}
class C3: C2() {
override var p2 = super<C2>.p2 + "<prop:C3>"
set(value) {
super<C2>.p2 = value
field = "<prop:C3>" + super<C2>.p2
}
}
fun box(): String {
val c1 = C1()
val c3 = C3()
c1.p2 = "zzz"
c3.p2 = "zzz"
val c1p2 = c1.p2
if (c1p2 != "<prop:C1><prop:C>zzz") return "FAIL 1: "
val c3p2 = c3.p2
if (c3p2 != "<prop:C3><prop:C>zzz") return "FAIL 2: "
return "OK"
}
@@ -1,15 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
val x = Bar(42).x
if (x != 42 ) return "FAIL: $x"
return "OK"
}
class Foo(val x: Int)
typealias Bar = Foo
@@ -1,28 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
foo<String>("17")
bar<String>("17")
foo<String>(42)
bar<String>(42)
assertEquals("17\n17\n42\n42\n", sb.toString())
return "OK"
}
fun <T> foo(x: Any?) {
val y = x as T
sb.appendLine(y.toString())
}
fun <T> bar(x: Any?) {
val y = x as? T
sb.appendLine(y.toString())
}
@@ -1,18 +0,0 @@
/*
* 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.
*/
// IGNORE_BACKEND: NATIVE
import kotlin.test.*
fun box(): String {
try {
val x = cast<String>(Any())
return "FAIL: ${x.length}"
} catch (e: Throwable) {
return "OK"
}
}
fun <T> cast(x: Any?) = x as T
@@ -1,42 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
testCast<TestKlass>(TestKlass(), true)
testCast<TestKlass>(null, false)
testCastToNullable<TestKlass>(null, true)
return "OK"
}
class TestKlass
fun ensure(b: Boolean) {
if (!b) {
println("Error")
}
}
fun <T : Any> testCast(x: Any?, expectSuccess: Boolean) {
try {
x as T
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun <T : Any> testCastToNullable(x: Any?, expectSuccess: Boolean) {
try {
x as T?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
@@ -1,28 +0,0 @@
/*
* Copyright 2010-2019 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.
*/
import kotlin.test.*
fun box(): String {
CI1I2().uncheckedCast<CI1I2>()
CI1I2().uncheckedCast<OtherCI1I2>()
assertFailsWith<ClassCastException> {
Any().uncheckedCast<CI1I2>()
}
return "OK"
}
fun <R : C> Any?.uncheckedCast() where R : I1, R : I2 {
this as R
}
interface I1
interface I2
open class C
class CI1I2 : C(), I1, I2
class OtherCI1I2 : C(), I1, I2
-10
View File
@@ -1,10 +0,0 @@
/*
* 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.
*/
fun box(): String {
val unit = println("First")
if (unit.toString() != "kotlin.Unit") return "FAIL 1: $unit"
return "OK"
}
-14
View File
@@ -1,14 +0,0 @@
/*
* 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.
*/
fun box(): String {
val x = foo()
if (x.toString() != "kotlin.Unit") return "FAIL: $x"
return "OK"
}
fun foo() {
return Unit
}
-14
View File
@@ -1,14 +0,0 @@
/*
* 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.
*/
fun box(): String {
val actual = foo(Unit)
if (actual != "kotlin.Unit") return "FAIL: $actual"
return "OK"
}
fun foo(x: Any): String {
return x.toString()
}
-42
View File
@@ -1,42 +0,0 @@
/*
* 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.
*/
fun box(): String {
for (x in 0 .. 8) {
foo(x, Unit)
}
return "OK"
}
var global = 42
fun foo(x: Int, unit: Unit) {
var local = 5
val y: Unit = when (x) {
0 -> {}
1 -> local = 6
2 -> global = 43
3 -> unit
4 -> Unit
5 -> bar()
6 -> return
7 -> {
5
bar()
}
8 -> {
val z: Any = Unit
z as Unit
}
else -> throw Error()
}
if (y !== Unit) {
throw Error("Fail at x = $x")
}
}
fun bar() {
}
-89
View File
@@ -1,89 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun foo(a: Int, b : Int): Int = a + b * 2
fun box(): String {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var length = array.size - 1
var sum = 0
array.forEach {
sum += it
}
for (i in array.indices) {
array[i] = 6
}
for (i in 0 until array.size) {
array[i] = 7
}
for (i in array.size - 1 downTo 1) {
array[i] = 7
}
for (it in array) {
sum += it
}
for (i in 0..array.size - 1 step 2) {
array[i] = 7
}
for (i in 0 until array.size step 2) {
array[i] = 7
}
for (i in array.indices step 2) {
array[i] = 6
}
for (i in array.size - 1 downTo 1 step 2) {
array[i] = 7
}
for ((index, value) in array.withIndex()) {
array[index] = 8
}
for ((i, v) in (0..array.size - 1 step 2).withIndex()) {
array[v] = 8
array[i] = 6
}
for (i in array.reversed()) {
sum += i
}
for (i in (0..array.size-1).reversed()) {
array [i] = 10
}
for (i in 0 until array.size) {
array[i] = 7
for (j in 0 until array1.size) {
array1[j] = array[i]
}
}
val size = array.size - 1
val size1 = size
for (i in 0..size1) {
foo(array[i], array[i])
}
for (i in 0..array.size - 2) {
array[i+1] = array[i]
}
if (array.toList() != listOf(7, 7, 7, 7, 7, 7, 7, 7, 7, 7)) return "FAIL 1: ${array.toList()}"
if (array1.toList() != listOf(7, 7, 7)) return "FAIL 2: ${array1.toList()}"
return "OK"
}
@@ -1,22 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
var needSmallArray = true
val array: Array<Int> = arrayOf(1)
get() = if (needSmallArray) field else arrayOf(1, 2, 3)
fun box(): String {
val a = array
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until array.size) {
a[index] = 6
}
}
return "OK"
}
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
import kotlin.reflect.KProperty
var needSmallArray = true
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Array<Int> {
return if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
}
class WithDelegates {
val array by Delegate()
}
fun box(): String {
val obj = WithDelegates()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
return "OK"
}
@@ -1,28 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
class Foo(size: Int) {
val array = IntArray(size)
}
class Bar {
val smallFoo = Foo(1)
val largeFoo = Foo(10)
val smallArray = smallFoo.array
val largeArray = largeFoo.array
}
fun box(): String {
val bar = Bar()
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until bar.largeArray.size) {
bar.smallArray[index] = 6
}
}
return "OK"
}
@@ -1,29 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
class First(initArray: Array<Int>) {
val array = initArray
}
class Second(initArray: Array<Int>){
val first = First(initArray)
}
class Third(initArray: Array<Int>) {
val second = Second(initArray)
}
fun box(): String {
val a = Third(arrayOf(1, 2, 3, 4, 5))
val b = Third(arrayOf(1, 2))
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..a.second.first.array.size-1) {
b.second.first.array[i] = 6
}
}
return "OK"
}
@@ -1,59 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[i * 2] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array1[i] = 6
}
}
var a = array.size - 1
val b = ++a
val c = b
assertFailsWith<IndexOutOfBoundsException> {
for (i in c downTo 0) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size + 1 downTo 0) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 0) {
array[i] = 6
}
}
return "OK"
}
@@ -1,49 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = UIntArray(10) { 0U }
val array1 = UIntArray(3) { 0U }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0 step 2) {
array[j] = 6U
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array[i + 1] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array1[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size / 0.2).toInt() downTo 1 step 2) {
array[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -3 step 2) {
array[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 1 step 2) {
array[i] = 6U
}
}
return "OK"
}
@@ -1,16 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0 }
assertFailsWith<IndexOutOfBoundsException> {
array.forEachIndexed { index, _ ->
array[index + 1] = 1
}
}
return "OK"
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0 }
val array1 = Array(3) { 0 }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[i + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array1[i] = 6
}
}
return "OK"
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array1[i] = 6
}
}
return "OK"
}
@@ -1,57 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[j] = 6
j++
}
}
var length = array.size - 1
length = 2 * length
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..length) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[i + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size) {
array[i] = 6
}
}
return "OK"
}
@@ -1,49 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1 step 2) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1 step 2) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size step 2) {
array[i] = 6
}
}
return "OK"
}
-38
View File
@@ -1,38 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size-1).reversed()) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0 until array.size).reversed()) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size).reversed()) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size downTo 0).reversed()) {
array[i] = 6
}
}
return "OK"
}
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size + 10) {
array[i] = 6
}
}
return "OK"
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = CharArray(10) { '0' }
val array1 = CharArray(3) { '0' }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[j] = '6'
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[i + 3] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array1[i] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until (array.size/0.5).toInt() step 2) {
array[i] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -array.size until array.size step 2) {
array[i] = '6'
}
}
return "OK"
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
fun box(): String {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[index + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[value] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size + 30 step 2).withIndex()) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size).withIndex()) {
array[v] = 8
}
}
return "OK"
}
-62
View File
@@ -1,62 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.reflect.KProperty
import kotlin.test.*
var needSmallArray = true
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Array<Int> {
return if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
}
open class Base {
open val array = Array(10) { 100 }
val array1 by Delegate()
}
class Child : Base() {
override val array: Array<Int>
get() = if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
fun box(): String {
val obj = Child()
val base = Base()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array1.size-1) {
needSmallArray = true
obj.array1[i] = 6
needSmallArray = false
}
}
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
base.array[i] = 6
needSmallArray = false
}
}
return "OK"
}
-29
View File
@@ -1,29 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
import kotlin.test.*
var needSmallArray = true
class WithGetter() {
val array: Array<Int>
get() = if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
fun box(): String {
val obj = WithGetter()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
return "OK"
}
@@ -1,58 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun <T> areSame(arg1: T, arg2: T): Boolean {
return arg1 === arg2
}
fun Boolean.oneIfTrueElseZero(): Int {
return if (this) 1 else 0
}
fun box(): String {
var acc = 0
val range = 1000
for (i in arrayOf(false, true)) {
for (j in arrayOf(false, true)) {
acc += areSame(i, j).oneIfTrueElseZero()
}
}
if (acc != 2) "FAIL 1: $acc"
acc = 0
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 2: $acc"
acc = 0
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 3: $acc"
acc = 0
for (i in 0.toChar()..range.toChar()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 4: $acc"
acc = 0
for (i in -range..range) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 5: $acc"
acc = 0
for (i in -range.toLong()..range.toLong()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 6: $acc"
return "OK"
}
-22
View File
@@ -1,22 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
class Box<T>(t: T) {
var value = t
}
fun box(): String {
val box: Box<Int> = Box<Int>(17)
if (box.value != 17) return "FAIL 1: ${box.value}"
val nonConst = 17
val box2: Box<Int> = Box<Int>(nonConst)
if (box2.value != 17) return "FAIL 1: ${box2.value}"
return "OK"
}
-40
View File
@@ -1,40 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun foo(arg: Any) {
sb.appendLine(arg.toString())
}
fun box(): String {
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)
assertEquals("""
1
2
false
Hello
1
2
false
Hello
""".trimIndent(), sb.toString())
return "OK"
}
-17
View File
@@ -1,17 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
val FALSE: Boolean? = false
if (FALSE != null) {
do {
return "OK"
} while (FALSE)
}
return "FAIL"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
class Foo(val value: Int?) {
fun foo() {
printInt(if (value != null) value else 42)
}
}
fun box(): String {
Foo(17).foo()
Foo(null).foo()
assertEquals("17\n42\n", sb.toString())
return "OK"
}
-21
View File
@@ -1,21 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun foo(x: Number) {
sb.appendLine(x.toByte())
}
fun box(): String {
foo(18)
val nonConst = 18
foo(nonConst)
assertEquals("18\n18\n", sb.toString())
return "OK"
}
-42
View File
@@ -1,42 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun is42(x: Any?) {
sb.appendLine(x == 42)
sb.appendLine(42 == x)
}
fun box(): String {
is42(16)
is42(42)
is42("42")
val nonConst16 = 16
val nonConst42 = 42
val nonConst42String = "42"
is42(nonConst16)
is42(nonConst42)
is42(nonConst42String)
assertEquals("""
false
false
true
true
false
false
false
false
true
true
false
false
""".trimIndent(), sb.toString())
return "OK"
}
-19
View File
@@ -1,19 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
42.println()
val nonConst = 42
nonConst.println()
assertEquals("42\n42\n", sb.toString())
return "OK"
}
fun <T> T.println() = sb.appendLine(this)
-19
View File
@@ -1,19 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
val res1 = foo(17)
if (res1 != 17) return "FAIL 1: $res1"
val nonConst = 17
val res2 = foo(nonConst)
if (res2 != 17) return "FAIL 2: $res2"
return "OK"
}
fun <T : Int> foo(x: T): Int = x
-51
View File
@@ -1,51 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x.toString())
fun printBoolean(x: Boolean) = sb.appendLine(x.toString())
fun printUInt(x: UInt) = sb.appendLine(x.toString())
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
sb.appendLine("other")
}
fun box(): String {
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)
assertEquals("""
1
2
true
other
1
2
true
other
""".trimIndent(), sb.toString())
return "OK"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Int?) {
if (arg != null)
printInt(arg)
}
fun box(): String {
foo(42)
val nonConst = 42
foo(nonConst)
assertEquals("42\n42\n", sb.toString())
return "OK"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any?) {
if (arg is Int? && arg != null)
printInt(arg)
}
fun box(): String {
foo(16)
val nonConst = 16
foo(nonConst)
assertEquals("16\n16\n", sb.toString())
return "OK"
}
-26
View File
@@ -1,26 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Int?) {
printInt(arg ?: 16)
}
fun box(): String {
foo(null)
foo(42)
val nonConstNull = null
val nonConstInt = 42
foo(nonConstNull)
foo(nonConstInt)
assertEquals("16\n42\n16\n42\n", sb.toString())
return "OK"
}
-26
View File
@@ -1,26 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any) {
printInt(arg as? Int ?: 16)
}
fun box(): String {
foo(42)
foo("Hello")
val nonConstInt = 42
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
assertEquals("42\n16\n42\n16\n", sb.toString())
return "OK"
}
-31
View File
@@ -1,31 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any) {
val argAsInt = try {
arg as Int
} catch (e: ClassCastException) {
0
}
printInt(argAsInt)
}
fun box(): String {
foo(1)
foo("Hello")
val nonConstInt = 1
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
assertEquals("1\n0\n1\n0\n", sb.toString())
return "OK"
}
-36
View File
@@ -1,36 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun foo(vararg args: Any?) {
for (arg in args) {
sb.appendLine(arg.toString())
}
}
fun box(): String {
foo(1, null, true, "Hello")
val nonConstInt = 1
val nonConstNull = null
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt, nonConstNull, nonConstBool, nonConstString)
assertEquals("""
1
null
true
Hello
1
null
true
Hello
""".trimIndent(), sb.toString())
return "OK"
}
-36
View File
@@ -1,36 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
fun foo(vararg args: Any?) {
for (arg in args) {
sb.appendLine(arg.toString())
}
}
fun bar(vararg args: Any?) {
foo(1, *args, 2, *args, 3)
}
fun box(): String {
bar(null, true, "Hello")
assertEquals("""
1
null
true
Hello
2
null
true
Hello
3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,25 +0,0 @@
/*
* 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.
*/
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()
}
}
fun box(): String {
val res1 = unaryMinus(0.0).toString()
if (res1 != "-0.0") return "FAIL 1: $res1"
val res2 = unaryMinus(0.0f).toString()
if (res2 != "-0.0") return "FAIL 2: $res2"
return "OK"
}
@@ -1,24 +0,0 @@
/*
* 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.
*/
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"
}
@@ -1,24 +0,0 @@
/*
* 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.
*/
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"
}
@@ -1,18 +0,0 @@
/*
* 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.
*/
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"
}
-20
View File
@@ -1,20 +0,0 @@
/*
* 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.
*/
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"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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.
*/
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"
}
-24
View File
@@ -1,24 +0,0 @@
/*
* 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.
*/
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"
}
-15
View File
@@ -1,15 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun foo() {
}
fun box(): String {
if (true) foo() else foo()
return "OK"
}
-17
View File
@@ -1,17 +0,0 @@
/*
* 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.
*/
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()
}
-13
View File
@@ -1,13 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
when (true) {
true -> return "OK"
false -> return "FAIL"
}
}
-17
View File
@@ -1,17 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
fun box(): String {
foo(0)
return "OK"
}
fun foo(x: Int) {
when (x) {
0 -> 0
}
}
@@ -1,24 +0,0 @@
/*
* 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.
*/
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"
}
@@ -1,30 +0,0 @@
/*
* 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.
*/
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
}
}
@@ -1,31 +0,0 @@
// MODULE: lib
// FILE: lib.kt
package a
interface A<T> {
fun foo(): T
}
open class C: A<Int> {
override fun foo(): Int = 42
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
class B: C()
fun box(): String {
val b = B()
assertEquals(42, b.foo())
val c: C = b
assertEquals(42, c.foo())
val a: A<Int> = b
assertEquals(42, a.foo())
return "OK"
}
@@ -1,23 +0,0 @@
// MODULE: lib
// FILE: lib.kt
sealed class Tag {
abstract fun value(): Any
}
sealed class TagBoolean : Tag() {
abstract override fun value(): String
object True : TagBoolean() {
override fun value() = "OK"
}
object False : TagBoolean() {
override fun value() = "FAIL"
}
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = TagBoolean.True.value()
@@ -1,34 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
class A { }
class B { }
class C { }
interface Parser<in IN: Any, out OUT: Any> {
fun parse(source: IN): OUT
}
interface MultiParser<in IN: Any, out OUT: Any> {
fun parse(source: IN): Collection<OUT>
}
interface ExtendsInterface<T: Any>: Parser<A, T>, MultiParser<B, T> {
override fun parse(source: B): Collection<T> = ArrayList<T>()
}
abstract class AbstractClass(): ExtendsInterface<C> {
public override fun parse(source: A): C = C()
}
fun box(): String {
val array = object : AbstractClass() { }.parse(B())
return "OK"
}
-41
View File
@@ -1,41 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
private object NotEmptyMap : MutableMap<Any, Int> {
override fun containsKey(key: Any): Boolean = true
override fun containsValue(value: Int): Boolean = true
// non-special bridges get(Object)Integer -> get(Object)I
override fun get(key: Any): Int = 1
override fun remove(key: Any): Int = 1
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun put(key: Any, value: Int): Int? = throw UnsupportedOperationException()
override fun putAll(from: Map<out Any, Int>): Unit = throw UnsupportedOperationException()
override fun clear(): Unit = throw UnsupportedOperationException()
override val entries: MutableSet<MutableMap.MutableEntry<Any, Int>> get() = null!!
override val keys: MutableSet<Any> get() = null!!
override val values: MutableCollection<Int> get() = null!!
}
fun box(): String {
val n = NotEmptyMap as MutableMap<Any?, Any?>
if (n.get(null) != null) return "FAIL 1: $n"
if (n.containsKey(null)) return "FAIL 2: $n"
if (n.containsValue(null)) return "FAIL 3: $n"
if (n.remove(null) != null) return "FAIL 4: $n"
if (n.get(1) == null) return "FAIL 5: $n"
if (!n.containsKey("")) return "FAIL 6: $n"
if (!n.containsValue(3)) return "FAIL 7: $n"
if (n.remove("") == null) return "FAIL 8: $n"
return "OK"
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2020 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.
*/
import kotlin.test.*
interface Element {
val isContained: Boolean
}
object ContainedElement : Element {
override val isContained: Boolean = true
}
object NotContainedElement : Element {
override val isContained: Boolean = false
}
internal class MySet<E : Element> : Set<E> {
override fun contains(element: E): Boolean = element.isContained
override fun equals(other: Any?): Boolean = TODO()
override fun hashCode(): Int = TODO()
override fun toString(): String = TODO()
override val size: Int get() = TODO()
override fun isEmpty(): Boolean = TODO()
override fun containsAll(elements: Collection<E>): Boolean = TODO()
override fun iterator(): Iterator<E> = TODO()
}
fun set(): Set<Any> = MySet<Element>()
fun box(): String {
val set = set()
if (set.contains(Any())) return "FAIL 1: $set"
if (set.contains(NotContainedElement)) return "FAIL 2: $set"
if (!set.contains(ContainedElement)) return "FAIL 3: $set"
return "OK"
}
-26
View File
@@ -1,26 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
// vtable call
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
fun box(): String {
val c = C()
val a: A = c
val res1 = c.foo().toString()
if (res1 != "42") return "FAIL 1: $res1"
val res2 = a.foo().toString()
if (res2 != "42") return "FAIL 2: $res2"
return "OK"
}
-28
View File
@@ -1,28 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
// interface call, bridge overridden
interface Z1 {
fun foo(x: Int) : Any
}
open class A : Z1 {
override fun foo(x: Int) : Int = 5
}
open class B : A() {
override fun foo(x: Int) : Int = 42
}
fun box(): String {
val z1: A = B()
val res = (z1.foo(1) + 1000).toString()
if (res != "1042") return "FAIL: $res"
return "OK"
}
-40
View File
@@ -1,40 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
open class A<T> {
open fun foo(x: T) {
sb.appendLine(x.toString())
}
}
interface I {
fun foo(x: Int)
}
class B : A<Int>(), I {
var z: Int = 5
override fun foo(x: Int) {
z = x
}
}
fun zzz(a: A<Int>) {
a.foo(42)
}
fun box(): String {
val b = B()
zzz(b)
val a = A<Int>()
zzz(a)
sb.appendLine(b.z.toString())
assertEquals("42\n42\n", sb.toString())
return "OK"
}
-35
View File
@@ -1,35 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
interface I {
fun foo(x: Int)
}
abstract class A<T> {
abstract fun foo(x: T)
}
class B : A<Int>(), I {
override fun foo(x: Int) {
sb.appendLine(x)
Unit
}
}
fun box(): String {
val b = B()
val a: A<Int> = b
val c: I = b
b.foo(42)
a.foo(42)
c.foo(42)
assertEquals("42\n42\n42\n", sb.toString())
return "OK"
}
-36
View File
@@ -1,36 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
abstract class A<in T> {
abstract fun foo(x: T)
}
class B : A<Int>() {
override fun foo(x: Int) {
sb.appendLine("B: $x")
}
}
class C : A<Any>() {
override fun foo(x: Any) {
sb.appendLine("C: $x")
}
}
fun foo(arg: A<Int>) {
arg.foo(42)
}
fun box(): String {
foo(B())
foo(C())
assertEquals("B: 42\nC: 42\n", sb.toString())
return "OK"
}
-34
View File
@@ -1,34 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
open class A<T> {
open fun T.foo() {
sb.appendLine(this.toString())
}
fun bar(x: T) {
x.foo()
}
}
open class B: A<Int>() {
override fun Int.foo() {
sb.appendLine(this.toString())
}
}
fun box(): String {
val b = B()
val a = A<Int>()
b.bar(42)
a.bar(42)
assertEquals("42\n42\n", sb.toString())
return "OK"
}
-66
View File
@@ -1,66 +0,0 @@
/*
* 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.
*/
import kotlin.test.*
val sb = StringBuilder()
open class A<T, U> {
open fun foo(x: T, y: U) {
sb.appendLine(x.toString())
sb.appendLine(y.toString())
}
}
interface I1<T> {
fun foo(x: Int, y: T)
}
interface I2<T> {
fun foo(x: T, y: Int)
}
class B : A<Int, Int>(), I1<Int>, I2<Int> {
var z: Int = 5
var q: Int = 7
override fun foo(x: Int, y: Int) {
z = x
q = y
}
}
fun zzz(a: A<Int, Int>) {
a.foo(42, 56)
}
fun box(): String {
val b = B()
zzz(b)
val a = A<Int, Int>()
zzz(a)
sb.appendLine(b.z.toString())
sb.appendLine(b.q.toString())
val i1: I1<Int> = b
i1.foo(56, 42)
sb.appendLine(b.z.toString())
sb.appendLine(b.q.toString())
val i2: I2<Int> = b
i2.foo(156, 142)
sb.appendLine(b.z.toString())
sb.appendLine(b.q.toString())
assertEquals("""
42
56
42
56
56
42
156
142
""".trimIndent(), sb.toString())
return "OK"
}

Some files were not shown because too many files have changed in this diff Show More