@@ -14,6 +14,7 @@ import net.aquadc.persistence.extended.partial
14
14
import net.aquadc.persistence.struct.Schema
15
15
import net.aquadc.persistence.struct.Struct
16
16
import net.aquadc.persistence.struct.build
17
+ import net.aquadc.persistence.tokens.Token
17
18
import net.aquadc.persistence.tokens.readAs
18
19
import net.aquadc.persistence.tokens.readListOf
19
20
import net.aquadc.persistence.tokens.tokens
@@ -31,11 +32,13 @@ import net.aquadc.persistence.type.set
31
32
import net.aquadc.persistence.type.string
32
33
import net.aquadc.properties.persistence.enum
33
34
import okio.ByteString.Companion.decodeHex
35
+ import org.junit.Assert.assertArrayEquals
34
36
import org.junit.Assert.assertEquals
35
37
import org.junit.Assert.assertNotSame
36
38
import org.junit.Assert.assertSame
37
39
import org.junit.Test
38
40
import java.io.StringWriter
41
+ import java.util.Base64
39
42
import java.util.EnumSet
40
43
41
44
@@ -153,8 +156,8 @@ class PersistenceTest {
153
156
)
154
157
}
155
158
156
- val smallSchema = Tuple3 (" a" , string, " b" , string, " c" , string)
157
- val partialSmallSchema = partial(smallSchema)
159
+ private val smallSchema = Tuple3 (" a" , string, " b" , string, " c" , string)
160
+ private val partialSmallSchema = partial(smallSchema)
158
161
159
162
@Test fun `json empty partial` () {
160
163
assertEquals(
@@ -238,6 +241,27 @@ class PersistenceTest {
238
241
)
239
242
}
240
243
244
+ @Test fun coercions () {
245
+ val blob = byteArrayOf(1 , 2 , 3 )
246
+ val base = Base64 .getEncoder().encodeToString(blob)
247
+ val tokens = """ {"1":"456.789","$base ":"123"}""" .reader().json().tokens()
248
+
249
+ tokens.poll(Token .BeginDictionary )
250
+
251
+ assertEquals(Token .Str , tokens.peek())
252
+ assertEquals(1 , tokens.poll(Token .I32 ))
253
+
254
+ assertEquals(Token .Str , tokens.peek())
255
+ assertEquals(456.789 , tokens.poll(Token .F64 ))
256
+
257
+ assertEquals(Token .Str , tokens.peek())
258
+ assertArrayEquals(blob, tokens.poll(Token .Blob ) as ByteArray )
259
+
260
+ assertEquals(Token .Str , tokens.peek())
261
+ assertEquals(123 , tokens.poll(Token .I32 ))
262
+
263
+ }
264
+
241
265
private fun <T > read (json : String , type : DataType <T >, lenient : Boolean = false): T =
242
266
json.reader().json().also {
243
267
it.isLenient = lenient
0 commit comments