mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 06:20:38 +00:00
more test cases
This commit is contained in:
39
tests/spec/mobjectconstr_unnamed.nim
Normal file
39
tests/spec/mobjectconstr_unnamed.nim
Normal 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")
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user