-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nim regression test for canBeImplicit
- Loading branch information
Showing
3 changed files
with
37 additions
and
12 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,33 @@ | ||
import unittest, macros | ||
|
||
type | ||
Person = object | ||
name: string | ||
|
||
ContainerKind = enum | ||
ckString, ckInt, ckBool, ckPerson, ckNone | ||
|
||
Container = object | ||
case kind: ContainerKind | ||
of ckString: | ||
strVal: string | ||
of ckInt: | ||
intVal: int | ||
of ckBool: | ||
boolVal: bool | ||
of ckPerson: | ||
personVal: Person | ||
of ckNone: | ||
discard | ||
|
||
proc canBeImplicit(t: typedesc): string {.compileTime.} = | ||
## returns empty string if type can be implicit, else the reason why it can't | ||
let tDesc = getType(t) | ||
if tDesc.kind != nnkObjectTy: return "type is not an object" | ||
return "" | ||
|
||
suite "Nim Regression Tests": | ||
test "canBeImplicit": | ||
const res = canBeImplicit(Container) | ||
assert len(res) == 0, "unexpected error for canBeImplicit: " & res | ||
|