summaryrefslogtreecommitdiff
path: root/runtime/commonTest/src/kotlinx/serialization/cbor/CborWriterTest.kt
blob: 397ea00c7f6649efe73000c48a16af287b07626b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright 2017 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package kotlinx.serialization.cbor

import kotlinx.serialization.dumps
import kotlinx.serialization.test.shouldBe
import kotlin.test.Test
import kotlin.test.assertEquals


class CborWriterTest {
    @Test
    fun writeSimpleClass() {
        Cbor.dumps(Simple.serializer(), Simple("str")) shouldBe "bf616163737472ff"
    }

    @Test
    fun writeComplicatedClass() {
        val test = SmallZoo(
                "Hello, world!",
                42,
                null,
                listOf("a", "b"),
                mapOf(1 to true, 2 to false),
                Simple("lol"),
                listOf(Simple("kek"))
        )
        Cbor.dumps(SmallZoo.serializer(), test) shouldBe "bf637374726d48656c6c6f2c20776f726c64216169182a686e756c6c61626c65f6646c6973749f61616162ff636d6170bf01f502f4ff65696e6e6572bf6161636c6f6cff6a696e6e6572734c6973749fbf6161636b656bffffff"
    }

    @Test
    fun writeManyNumbers() {
        val test = NumberZoo(
                100500,
                Long.MAX_VALUE,
                42.0f,
                1235621356215.0,
                true,
                'a'
        )
        Cbor.dumps(NumberZoo.serializer(), test) shouldBe "bf63696e741a00018894646c6f6e671b7fffffffffffffff65666c6f6174fa4228000066646f75626c65fb4271fb0c5a2b700067626f6f6c65616ef564636861721861ff"
    }
}