-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expand tests and reintroduce mismatch error messages
- Loading branch information
Showing
6 changed files
with
155 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import ../traitor | ||
import balls | ||
|
||
type RaiseNothing = distinct tuple[doThing: proc(_: Atom){.nimcall, raises: [], noSideEffect.}] | ||
implTrait RaiseNothing | ||
|
||
proc doThing(i: int) = | ||
raise newException(ValueError, "bleh") | ||
|
||
proc doThing(i: float) = discard | ||
|
||
proc doThing(s: string) = echo s | ||
|
||
|
||
|
||
type RaiseValue = distinct tuple[doStuff: proc(_: Atom){.nimcall, raises: [ValueError].}] | ||
|
||
implTrait RaiseValue | ||
|
||
proc doStuff(i: float) = raise (ref ValueError)() | ||
|
||
proc doStuff(s: string) = raise (ref ValueError)() | ||
|
||
proc doStuff(s: bool) = discard | ||
|
||
suite "Proc annotations": | ||
test "raise nothing": | ||
discard 3d.toTrait RaiseNothing | ||
check not compiles(10.toTrait RaiseNothing) | ||
check not compiles("hmm".toTrait RaiseNothing) | ||
|
||
test "raise value": | ||
expect ValueError, 3d.toTrait(RaiseValue).doStuff() | ||
expect ValueError, "".toTrait(RaiseValue).doStuff() | ||
false.toTrait(RaiseValue).doStuff() | ||
|
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 |
---|---|---|
|
@@ -12,3 +12,5 @@ srcDir = "" | |
requires "nim >= 2.0.0" | ||
requires "micros >= 0.1.5" | ||
|
||
taskRequires "test", "balls >= 5.0.0" | ||
|