[JS IR] Add stdlib regression tests
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1273
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
// Copy of stdlib test test.collections.ArraysTest.plusInference
|
||||
|
||||
fun box(): String {
|
||||
val arrayOfArrays: Array<Array<out Any>> = arrayOf(arrayOf<Any>("s") as Array<out Any>)
|
||||
val elementArray = arrayOf<Any>("a") as Array<out Any>
|
||||
val arrayPlusElement: Array<Array<out Any>> = arrayOfArrays.plusElement(elementArray)
|
||||
assertEquals("a", arrayPlusElement[1][0])
|
||||
|
||||
val arrayOfStringArrays = arrayOf(arrayOf("s"))
|
||||
val arrayPlusArray = arrayOfStringArrays + arrayOfStringArrays
|
||||
assertEquals("s", arrayPlusArray[1][0])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1750
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val size = 2
|
||||
val a = Array(size) { "$it" }
|
||||
val data = Iterable { a.iterator() }
|
||||
|
||||
val dataChunked = data.chunked(size).single()
|
||||
val expectedSingleChunk = data.toList()
|
||||
if (expectedSingleChunk != dataChunked)
|
||||
return "Fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1274
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
import kotlin.js.json
|
||||
|
||||
fun box(): String {
|
||||
var obj = json(Pair("firstName", "John"), Pair("lastName", "Doe"), Pair("age", 30))
|
||||
assertEquals("John", obj["firstName"], "firstName")
|
||||
assertEquals("Doe", obj["lastName"], "lastName")
|
||||
assertEquals(30, obj["age"], "age")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1279
|
||||
// Snippet from stdlib test test.exceptions.ExceptionTest
|
||||
|
||||
private val cause = Exception("cause")
|
||||
|
||||
fun assertSame(x: Any?, y: Any?) {
|
||||
if (x !== y) {
|
||||
error("Assertion failed")
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Throwable> testCreateException(
|
||||
noarg: () -> T,
|
||||
fromMessage: (String?) -> T,
|
||||
fromCause: ((Throwable?) -> T)? = null,
|
||||
fromMessageCause: ((String?, Throwable?) -> T)? = null
|
||||
) {
|
||||
noarg().let { e ->
|
||||
assertEquals(null, e.message)
|
||||
assertEquals(null, e.cause)
|
||||
}
|
||||
|
||||
fromMessage("message").let { e ->
|
||||
assertEquals("message", e.message)
|
||||
assertEquals(null, e.cause)
|
||||
}
|
||||
|
||||
fromMessage(null).let { e ->
|
||||
assertTrue(e.message == null || e.message == "null")
|
||||
}
|
||||
|
||||
fromMessageCause?.run {
|
||||
invoke("message", cause).let { e ->
|
||||
assertEquals("message", e.message)
|
||||
assertSame(cause, e.cause)
|
||||
}
|
||||
invoke(null, null).let { e ->
|
||||
assertEquals(null, e.message)
|
||||
assertEquals(null, e.cause)
|
||||
}
|
||||
}
|
||||
|
||||
fromCause?.invoke(cause)?.let { e ->
|
||||
assertSame(cause, e.cause)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testCreateException(::Throwable, ::Throwable, ::Throwable, ::Throwable)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user