[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,20 @@
|
||||
/*
|
||||
* 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 square(a:Int):Int = a * a
|
||||
fun sumOfSquares(a:Int, b:Int):Int = square(a) + square(b)
|
||||
fun diffOfSquares(a:Int, b:Int):Int = square(a) - square(b)
|
||||
fun mod(a:Int,b:Int):Int = a / b
|
||||
fun remainder(a:Int, b:Int):Int = a % b
|
||||
|
||||
fun box(): String {
|
||||
if (square(2) != 4) throw Error()
|
||||
if (sumOfSquares(2, 4) != 20) throw Error()
|
||||
if (diffOfSquares(2, 4) != -12) throw Error()
|
||||
if (mod(5, 2) != 2) throw Error()
|
||||
if (remainder(5, 2) != 1) throw Error()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* 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 bool_yes(): Boolean = true
|
||||
|
||||
fun box(): String {
|
||||
if (!bool_yes()) return "FAIL !bool_yes()"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Created by minamoto on 12/26/16.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
open class A(val a:Int) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other == null || other as? A == null) return false
|
||||
return (other as A).a == a // Where is smart casting?
|
||||
}
|
||||
|
||||
companion object {
|
||||
val zero = A(0)
|
||||
val one = A(1)
|
||||
val magic = A(42)
|
||||
}
|
||||
}
|
||||
|
||||
// FUN public fun foo(a: defaults.A = ...): kotlin.Int
|
||||
// a: EXPRESSION_BODY
|
||||
// CALL '<get-magic>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
// BLOCK_BODY
|
||||
// RETURN type=kotlin.Nothing from='foo(A = ...): Int'
|
||||
// CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: GET_VAR 'value-parameter a: A = ...' type=defaults.A origin=null
|
||||
fun foo(a: A = A.magic, b:Int = 0xdeadbeef.toInt()) = a.a
|
||||
|
||||
// FUN public fun bar(a: defaults.A, inc: kotlin.Int = ...): defaults.A
|
||||
// inc: EXPRESSION_BODY
|
||||
// CONST Int type=kotlin.Int value='0'
|
||||
// BLOCK_BODY
|
||||
// RETURN type=kotlin.Nothing from='bar(A, Int = ...): A'
|
||||
// CALL 'constructor A(Int)' type=defaults.A origin=null
|
||||
// a: CALL 'plus(Int): Int' type=kotlin.Int origin=PLUS
|
||||
// $this: CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: GET_VAR 'value-parameter a: A' type=defaults.A origin=null
|
||||
// other: GET_VAR 'value-parameter inc: Int = ...' type=kotlin.Int origin=null
|
||||
fun bar(a:A, inc:Int = 0) = A(a.a + inc)
|
||||
|
||||
|
||||
fun box(): String {
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'foo(A = ...): Int' type=kotlin.Int origin=null
|
||||
// arg1: CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: CALL '<get-magic>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
if (foo() != A.magic.a) {
|
||||
println("magic failed")
|
||||
throw Error()
|
||||
}
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'foo(A = ...): Int' type=kotlin.Int origin=null
|
||||
// a: CALL 'constructor A(Int)' type=defaults.A origin=null
|
||||
// a: CONST Int type=kotlin.Int value='1'
|
||||
// arg1: CONST Int type=kotlin.Int value='1'
|
||||
if (foo(A(1)) != 1) {
|
||||
println("one failed: foo(A(1))")
|
||||
throw Error()
|
||||
}
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'bar(A, Int = ...): A' type=defaults.A origin=null
|
||||
// a: CALL '<get-one>(): A' type=defaults.A origin=GET_PROPERTY <---
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
// arg1: CALL '<get-one>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
|
||||
if (bar(A.one) != A.one) {
|
||||
println("A one failed")
|
||||
throw Error()
|
||||
}
|
||||
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: CALL 'bar(A, Int = ...): A' type=defaults.A origin=null
|
||||
// a: CALL '<get-one>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
// inc: CONST Int type=kotlin.Int value='1'
|
||||
// arg1: CONST Int type=kotlin.Int value='2'
|
||||
if (bar(A.one, 1).a != 2) {
|
||||
println("A one + 1 failed")
|
||||
throw Error()
|
||||
}
|
||||
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 foo(x:Int = 0, y:Int = x + 1, z:Int = x + y + 1) = x + y + z
|
||||
|
||||
fun box(): String {
|
||||
val v = foo()
|
||||
if (v != 3) {
|
||||
println("test failed $v expected 3")
|
||||
throw Error()
|
||||
}
|
||||
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.*
|
||||
|
||||
enum class A(one: Int, val two: Int = one) {
|
||||
FOO(42)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(42, (A.FOO.two))
|
||||
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 Int.foo(inc0:Int, inc:Int = 0) = this + inc0 + inc
|
||||
|
||||
fun box(): String {
|
||||
val v = 42.foo(0)
|
||||
if (v != 42) {
|
||||
println("test failed v:$v expected:42")
|
||||
throw Error()
|
||||
}
|
||||
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.
|
||||
*/
|
||||
|
||||
fun foo(a:Int = 2, b:String = "Hello", c:Int = 4):String = "$b-$c$a"
|
||||
fun foo(a:Int = 3, b:Int = a + 1, c:Int = a + b) = a + b + c
|
||||
|
||||
fun box(): String {
|
||||
val a = foo(b="Universe")
|
||||
if (a != "Universe-42")
|
||||
throw Error()
|
||||
|
||||
val b = foo(b = 5)
|
||||
if (b != (/* a = */ 3 + /* b = */ 5 + /* c = */ (3 + 5)))
|
||||
throw Error()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS Defaults4Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -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.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class A {
|
||||
open fun foo(x: Int = 42) = sb.append(x)
|
||||
}
|
||||
|
||||
open class B : A()
|
||||
|
||||
class C : B() {
|
||||
override fun foo(x: Int) = sb.append(x + 1)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
C().foo()
|
||||
|
||||
assertEquals("43", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS Defaults5Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -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.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class TestClass(val x: Int) {
|
||||
fun foo(y: Int = x) {
|
||||
sb.appendLine(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun TestClass.bar(y: Int = x) {
|
||||
sb.appendLine(y)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
TestClass(5).foo()
|
||||
TestClass(6).bar()
|
||||
|
||||
assertEquals("5\n6\n", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class Foo(val x: Int = 42)
|
||||
class Bar : Foo()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(42, Bar().x)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS Defaults7Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
/**
|
||||
* Test fails with code generation:
|
||||
* Call parameter type does not match function signature!
|
||||
* %5 = invoke %struct.ObjHeader* @"kfun:kotlin.native.internal.boxInt(kotlin.Int)"(i32 1, %struct.ObjHeader** %4)
|
||||
* to label %label_ unwind label %cleanup_landingpad
|
||||
* i32 invoke void @"kfun:foo$default(kotlin.Int;kotlin.Int;kotlin.Int)"(%struct.ObjHeader* %5, i32 0, i32 2)
|
||||
* to label %label_1 unwind label %cleanup_landingpad
|
||||
*/
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun <T> foo(a : T, b : Int = 42){
|
||||
sb.append(b)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo(1)
|
||||
|
||||
assertEquals("42", sb.toString())
|
||||
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.*
|
||||
|
||||
class Foo {
|
||||
fun test(x: Int = 1) = x
|
||||
}
|
||||
|
||||
class Bar {
|
||||
fun test(x: Int = 2) = x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(2, Bar().test())
|
||||
|
||||
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.*
|
||||
|
||||
class Foo {
|
||||
inner class Bar(x: Int, val y: Int = 1) {
|
||||
constructor() : this(42)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, Foo().Bar().y)
|
||||
return "OK"
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I<T> {
|
||||
fun f(x: String = "OK"): String
|
||||
}
|
||||
|
||||
open class A<T> {
|
||||
open fun f(x: String) = x
|
||||
}
|
||||
|
||||
class B : A<String>(), I<String>
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
return b.f()
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
inline class Foo(val value: Int)
|
||||
fun foo(x: Foo = Foo(42)) = x.value
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(foo(), 42)
|
||||
assertEquals(foo(Foo(17)), 17)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS DefaultsWithVarArg1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun foo(s: String = "", vararg args: Any) {
|
||||
if (args == null) {
|
||||
sb.appendLine("Failed!")
|
||||
} else {
|
||||
sb.append("$s ")
|
||||
args.forEach {
|
||||
sb.append("$it")
|
||||
}
|
||||
sb.appendLine(", Correct!")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo("Hello")
|
||||
foo("Hello", "World")
|
||||
foo()
|
||||
|
||||
assertEquals("""
|
||||
Hello , Correct!
|
||||
Hello World, Correct!
|
||||
, Correct!
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS DefaultsWithVarArg2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -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.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun foo(vararg arr: Int = intArrayOf(1, 2)) {
|
||||
arr.forEach { sb.appendLine(it) }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
foo(42)
|
||||
|
||||
assertEquals("""
|
||||
1
|
||||
2
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// KT-66104: Internal error in file lowering: java.util.NoSuchElementException: Sequence contains no element matching the predicate.
|
||||
// IGNORE_BACKEND: WASM
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun eqeqB (a:Byte, b:Byte ) = a == b
|
||||
fun eqeqS (a:Short, b:Short ) = a == b
|
||||
fun eqeqI (a:Int, b:Int ) = a == b
|
||||
fun eqeqL (a:Long, b:Long ) = a == b
|
||||
fun eqeqF (a:Float, b:Float ) = a == b
|
||||
fun eqeqD (a:Double, b:Double) = a == b
|
||||
fun eqeqStr(a:String, b:String) = a == b
|
||||
|
||||
fun eqeqN (a: Nothing, b: Nothing) = a == b
|
||||
fun eqeqNN (a: Nothing?, b: Nothing?) = a == b
|
||||
|
||||
fun eqeqeq (a: Any?, b: Any?) = a === b
|
||||
|
||||
fun gtI (a:Int, b:Int ) = a > b
|
||||
fun ltI (a:Int, b:Int ) = a < b
|
||||
fun geI (a:Int, b:Int ) = a >= b
|
||||
fun leI (a:Int, b:Int ) = a <= b
|
||||
fun neI (a:Int, b:Int ) = a != b
|
||||
|
||||
fun gtF (a:Float, b:Float ) = a > b
|
||||
fun ltF (a:Float, b:Float ) = a < b
|
||||
fun geF (a:Float, b:Float ) = a >= b
|
||||
fun leF (a:Float, b:Float ) = a <= b
|
||||
fun neF (a:Float, b:Float ) = a != b
|
||||
|
||||
fun helloString() = "Hello"
|
||||
fun goodbyeString() = "Goodbye"
|
||||
|
||||
fun box(): String {
|
||||
if (!eqeqB(3 , 3 )) throw Error()
|
||||
if (!eqeqS(3 , 3 )) throw Error()
|
||||
if (!eqeqI(3 , 3 )) throw Error()
|
||||
if (!eqeqL(3L , 3L )) throw Error()
|
||||
if (!eqeqF(3.0f, 3.0f)) throw Error()
|
||||
if (!eqeqD(3.0 , 3.0 )) throw Error()
|
||||
|
||||
if (!eqeqStr(helloString(), helloString())) throw Error()
|
||||
|
||||
if (!eqeqNN(null, null)) throw Error()
|
||||
|
||||
if (!eqeqeq(helloString(), helloString())) throw Error()
|
||||
if (eqeqeq(helloString(), goodbyeString())) throw Error()
|
||||
|
||||
if (gtI (2 , 3 )) throw Error()
|
||||
if (ltI (3 , 2 )) throw Error()
|
||||
if (geI (2 , 3 )) throw Error()
|
||||
if (leI (3 , 2 )) throw Error()
|
||||
if (neI (2 , 2 )) throw Error()
|
||||
|
||||
if (gtF (2.0f , 3.0f )) throw Error()
|
||||
if (ltF (3.0f , 2.0f )) throw Error()
|
||||
if (geF (2.0f , 3.0f )) throw Error()
|
||||
if (leF (3.0f , 2.0f )) throw Error()
|
||||
if (neF (2.0f , 2.0f )) throw Error()
|
||||
|
||||
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.*
|
||||
|
||||
class B(val a: Int)
|
||||
|
||||
fun B.foo() = this.a
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(42, B(42).foo())
|
||||
return "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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// This code fails to link when bultins are taken from the
|
||||
// frontend generated module, instead of our library.
|
||||
// Because the generated module doesn't see our name changing annotations,
|
||||
// the function names are all wrong.
|
||||
|
||||
fun intrinsic(b: Int): Int {
|
||||
var sum = 1
|
||||
sum = sum + b
|
||||
return sum
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(4, intrinsic(3))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS LocalFunctionKt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val x = 1
|
||||
fun local0() = sb.appendLine(x)
|
||||
fun local1() {
|
||||
fun local2() {
|
||||
local1()
|
||||
}
|
||||
local0()
|
||||
}
|
||||
|
||||
fun l1() {
|
||||
var x = 1
|
||||
fun l2() {
|
||||
fun l3() {
|
||||
l1()
|
||||
x = 5
|
||||
}
|
||||
l3()
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 {
|
||||
var a = 0
|
||||
fun local() {
|
||||
class A {
|
||||
val b = 0
|
||||
fun f() {
|
||||
a = b
|
||||
}
|
||||
|
||||
}
|
||||
fun local2() : A {
|
||||
return A()
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 {
|
||||
fun bar() {
|
||||
fun local1() {
|
||||
bar()
|
||||
}
|
||||
local1()
|
||||
|
||||
var x = 0
|
||||
fun local2() {
|
||||
x++
|
||||
bar()
|
||||
}
|
||||
local2()
|
||||
}
|
||||
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 minus_eq(a: Int): Int {
|
||||
var b = 11
|
||||
b -= a
|
||||
return b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals (-12, minus_eq(23))
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -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 foo(a:Int, b:Int) = a - b
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(18, foo(b = 24, a = 42))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun Any.nothing(): Nothing {
|
||||
while (true) {}
|
||||
}
|
||||
|
||||
class Anything
|
||||
|
||||
fun testFunction1(obj: Any?): Nothing? = obj?.nothing()
|
||||
fun testFunction2(obj: Any?): Any? = obj?.nothing()
|
||||
fun testFunction3(obj: Any?): String? = obj?.nothing()
|
||||
fun testFunction4(obj: Any?): Unit? = obj?.nothing()
|
||||
fun testFunction5(obj: Any?): Anything? = obj?.nothing()
|
||||
|
||||
fun testLambda1() {
|
||||
val block: (Any?) -> Nothing? = {
|
||||
it?.nothing()
|
||||
}
|
||||
block(null)
|
||||
}
|
||||
|
||||
fun testLambda2() {
|
||||
val block: (Any?) -> Nothing? = {
|
||||
print("") // more than one statement inside of the body
|
||||
it?.nothing()
|
||||
}
|
||||
block(null)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testFunction1(null)
|
||||
testFunction2(null)
|
||||
testFunction3(null)
|
||||
testFunction4(null)
|
||||
testFunction5(null)
|
||||
|
||||
testLambda1()
|
||||
testLambda2()
|
||||
|
||||
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 plus_eq(a: Int): Int {
|
||||
var b = 11
|
||||
b += a
|
||||
return b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(14, plus_eq(3))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun фу(а: Int, б: Int, в: Int, г: Int, д: Int, е: Int, ё: Int, ж: Int, з: Int, и: Int, й: Int, к: Int,
|
||||
л: Int, м: Int, н: Int, о: Int, п: Int, р: Int, с: Int, т: Int, у: Int, ф: Int, х: Int, ц: Int,
|
||||
ч: Int, ш: Int, щ: Int, ъ: Int, ы: Int, ь: Int, э: Int, ю: Int, я: Int): Int {
|
||||
return а + б + в + г + д + е + ё + ж + з + и + й + к + л + м + н + о +
|
||||
п + р + с + т + у + ф + х + ц + ч + ш + щ + ъ + ы + ь + э + ю + я
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ref = ::фу
|
||||
assertEquals(528, ref(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32))
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun sumIB(a:Int, b:Byte ) = a + b
|
||||
fun sumIS(a:Int, b:Short ) = a + b
|
||||
fun sumII(a:Int, b:Int ) = a + b
|
||||
fun sumIL(a:Int, b:Long ) = a + b
|
||||
fun sumIF(a:Int, b:Float ) = a + b
|
||||
fun sumID(a:Int, b:Double) = a + b
|
||||
|
||||
fun modID(a:Int, b:Double) = a % b
|
||||
|
||||
fun box(): String {
|
||||
if (sumIB(2, 3) != 5) throw Error()
|
||||
if (sumIS(2, 3) != 5) throw Error()
|
||||
if (sumII(2, 3) != 5) throw Error()
|
||||
if (sumIL(2, 3L) != 5L) throw Error()
|
||||
if (sumIF(2, 3.0f) != 5.0f) throw Error()
|
||||
if (sumID(2, 3.0) != 5.0) throw Error()
|
||||
if (modID(5, 3.0) != 2.0) throw Error()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun sum3():Int = sum(1, 2, 33)
|
||||
fun sum(a:Int, b:Int, c:Int): Int = a + b + c
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(36, sum3())
|
||||
return "OK"
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(a:Int):Int = a
|
||||
fun bar(a:Int):Int = a
|
||||
|
||||
fun sumFooBar(a:Int, b:Int):Int = foo(a) + bar(b)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(5, sumFooBar(2, 3))
|
||||
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():Int = 1
|
||||
fun bar():Int = 2
|
||||
fun sum():Int = foo() + bar()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(3, sum())
|
||||
return "OK"
|
||||
}
|
||||
@@ -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 sum(a:Int): Int = a + 33
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(35, sum(2))
|
||||
return "OK"
|
||||
}
|
||||
@@ -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 sum(a:Float, b:Int) = a + b
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(3.0F, sum(1.0F, 2))
|
||||
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 sum(a:Int, b:Int):Int {
|
||||
var c:Int
|
||||
c = a + b
|
||||
return c
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(50, sum(42, 8))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun test1(): Any? {
|
||||
return 1
|
||||
42
|
||||
}
|
||||
|
||||
fun test2(): Int? {
|
||||
return 2
|
||||
42
|
||||
}
|
||||
|
||||
fun test3(): Any {
|
||||
return 3
|
||||
42
|
||||
}
|
||||
|
||||
fun test4(): Int {
|
||||
return 4
|
||||
42
|
||||
}
|
||||
|
||||
suspend fun test5(): Any? {
|
||||
return 5
|
||||
42
|
||||
}
|
||||
|
||||
suspend fun test6(): Int? {
|
||||
return 6
|
||||
42
|
||||
}
|
||||
|
||||
suspend fun test7(): Any {
|
||||
return 7
|
||||
42
|
||||
}
|
||||
|
||||
suspend fun test8(): Int {
|
||||
return 8
|
||||
42
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <T> (suspend () -> T).runCoroutine() : T {
|
||||
var result : Any? = null
|
||||
startCoroutine(Continuation(EmptyCoroutineContext) { result = it.getOrThrow() })
|
||||
return result as T
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, test1())
|
||||
assertEquals(2, test2())
|
||||
assertEquals(3, test3())
|
||||
assertEquals(4, test4())
|
||||
|
||||
assertEquals(5, ::test5.runCoroutine())
|
||||
assertEquals(6, ::test6.runCoroutine())
|
||||
assertEquals(7, ::test7.runCoroutine())
|
||||
assertEquals(8, ::test8.runCoroutine())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user