fix #85 lynon empty list encoding
This commit is contained in:
parent
bfffea7e69
commit
678cfbf45e
@ -127,9 +127,11 @@ open class LynonEncoder(val bout: BitOutput, val settings: LynonSettings = Lynon
|
||||
*/
|
||||
suspend fun encodeAnyList(scope: Scope, list: List<Obj>,fixedSize: Boolean = false) {
|
||||
if( list.isEmpty()) {
|
||||
// any-typed, empty, save space
|
||||
putBit(0)
|
||||
encodeUnsigned(0u)
|
||||
// Empty list: we still need to write the heterogenous/homogenous flag bit
|
||||
// but must NOT write the size when fixedSize is provided, as decoder will
|
||||
// use the provided size and won't read it from the stream.
|
||||
putBit(0) // treat empty lists as heterogeneous
|
||||
if (!fixedSize) encodeUnsigned(0u)
|
||||
}
|
||||
else {
|
||||
val objClass = list[0].objClass
|
||||
|
||||
@ -4013,6 +4013,13 @@ class ScriptTest {
|
||||
assertEquals( TestJson4(TestEnum.One), x)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringLast() = runTest {
|
||||
eval("""
|
||||
assertEquals('t', "assert".last())
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogicalNot() = runTest {
|
||||
eval("""
|
||||
|
||||
@ -778,6 +778,19 @@ class Wallet( id, ownerKey, balance=0, createdAt=Instant.now().truncateToSecond(
|
||||
assert( Lynon.encode(Poin3(1,2)).size <= 110)
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLyngDecodeResult() = runTest {
|
||||
val a = eval("""
|
||||
[Map(),Map(),Map()]
|
||||
""".trimIndent())
|
||||
val b = lynonDecodeAny(Scope(), lynonEncodeAny(Scope(), a))
|
||||
assertEquals(a, b )
|
||||
// val c = b.decodeSerializable<JsonElement>()
|
||||
// println(c)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user