tests: Copy stdlib tests from Kotlin/JVM
This patch copies Kotlin/JVM stdlib tests (libraries/stdlib/test) excepting ones with explicit java dependencies. It also transforms the tests to use them as box-tests.
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun box() {
|
||||
for (component in listOf(Int.MIN_VALUE, -1, 0, KotlinVersion.MAX_COMPONENT_VALUE, KotlinVersion.MAX_COMPONENT_VALUE + 1, Int.MAX_VALUE)) {
|
||||
for (place in 0..2) {
|
||||
val (major, minor, patch) = IntArray(3) { index -> if (index == place) component else 0 }
|
||||
if (component in 0..KotlinVersion.MAX_COMPONENT_VALUE) {
|
||||
KotlinVersion(major, minor, patch)
|
||||
} else {
|
||||
assertFailsWith<IllegalArgumentException>("Expected $major.$minor.$patch to be invalid version") {
|
||||
KotlinVersion(major, minor, patch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun box() {
|
||||
assertTrue(KotlinVersion.CURRENT.isAtLeast(1, 1))
|
||||
assertTrue(KotlinVersion.CURRENT.isAtLeast(1, 1, 0))
|
||||
assertTrue(KotlinVersion.CURRENT >= KotlinVersion(1, 1))
|
||||
assertTrue(KotlinVersion(1, 1) <= KotlinVersion.CURRENT)
|
||||
|
||||
val anotherCurrent = KotlinVersion.CURRENT.run { KotlinVersion(major, minor, patch) }
|
||||
assertEquals(KotlinVersion.CURRENT, anotherCurrent)
|
||||
assertEquals(KotlinVersion.CURRENT.hashCode(), anotherCurrent.hashCode())
|
||||
assertEquals(0, KotlinVersion.CURRENT.compareTo(anotherCurrent))
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun box() {
|
||||
val lazyInt = lazyOf(1)
|
||||
|
||||
assertTrue(lazyInt.isInitialized())
|
||||
assertEquals(1, lazyInt.value)
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun box() {
|
||||
var callCount = 0
|
||||
val lazyInt = lazy { ++callCount }
|
||||
|
||||
assertEquals(0, callCount)
|
||||
assertFalse(lazyInt.isInitialized())
|
||||
assertEquals(1, lazyInt.value)
|
||||
assertEquals(1, callCount)
|
||||
assertTrue(lazyInt.isInitialized())
|
||||
|
||||
lazyInt.value
|
||||
assertEquals(1, callCount)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun box() {
|
||||
var callCount = 0
|
||||
val lazyInt = lazy { ++callCount }
|
||||
|
||||
assertNotEquals("1", lazyInt.toString())
|
||||
assertEquals(0, callCount)
|
||||
|
||||
assertEquals(1, lazyInt.value)
|
||||
assertEquals("1", lazyInt.toString())
|
||||
assertEquals(1, callCount)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
|
||||
private class PartiallyImplementedClass {
|
||||
public val prop: String get() = TODO()
|
||||
fun method1() = TODO() as String
|
||||
public fun method2(): Int = TODO()
|
||||
|
||||
public fun method3(switch: Boolean, value: String): String {
|
||||
if (!switch)
|
||||
TODO("what if false")
|
||||
else {
|
||||
if (value.length < 3)
|
||||
throw TODO("write message")
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
public fun method4() {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertNotImplemented(block: () -> Unit) {
|
||||
assertFailsWith<NotImplementedError>(block = block)
|
||||
}
|
||||
|
||||
private fun assertNotImplementedWithMessage(message: String, block: () -> Unit) {
|
||||
val e = assertFailsWith<NotImplementedError>(block = block)
|
||||
assertTrue(message in e.message!!)
|
||||
}
|
||||
|
||||
|
||||
fun box() {
|
||||
val inst = PartiallyImplementedClass()
|
||||
|
||||
assertNotImplemented { inst.prop }
|
||||
assertNotImplemented { inst.method1() }
|
||||
assertNotImplemented { inst.method2() }
|
||||
assertNotImplemented { inst.method4() }
|
||||
assertNotImplementedWithMessage("what if false") { inst.method3(false, "test") }
|
||||
assertNotImplementedWithMessage("write message") { inst.method3(true, "t") }
|
||||
assertEquals("test", inst.method3(true, "test"))
|
||||
}
|
||||
Reference in New Issue
Block a user