TODO as a function. Add an overload with a string reason.

#KT-8153 Fixed
This commit is contained in:
Ilya Gorbunov
2015-07-14 19:57:15 +03:00
parent bfb116c0b2
commit f2716a973c
2 changed files with 36 additions and 14 deletions
+28 -13
View File
@@ -5,32 +5,47 @@ 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 val prop: String get() = TODO()
// fun method1() = TODO() as String // <- doesn't compile in JS
public fun method2(): Int = TODO()
public fun method3(switch: Boolean, value: String): String {
if (!switch)
TODO
TODO("what if false")
else {
if (value.length() < 3)
throw TODO
else
return value
throw TODO("write message")
}
return value
}
public fun method4() {
TODO()
}
}
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() {
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)
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"))
}
}