1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
discard """
output: '''{"columns":[{"t":null},{"t":null}]}
{"columns":[{"t":null},{"t":null}]}
'''
"""
## Tests javascript object generation
type
Kg = distinct float
Price = int
Item = object of RootObj
weight: Kg
price: Price
desc: cstring
Person = object of RootObj
name: cstring
age: int
item: Item
Test = object
name: cstring
Recurse[T] = object
data: T
next: ref Recurse[T]
var
test = Test(name: "Jorden")
sword = Item(desc: "pointy", weight: Kg(10.0),
price: Price(50))
knight = Person(name: "robert", age: 19, item: sword)
recurse4 = (ref Recurse[int])(data: 4, next: nil)
recurse3 = (ref Recurse[int])(data: 3, next: recurse4)
recurse2 = (ref Recurse[int])(data: 2, next: recurse3)
recurse1 = Recurse[int](data: 1, next: recurse2)
doAssert test.name == cstring"Jorden"
doAssert knight.age == 19
doAssert knight.item.price == 50
doAssert recurse1.next.next.data == 3
# bug #6035
proc toJson*[T](data: T): cstring {.importc: "JSON.stringify".}
type
Column = object
t: ref Column
Test2 = object
columns: seq[Column]
var test1 = Test2(columns: @[Column(t: nil), Column(t: nil)])
let test2 = test1
echo toJSON(test1)
echo toJSON(test2)
block issue10005:
type
Player = ref object of RootObj
id*: string
nickname*: string
color*: string
proc newPlayer(nickname: string, color: string): Player =
let pl = Player(color: "#123", nickname: nickname)
return Player(
id: "foo",
nickname: nickname,
color: color,
)
doAssert newPlayer("foo", "#1232").nickname == "foo"
|