Skip to content

Commit cd4606e

Browse files
committed
More tests
1 parent 8c853ed commit cd4606e

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

tests/ser/tmake.nim

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,28 @@ type
3737
discard
3838
3939
SkipIfObject = object
40+
alwaysSkipped {.skipped.}: int
41+
serializeSkipped {.skipSerializing.}: int
4042
text {.skipSerializeIf(isNone).}: Option[string]
4143
4244
SerializeWithObject = object
4345
date {.serializeWith(toTimestamp).}: DateTime
46+
47+
RenameObject = object
48+
name {.renameSerialize("fullname").}: string
49+
50+
User = object
51+
id: int
52+
53+
Pagination = object
54+
limit: int64
55+
offset: int64
56+
total: int64
57+
58+
Users = object
59+
users: seq[User]
60+
pagination {.inlineKeys.}: Pagination
61+
4462
4563
proc serialize[Serializer](self: ref int, serializer: var Serializer) =
4664
serializer.serializeInt(self[])
@@ -54,6 +72,11 @@ makeSerializable(CaseObject)
5472
makeSerializable(UntaggedCaseObject)
5573
makeSerializable(SkipIfObject)
5674
makeSerializable(SerializeWithObject)
75+
makeSerializable(RenameObject)
76+
77+
makeSerializable(User)
78+
makeSerializable(Pagination)
79+
makeSerializable(Users)
5780
5881
suite "makeSerializable":
5982
test "simple":
@@ -98,7 +121,7 @@ suite "makeSerializable":
98121
StructEnd()
99122
]
100123

101-
test "case object":
124+
test "case":
102125
serTokens CaseObject(kind: true, yes: "yes"), [
103126
Struct("CaseObject"),
104127
String("kind"),
@@ -115,7 +138,7 @@ suite "makeSerializable":
115138
StructEnd()
116139
]
117140

118-
test "untagged case object":
141+
test "untagged case":
119142
serTokens UntaggedCaseObject(kind: true, yes: "yes"), [
120143
Struct("UntaggedCaseObject"),
121144
String("yes"),
@@ -128,7 +151,7 @@ suite "makeSerializable":
128151
StructEnd()
129152
]
130153

131-
test "object with skipSerializeIf":
154+
test "skipSerializeIf":
132155
serTokens SkipIfObject(text: some "text"), [
133156
Struct("SkipIfObject"),
134157
String("text"),
@@ -141,11 +164,35 @@ suite "makeSerializable":
141164
StructEnd()
142165
]
143166

144-
test "object with serializeWith":
167+
test "serializeWith":
145168
let date = now()
146169
serTokens SerializeWithObject(date: date), [
147170
Struct("SerializeWithObject"),
148171
String("date"),
149172
Integer(int(date.toTime.toUnix)),
150173
StructEnd()
151174
]
175+
176+
test "renameSerialize":
177+
serTokens RenameObject(name: "Name"), [
178+
Struct("RenameObject"),
179+
String("fullname"),
180+
String("Name"),
181+
StructEnd()
182+
]
183+
184+
test "inlineKeys":
185+
serTokens Users(), [
186+
Struct("Users"),
187+
String("users"),
188+
Seq(some 0),
189+
SeqEnd(),
190+
String("limit"),
191+
Integer(0),
192+
String("offset"),
193+
Integer(0),
194+
String("total"),
195+
Integer(0),
196+
StructEnd()
197+
]
198+

0 commit comments

Comments
 (0)