Mercurial > games > semicongine
comparison tests/test_storage.nim @ 1468:cbca94a95736
add: custom serialization
| author | sam <sam@basx.dev> |
|---|---|
| date | Tue, 01 Apr 2025 00:26:14 +0700 |
| parents | 7b2ec9f3d0f6 |
| children | 63364723d460 |
comparison
equal
deleted
inserted
replaced
| 1466:58b62be1902c | 1468:cbca94a95736 |
|---|---|
| 17 proc testWorldAPI() = | 17 proc testWorldAPI() = |
| 18 type Obj1 = object | 18 type Obj1 = object |
| 19 value: int | 19 value: int |
| 20 | 20 |
| 21 type Obj2 = object | 21 type Obj2 = object |
| 22 value: string | 22 a: string |
| 23 b: Obj1 | |
| 24 c: seq[int] | |
| 25 d: array[3, Obj1] | |
| 26 e: bool | |
| 23 | 27 |
| 24 assert listWorlds().len == 0 | 28 assert listWorlds().len == 0 |
| 25 | 29 |
| 26 const obj1 = Obj1(value: 42) | 30 const obj1 = Obj1(value: 42) |
| 27 "testWorld".storeWorld(obj1) | 31 "testWorld".storeWorld(obj1) |
| 28 assert listWorlds() == @["testWorld"] | 32 assert listWorlds() == @["testWorld"] |
| 29 assert loadWorld[Obj1]("testWorld") == obj1 | 33 assert loadWorld[Obj1]("testWorld") == obj1 |
| 30 | 34 |
| 31 const obj2 = Obj2(value: "Hello world") | 35 const obj2 = Obj2( |
| 36 a: "Hello world", | |
| 37 b: Obj1(value: 20), | |
| 38 c: @[1, 2, 3, 4], | |
| 39 d: [Obj1(value: 1), Obj1(value: 2), Obj1(value: 3)], | |
| 40 e: true, | |
| 41 ) | |
| 32 "testWorld".storeWorld(obj2) | 42 "testWorld".storeWorld(obj2) |
| 33 assert listWorlds() == @["testWorld"] | 43 assert listWorlds() == @["testWorld"] |
| 34 assert loadWorld[Obj2]("testWorld") == obj2 | 44 assert loadWorld[Obj2]("testWorld") == obj2 |
| 35 | 45 |
| 36 "earth".storeWorld(obj2) | 46 "earth".storeWorld(obj2) |
