comparison tests/test_storage.nim @ 1465:7b2ec9f3d0f6

add: external serialization library
author sam <sam@basx.dev>
date Wed, 26 Mar 2025 00:37:50 +0700
parents 3e3192241ea7
children cbca94a95736
comparison
equal deleted inserted replaced
1464:3e3192241ea7 1465:7b2ec9f3d0f6
13 # save and load custom 13 # save and load custom
14 store(storage, KEY, TEST_VALUE) 14 store(storage, KEY, TEST_VALUE)
15 assert storage.load(KEY, 0) == TEST_VALUE 15 assert storage.load(KEY, 0) == TEST_VALUE
16 16
17 proc testWorldAPI() = 17 proc testWorldAPI() =
18 type Obj1 = object
19 value: int
20
21 type Obj2 = object
22 value: string
23
18 assert listWorlds().len == 0 24 assert listWorlds().len == 0
19 25
20 "testWorld".storeWorld(42) 26 const obj1 = Obj1(value: 42)
27 "testWorld".storeWorld(obj1)
21 assert listWorlds() == @["testWorld"] 28 assert listWorlds() == @["testWorld"]
22 assert loadWorld[int]("testWorld") == 42 29 assert loadWorld[Obj1]("testWorld") == obj1
23 30
24 "testWorld".storeWorld("hello") 31 const obj2 = Obj2(value: "Hello world")
32 "testWorld".storeWorld(obj2)
25 assert listWorlds() == @["testWorld"] 33 assert listWorlds() == @["testWorld"]
26 assert loadWorld[string]("testWorld") == "hello" 34 assert loadWorld[Obj2]("testWorld") == obj2
27 35
28 "earth".storeWorld("hello") 36 "earth".storeWorld(obj2)
29 assert "earth" in listWorlds() 37 assert "earth" in listWorlds()
30 assert "testWorld" in listWorlds() 38 assert "testWorld" in listWorlds()
31 assert loadWorld[string]("earth") == "hello" 39 assert loadWorld[Obj2]("earth") == obj2
32 40
33 "earth".purgeWorld() 41 "earth".purgeWorld()
34 assert listWorlds() == @["testWorld"] 42 assert listWorlds() == @["testWorld"]
35 43
36 "testWorld".purgeWorld() 44 "testWorld".purgeWorld()