-
Notifications
You must be signed in to change notification settings - Fork 612
/
JsonHugeDataSerializationTest.kt
39 lines (30 loc) · 1.11 KB
/
JsonHugeDataSerializationTest.kt
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
/*
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization.json
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.test.noLegacyJs
import kotlin.test.Test
class JsonHugeDataSerializationTest : JsonTestBase() {
@Serializable
private data class Node(
val children: List<Node>?
)
private fun createNodes(count: Int, depth: Int): List<Node> {
val ret = mutableListOf<Node>()
if (depth == 0) return ret
for (i in 0 until count) {
ret.add(Node(createNodes(1, depth - 1)))
}
return ret
}
@Test
fun test() = noLegacyJs {
// create some huge instance
val rootNode = Node(createNodes(1000, 10))
// Encoding will always be true for a standard `encodeToString` - we leave this assumption so as not to insert a huge string into the sources
val expectedJson = Json.encodeToString(rootNode)
assertJsonFormAndRestored(Node.serializer(), rootNode, expectedJson)
}
}