backend/tests: Add blackbox tests from Kotlin JVM

Added tests from testData/codegen/box directory. There are blackbox tests
in other directories and they are to be added.
This commit is contained in:
Ilya Matveev
2017-01-12 19:43:20 +07:00
parent d5988297b1
commit 1b553ebfaf
2643 changed files with 66666 additions and 0 deletions
@@ -0,0 +1,7 @@
data class A(val x: Int) {
override fun hashCode(): Int = -3
}
fun box(): String {
return if (A(0).hashCode() == -3) "OK" else "fail"
}
@@ -0,0 +1,22 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
data class A(val x: Int) {
fun hashCode(other: Any): Int = 0
}
data class B(val x: Int) {
fun hashCode(other: B, another: Any): Int = 0
}
fun box(): String {
A::class.java.getDeclaredMethod("hashCode")
A::class.java.getDeclaredMethod("hashCode", Any::class.java)
B::class.java.getDeclaredMethod("hashCode")
B::class.java.getDeclaredMethod("hashCode", B::class.java, Any::class.java)
return "OK"
}
@@ -0,0 +1,9 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
data class A(val a: IntArray, var b: Array<String>)
fun box() : String {
if( A(intArrayOf(1,2,3),arrayOf("239")).hashCode() != 31*java.util.Arrays.hashCode(intArrayOf(0,1,2)) + "239".hashCode()) "fail"
return "OK"
}
@@ -0,0 +1,5 @@
data class A(val a: Boolean)
fun box() : String {
return if( A(true).hashCode()==1 && A(false).hashCode()==0 ) "OK" else "fail"
}
@@ -0,0 +1,7 @@
data class A(val a: Byte)
fun box() : String {
val v1 = A(10.toByte()).hashCode()
val v2 = (10.toByte() as Byte?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -0,0 +1,7 @@
data class A(val a: Char)
fun box() : String {
val v1 = A('a').hashCode()
val v2 = ('a' as Char?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -0,0 +1,7 @@
data class A(val a: Double)
fun box() : String {
val v1 = A(-10.toDouble()).hashCode()
val v2 = (-10.toDouble() as Double?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -0,0 +1,7 @@
data class A(val a: Float)
fun box() : String {
val v1 = A(-10.toFloat()).hashCode()
val v2 = (-10.toFloat() as Float?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -0,0 +1,7 @@
data class A<T>(val t: T)
fun box(): String {
val h = A<String?>(null).hashCode()
if (h != 0) return "Fail $h"
return "OK"
}
@@ -0,0 +1,7 @@
data class A(val a: Int)
fun box() : String {
val v1 = A(-10.toInt()).hashCode()
val v2 = (-10.toInt() as Int?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -0,0 +1,7 @@
data class A(val a: Long)
fun box() : String {
val v1 = A(-10.toLong()).hashCode()
val v2 = (-10.toLong() as Long?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -0,0 +1,16 @@
data class A(val a: Any?, var x: Int)
data class B(val a: Any?)
data class C(val a: Int, var x: Int?)
data class D(val a: Int?)
fun box() : String {
if( A(null,19).hashCode() != 19) "fail"
if( A(239,19).hashCode() != (239*31+19)) "fail"
if( B(null).hashCode() != 0) "fail"
if( B(239).hashCode() != 239) "fail"
if( C(239,19).hashCode() != (239*31+19)) "fail"
if( C(239,null).hashCode() != 239*31) "fail"
if( D(239).hashCode() != (239)) "fail"
if( D(null).hashCode() != 0) "fail"
return "OK"
}
@@ -0,0 +1,7 @@
data class A(val a: Short)
fun box() : String {
val v1 = A(10.toShort()).hashCode()
val v2 = (10.toShort() as Short?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}