diff old_tests/test_storage.nim @ 1203:6360c8d17ce0 compiletime-tests

did: preprations to add rendering tests
author sam <sam@basx.dev>
date Mon, 15 Jul 2024 20:06:42 +0700
parents tests/test_storage.nim@114f395b9144
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/old_tests/test_storage.nim	Mon Jul 15 20:06:42 2024 +0700
@@ -0,0 +1,39 @@
+import std/strformat
+
+import semicongine
+
+proc testSimple(storage: StorageType) =
+  const TEST_VALUE = 42
+  const KEY = "test"
+
+  # get default
+  assert storage.Load(KEY, 0) == default(type(TEST_VALUE))
+
+  # save and load custom
+  Store(storage, KEY, TEST_VALUE)
+  assert storage.Load(KEY, 0) == TEST_VALUE
+
+proc stressTest(storage: StorageType) =
+  for i in 1 .. 10000:
+    let key = &"key-{i}"
+    Store(storage, key, i)
+    assert storage.Load(key, 0) == i
+
+proc main() =
+  SystemStorage.Purge()
+  echo "SystemStorage: Testing simple store/load"
+  SystemStorage.testSimple()
+
+  UserStorage.Purge()
+  echo "UserStorage: Testing simple store/load"
+  UserStorage.testSimple()
+
+  echo "Stress test with 10'000 saves/loads"
+  SystemStorage.stressTest()
+
+  SystemStorage.Purge()
+  UserStorage.Purge()
+
+
+when isMainModule:
+  main()