-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get rid of isXYZWhere(predicate) functions.
add extension properties to allow traversal of the unwrapped value
- Loading branch information
1 parent
6bfb38a
commit c402b18
Showing
6 changed files
with
75 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,45 @@ | ||
package strikt.arrow.`try` | ||
|
||
import arrow.core.Failure | ||
import arrow.core.Predicate | ||
import arrow.core.Success | ||
import arrow.core.Try | ||
import strikt.api.Assertion | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Assertion.Builder<Try<T>>.isSuccess() = | ||
assert("should be Success") { | ||
when (it) { | ||
is Success -> pass() | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Success<T>> | ||
assert("should be Success") { | ||
when (it) { | ||
is Success -> pass() | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Success<T>> | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Assertion.Builder<Try<T>>.isSuccess(value: T) = | ||
assert("should be Success($value)") { | ||
when (it) { | ||
is Success -> { | ||
if (it.value == value) { | ||
pass() | ||
} else { | ||
fail() | ||
} | ||
} | ||
else -> fail() | ||
assert("should be Success($value)") { | ||
when (it) { | ||
is Success -> { | ||
if (it.value == value) { | ||
pass() | ||
} else { | ||
fail() | ||
} | ||
} as Assertion.Builder<Success<T>> | ||
} | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Success<T>> | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Assertion.Builder<Try<T>>.isSuccessWhere(check: Predicate<T>) = | ||
assert("should be Success") { | ||
when (it) { | ||
is Success -> { | ||
if (check(it.value)) { | ||
pass() | ||
} else { | ||
fail() | ||
} | ||
} | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Success<T>> | ||
val <T> Assertion.Builder<Success<T>>.value: Assertion.Builder<T> | ||
get() = get("success value") { value } | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Assertion.Builder<Try<T>>.isFailure() = | ||
assert("should be Failure") { | ||
when (it) { | ||
is Failure -> pass() | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Failure> | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Assertion.Builder<Try<T>>.isFailure(e: Exception) = | ||
assert("should be Failure") { | ||
when (it) { | ||
is Failure -> { | ||
if (it.exception == e) | ||
pass() | ||
else | ||
fail(actual = it.exception) | ||
} | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Failure> | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> Assertion.Builder<Try<T>>.isFailureWhere(check: Predicate<Throwable>) = | ||
assert("should be Failure") { | ||
when (it) { | ||
is Failure -> { | ||
if (check(it.exception)) { | ||
pass() | ||
} else { | ||
fail() | ||
} | ||
} | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Failure> | ||
|
||
inline fun <reified E : Throwable> Assertion.Builder<Try<*>>.isFailureOfType() = | ||
isFailureWhere { | ||
when (it) { | ||
is E -> true | ||
else -> false | ||
} | ||
assert("should be Failure") { | ||
when (it) { | ||
is Failure -> pass() | ||
else -> fail() | ||
} | ||
} as Assertion.Builder<Failure> | ||
|
||
val Assertion.Builder<Failure>.exception: Assertion.Builder<Throwable> | ||
get() = get("failure exception") { exception } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters