more test cases

This commit is contained in:
ringabout
2023-03-31 16:38:19 +08:00
parent a891b0d948
commit 1204f4a38e
2 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
type
Standard* = object
name: string
id*: int
owner*: string
Color1* = enum
Red, Blue, Green
Case1* = object
name*: string
id*: int
color*: Color1
owner: string
## inplace object construction works
doAssert Standard("Tree", 1, "sky") == Standard(name: "Tree", id: 1, owner: "sky")
proc initStandard*(name: string, id: int, owner: string): Standard =
Standard(name, id, owner)
## It works in the procs
doAssert initStandard("Tree", 1, "sky") == Standard(name: "Tree", id: 1, owner: "sky")
static: doAssert initStandard("Tree", 1, "sky") == Standard(name: "Tree", id: 1, owner: "sky")
template toStandard*(name: string, id: int, owner: string): Standard =
Standard(name, id, owner)
## It works in the procs
doAssert toStandard("Tree", 1, "sky") == Standard(name: "Tree", id: 1, owner: "sky")
static: doAssert toStandard("Tree", 1, "sky") == Standard(name: "Tree", id: 1, owner: "sky")
proc initColorRed*(name: string = "red", id: int = 1314, owner: string): Case1 =
result = Case1(name, id, Red, owner)
doAssert Case1("red", 1314, color: Red, owner: "unknown") == Case1("red", 1314, color: Red, "unknown")
doAssert Case1("red", 1314, Red, owner: "unknown") == Case1("red", 1314, Red, "unknown")
doAssert initColorRed(owner = "unknown") == Case1("red", id: 1314, Red, "unknown")

View File

@@ -1,3 +1,5 @@
import mobjectconstr_unnamed
type
Vector = object
a: int = 999
@@ -66,3 +68,23 @@ block:
block:
var x = Ciao(12, flag: true, 1, "123")
doAssert x.num == 1
## It works in the third module
block:
doAssert initStandard("", 1, "sky") == Standard(id: 1, owner: "sky")
doAssert initStandard("", 1, "sky") == Standard(1, "sky")
doAssert toStandard("", 1, "sky") == Standard(1, "sky")
proc foo() =
doAssert initStandard("", 1, "sky") == Standard(id: 1, owner: "sky")
doAssert initStandard("", 1, "sky") == Standard(1, "sky")
doAssert toStandard("", 1, "sky") == Standard(1, "sky")
foo()
template bar() =
doAssert initStandard("", 1, "sky") == Standard(id: 1, owner: "sky")
doAssert initStandard("", 1, "sky") == Standard(1, "sky")
doAssert toStandard("", 1, "sky") == Standard(1, "sky")
bar()