Mercurial > games > semicongine
comparison tests/test_storage.nim @ 1499:1f58458b7ef7 default tip main
did: fix a few issues with tests
| author | sam <sam@basx.dev> |
|---|---|
| date | Tue, 14 Oct 2025 00:27:28 +0700 |
| parents | 63364723d460 |
| children |
comparison
equal
deleted
inserted
replaced
| 1498:d3d667bbdda4 | 1499:1f58458b7ef7 |
|---|---|
| 1 import std/strformat | 1 import std/strformat |
| 2 import std/sequtils | |
| 2 | 3 |
| 3 import ../semicongine | 4 import ../semicongine |
| 4 import ../semicongine/storage | 5 import ../semicongine/storage |
| 5 | 6 |
| 6 proc testSimple(storage: StorageType) = | 7 proc testSimple(storage: StorageType) = |
| 32 | 33 |
| 33 assert listWorlds().len == 0 | 34 assert listWorlds().len == 0 |
| 34 | 35 |
| 35 const obj1 = Obj1(value: 42, id: ID(1)) | 36 const obj1 = Obj1(value: 42, id: ID(1)) |
| 36 "testWorld".storeWorld(obj1) | 37 "testWorld".storeWorld(obj1) |
| 37 assert listWorlds() == @["testWorld"] | 38 assert listWorlds()[0][1] == "testWorld" |
| 38 assert loadWorld[Obj1]("testWorld") == obj1 | 39 var myWorld: Obj1 |
| 40 loadWorld[Obj1]("testWorld", myWorld) | |
| 41 assert myWorld == obj1 | |
| 39 | 42 |
| 40 const obj2 = Obj2( | 43 const obj2 = Obj2( |
| 41 a: "Hello world", | 44 a: "Hello world", |
| 42 b: Obj1(value: 20, id: ID(20)), | 45 b: Obj1(value: 20, id: ID(20)), |
| 43 c: @[1, 2, 3, 4], | 46 c: @[1, 2, 3, 4], |
| 45 Obj1(value: 1, id: ID(11)), Obj1(value: 2, id: ID(22)), Obj1(value: 3, id: ID(33)) | 48 Obj1(value: 1, id: ID(11)), Obj1(value: 2, id: ID(22)), Obj1(value: 3, id: ID(33)) |
| 46 ], | 49 ], |
| 47 e: true, | 50 e: true, |
| 48 ) | 51 ) |
| 49 "testWorld".storeWorld(obj2) | 52 "testWorld".storeWorld(obj2) |
| 50 assert listWorlds() == @["testWorld"] | 53 assert listWorlds()[0][1] == "testWorld" |
| 51 assert loadWorld[Obj2]("testWorld") == obj2 | 54 var otherWorld: Obj2 |
| 55 loadWorld[Obj2]("testWorld", otherWorld) | |
| 56 assert otherWorld == obj2 | |
| 52 | 57 |
| 53 "earth".storeWorld(obj2) | 58 "earth".storeWorld(obj2) |
| 54 assert "earth" in listWorlds() | 59 assert "earth" in listWorlds().mapIt(it[1]) |
| 55 assert "testWorld" in listWorlds() | 60 assert "testWorld" in listWorlds().mapIt(it[1]) |
| 56 assert loadWorld[Obj2]("earth") == obj2 | 61 var moreWorld: Obj2 |
| 62 loadWorld[Obj2]("earth", moreWorld) | |
| 63 assert moreWorld == obj2 | |
| 57 | 64 |
| 58 "earth".purgeWorld() | 65 "earth".purgeWorld() |
| 59 assert listWorlds() == @["testWorld"] | 66 assert listWorlds()[0][1] == "testWorld" |
| 60 | 67 |
| 61 "testWorld".purgeWorld() | 68 "testWorld".purgeWorld() |
| 62 assert listWorlds().len == 0 | 69 assert listWorlds().len == 0 |
| 63 | 70 |
| 64 proc stressTest(storage: StorageType) = | 71 proc stressTest(storage: StorageType) = |
