Add alias for "fail"
This commit is contained in:
@@ -45,3 +45,7 @@ proc fail*[T](msg: string): OP[T] =
|
|||||||
assert res.error == "Something is wrong!"
|
assert res.error == "Something is wrong!"
|
||||||
OP[T](isOK: false, error: msg)
|
OP[T](isOK: false, error: msg)
|
||||||
|
|
||||||
|
proc fail*(T: typedesc, msg: string): OP[T] =
|
||||||
|
## Alias for `fail[T](string) proc <#fail,string>`_
|
||||||
|
fail[T] msg
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ test "Check proc results":
|
|||||||
check data.isOk
|
check data.isOk
|
||||||
check data.val == "This is test code!"
|
check data.val == "This is test code!"
|
||||||
|
|
||||||
test "Check failing proc":
|
test "Check failing result proc":
|
||||||
proc someProc(): OP[int] =
|
proc someProc(): OP[int] =
|
||||||
result.fail "Not implemented!"
|
result.fail "Not implemented!"
|
||||||
|
|
||||||
@@ -27,6 +27,22 @@ test "Check failing proc":
|
|||||||
assert data.isOk == false
|
assert data.isOk == false
|
||||||
assert data.error == "Not implemented!"
|
assert data.error == "Not implemented!"
|
||||||
|
|
||||||
|
test "Check failing typedesc proc ":
|
||||||
|
proc someProc(): OP[int] =
|
||||||
|
fail(int, "Not implemented!")
|
||||||
|
|
||||||
|
let data = someProc()
|
||||||
|
assert data.isOk == false
|
||||||
|
assert data.error == "Not implemented!"
|
||||||
|
|
||||||
|
test "Check failing type param proc ":
|
||||||
|
proc someProc(): OP[int] =
|
||||||
|
op.fail[int]("Not implemented!")
|
||||||
|
|
||||||
|
let data = someProc()
|
||||||
|
assert data.isOk == false
|
||||||
|
assert data.error == "Not implemented!"
|
||||||
|
|
||||||
test "Check changing result":
|
test "Check changing result":
|
||||||
proc checker(): OP[int] =
|
proc checker(): OP[int] =
|
||||||
result = ok 42
|
result = ok 42
|
||||||
|
|||||||
Reference in New Issue
Block a user