[wip] experiments with `if..is` and `if..of` re: #210
This commit is contained in:
parent
7f076e1451
commit
f6137266a0
|
@ -151,35 +151,154 @@ proc runSuite(cache: bool) =
|
||||||
|
|
||||||
# PASS!
|
# PASS!
|
||||||
when getRes.error is (ref CatchableError):
|
when getRes.error is (ref CatchableError):
|
||||||
|
check: true
|
||||||
echo "PASS: when getRes.error is (ref CatchableError)"
|
echo "PASS: when getRes.error is (ref CatchableError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
check: getRes.error.msg == "Block not in database"
|
check: getRes.error.msg == "Block not in database"
|
||||||
echo "NOTE: I am sure msg string is what we expect: " & getRes.error.msg
|
|
||||||
else:
|
else:
|
||||||
check: false
|
check: false
|
||||||
|
|
||||||
# FAIL!
|
# sanity check
|
||||||
when getRes.error is CatchableError:
|
when getRes.error is CatchableError:
|
||||||
check: true
|
check: true
|
||||||
else:
|
else:
|
||||||
echo "FAIL: when getRes.error is CatchableError"
|
|
||||||
check: false
|
check: false
|
||||||
echo "NOTE: this is only sanity check for ref vs. non-ref, but msg string is still what we expect: " & getRes.error.msg
|
echo "FAIL: when getRes.error is CatchableError"
|
||||||
|
echo "NOTE: sanity check for ref vs. non-ref; msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
|
# `when..is` does not work for error types that inherit from
|
||||||
|
# CatchableError, need to use a runtime check not a compile-time check
|
||||||
|
|
||||||
# FAIL!
|
# FAIL!
|
||||||
when getRes.error is (ref CodexError):
|
when getRes.error is (ref CodexError):
|
||||||
check: true
|
check: true
|
||||||
else:
|
else:
|
||||||
echo "FAIL: when getRes.error is (ref CodexError)"
|
|
||||||
check: false
|
check: false
|
||||||
echo "NOTE: msg string is still what we expect: " & getRes.error.msg
|
echo "FAIL: when getRes.error is (ref CodexError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
# FAIL!
|
# FAIL!
|
||||||
when getRes.error is (ref BlockNotFoundError):
|
when getRes.error is (ref BlockNotFoundError):
|
||||||
check: true
|
check: true
|
||||||
else:
|
else:
|
||||||
echo "FAIL: when getRes.error is (ref BlockNotFoundError)"
|
|
||||||
check: false
|
check: false
|
||||||
echo "NOTE: msg string is still what we expect: " & getRes.error.msg
|
echo "FAIL: when getRes.error is (ref BlockNotFoundError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error is (ref CatchableError):
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error is (ref CatchableError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# sanity check
|
||||||
|
if getRes.error is CatchableError:
|
||||||
|
check: true
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
echo "FAIL: if getRes.error is CatchableError"
|
||||||
|
echo "NOTE: sanity check for ref vs. non-ref; msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
|
# `if..is` does not work either
|
||||||
|
|
||||||
|
# FAIL!
|
||||||
|
if getRes.error is (ref CodexError):
|
||||||
|
check: true
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
echo "FAIL: if getRes.error is (ref CodexError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
|
if getRes.error is (ref BlockNotFoundError):
|
||||||
|
check: true
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
echo "FAIL: if getRes.error is (ref BlockNotFoundError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
|
# `case..of` does not compile with `of [type]` or `of (ref [type])`
|
||||||
|
# but `if..of` does work!
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error of (ref CatchableError):
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error of (ref CatchableError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error of CatchableError:
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error of CatchableError"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error of (ref CodexError):
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error of (ref CodexError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error of CodexError:
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error of CodexError"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error of (ref BlockNotFoundError):
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error of (ref BlockNotFoundError)"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# PASS!
|
||||||
|
if getRes.error of BlockNotFoundError:
|
||||||
|
check: true
|
||||||
|
echo "PASS: if getRes.error of BlockNotFoundError"
|
||||||
|
echo "NOTE: msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
|
||||||
|
# sanity check
|
||||||
|
if getRes.error of (ref ValueError):
|
||||||
|
check: true
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
echo "FAIL: if getRes.error of (ref ValueError)"
|
||||||
|
echo "NOTE: sanity check for error type not in inheritance chain; msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
|
# sanity check
|
||||||
|
if getRes.error of ValueError:
|
||||||
|
check: true
|
||||||
|
else:
|
||||||
|
check: false
|
||||||
|
echo "FAIL: if getRes.error of ValueError"
|
||||||
|
echo "NOTE: sanity check for error type not in inheritance chain; msg string is what we expect: " & getRes.error.msg
|
||||||
|
check: getRes.error.msg == "Block not in database"
|
||||||
|
|
||||||
test "hasBlock":
|
test "hasBlock":
|
||||||
let
|
let
|
||||||
|
|
Loading…
Reference in New Issue