From bfb116c0b26d05684b9930b274be9558220be721 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 14 Jul 2015 18:37:28 +0300 Subject: [PATCH] Provide TODO as a substitution for not yet implemented method body. #KT-8153 --- libraries/stdlib/src/kotlin/util/Standard.kt | 7 ++++ libraries/stdlib/test/utils/TODOTest.kt | 36 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 libraries/stdlib/test/utils/TODOTest.kt diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index 6155ff3407d..7c86a52e43e 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -1,5 +1,12 @@ package kotlin + +/** + * Always throws an [UnsupportedOperationException] stating that operation is not implemented. + */ +public val TODO: Nothing get() = throw UnsupportedOperationException("An operation is not implemented.") + + /** * Creates a tuple of type [Pair] from this and [that]. * diff --git a/libraries/stdlib/test/utils/TODOTest.kt b/libraries/stdlib/test/utils/TODOTest.kt new file mode 100644 index 00000000000..5ba03d729b7 --- /dev/null +++ b/libraries/stdlib/test/utils/TODOTest.kt @@ -0,0 +1,36 @@ +package test.utils + +import kotlin.* +import kotlin.test.* +import org.junit.Test as test + +private class PartiallyImplementedClass { + public val prop: String get() = TODO + + internal fun method1() = TODO as String + public fun method2(): Int = TODO + + public fun method3(switch: Boolean, value: String): String { + if (!switch) + TODO + else { + if (value.length() < 3) + throw TODO + else + return value + } + } +} + +class TODOTest { + test fun usage() { + val inst = PartiallyImplementedClass() + + assertTrue(fails { inst.prop } is UnsupportedOperationException) + assertTrue(fails { inst.method1() } is UnsupportedOperationException) + assertTrue(fails { inst.method2() } is UnsupportedOperationException) + assertTrue(fails { inst.method3(false, "test") } is UnsupportedOperationException) + assertTrue(fails { inst.method3(true, "t") } is UnsupportedOperationException) + assertEquals("test", inst.method3(true, "test")) + } +}