mp_bintools/src/wasmJsTest/kotlin/StorageTest.kt
sergeych d29bf960aa - no caching on stored delegates, fix problens with memory storage connections
+ optStored now properly load/store only non-null values
* possible concurrent modification in KVStorage.clear fixed
2024-11-30 13:37:20 +07:00

37 lines
927 B
Kotlin

import net.sergeych.bintools.*
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
class StorageTest {
@Test
fun storageTest() {
val s1 = defaultNamedStorage("test_mp_bintools")
for (n in s1.keys.toList()) s1.delete(n)
assertTrue(s1.keys.isEmpty())
var foo by s1("unknown")
assertEquals(foo, "unknown")
foo = "bar"
assertEquals(foo, "bar")
var answer by s1.optStored<Int>()
assertNull(answer)
answer = 42
assertEquals(answer, 42)
answer = 43
val s2 = defaultNamedStorage("test_mp_bintools")
val foo1 by s2.stored("?", "foo")
val answer1: Int? by s2.optStored("answer")
assertEquals("bar", foo1)
assertEquals(43, answer1)
for (i in 0..<13) {
s2.write("test_$i", "payload_$i")
}
}
}