TODO as a function. Add an overload with a string reason.
#KT-8153 Fixed
This commit is contained in:
@@ -4,7 +4,14 @@ package kotlin
|
|||||||
/**
|
/**
|
||||||
* Always throws an [UnsupportedOperationException] stating that operation is not implemented.
|
* Always throws an [UnsupportedOperationException] stating that operation is not implemented.
|
||||||
*/
|
*/
|
||||||
public val TODO: Nothing get() = throw UnsupportedOperationException("An operation is not implemented.")
|
public fun TODO(): Nothing = throw UnsupportedOperationException("An operation is not implemented.")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Always throws an [UnsupportedOperationException] stating that operation is not implemented.
|
||||||
|
*
|
||||||
|
* @param reason a string explaining why the implementation is missing.
|
||||||
|
*/
|
||||||
|
public fun TODO(reason: String): Nothing = throw UnsupportedOperationException("An operation is not implemented: $reason")
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,32 +5,47 @@ import kotlin.test.*
|
|||||||
import org.junit.Test as test
|
import org.junit.Test as test
|
||||||
|
|
||||||
private class PartiallyImplementedClass {
|
private class PartiallyImplementedClass {
|
||||||
public val prop: String get() = TODO
|
public val prop: String get() = TODO()
|
||||||
|
// fun method1() = TODO() as String // <- doesn't compile in JS
|
||||||
internal fun method1() = TODO as String
|
public fun method2(): Int = TODO()
|
||||||
public fun method2(): Int = TODO
|
|
||||||
|
|
||||||
public fun method3(switch: Boolean, value: String): String {
|
public fun method3(switch: Boolean, value: String): String {
|
||||||
if (!switch)
|
if (!switch)
|
||||||
TODO
|
TODO("what if false")
|
||||||
else {
|
else {
|
||||||
if (value.length() < 3)
|
if (value.length() < 3)
|
||||||
throw TODO
|
throw TODO("write message")
|
||||||
else
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun method4() {
|
||||||
|
TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TODOTest {
|
class TODOTest {
|
||||||
|
private fun assertNotImplemented(block: () -> Unit) {
|
||||||
|
assertTrue(fails(block) is UnsupportedOperationException)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertNotImplementedWithMessage(message: String, block: () -> Unit) {
|
||||||
|
val e = fails(block)
|
||||||
|
assertTrue(e is UnsupportedOperationException)
|
||||||
|
assertTrue(message in e!!.getMessage()!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
test fun usage() {
|
test fun usage() {
|
||||||
val inst = PartiallyImplementedClass()
|
val inst = PartiallyImplementedClass()
|
||||||
|
|
||||||
assertTrue(fails { inst.prop } is UnsupportedOperationException)
|
assertNotImplemented { inst.prop }
|
||||||
assertTrue(fails { inst.method1() } is UnsupportedOperationException)
|
// assertNotImplemented{ inst.method1() }
|
||||||
assertTrue(fails { inst.method2() } is UnsupportedOperationException)
|
assertNotImplemented { inst.method2() }
|
||||||
assertTrue(fails { inst.method3(false, "test") } is UnsupportedOperationException)
|
assertNotImplemented { inst.method4() }
|
||||||
assertTrue(fails { inst.method3(true, "t") } is UnsupportedOperationException)
|
assertNotImplementedWithMessage("what if false") { inst.method3(false, "test") }
|
||||||
|
assertNotImplementedWithMessage("write message") { inst.method3(true, "t") }
|
||||||
assertEquals("test", inst.method3(true, "test"))
|
assertEquals("test", inst.method3(true, "test"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user