Intention to convert assert to an if with throw

This commit is contained in:
Tal Man
2014-04-10 13:17:09 -04:00
parent db38f420f3
commit 9cff3ba049
40 changed files with 402 additions and 1 deletions
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, "text")
}
class AssertionError
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw lang.AssertionError("text")
}
}
class AssertionError
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true && false, "text")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!(true && false)) {
throw AssertionError("text")
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(1 > 0, "text")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (1 <= 0) {
throw AssertionError("text")
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(0 != 1, "text")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (0 == 1) {
throw AssertionError("text")
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
val x = true
val y = false
<caret>assert(x || y, "text")
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun foo() {
val x = true
val y = false
if (!(x || y)) {
throw AssertionError("text")
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(bar(), "text")
}
fun bar(): Boolean = true
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun foo() {
if (!bar()) {
throw AssertionError("text")
}
}
fun bar(): Boolean = true
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, ::message)
}
fun message(): String = "text"
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError(message())
}
}
fun message(): String = "text"
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun foo() {
<caret>assert(true, "")
}
fun assert(b: Boolean, s: String) {}
@@ -0,0 +1,9 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
package pr442.kotlin
fun foo() {
<caret>assert(true, "")
}
fun assert(b: Boolean, s: String) {}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
// ERROR: No value passed for parameter value
fun foo() {
<caret>assert { "text" }
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, { "text" })
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError({ "text" }())
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true) { "text" }
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError({ "text" }())
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
val f = { "text" }
<caret>assert(true, f)
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun foo() {
val f = { "text" }
if (!true) {
throw AssertionError(f())
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true)
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError("Assertion failed")
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert((true && false), "text")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!(true && false)) {
throw AssertionError("text")
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, "text")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError("text")
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo() {
val f = "text"
<caret>assert(true, f)
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun foo() {
val f = "text"
if (!true) {
throw AssertionError(f)
}
}