WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package kotlinx.serialization

import kotlinx.serialization.json.*
import kotlinx.serialization.test.*
import kotlin.test.*

class JsonPathTest : JsonTestBase() {
Expand Down Expand Up @@ -36,8 +35,7 @@ class JsonPathTest : JsonTestBase() {
fun testUnknownKeyIsProperlyReported() {
expectPath("$.i") { Json.decodeFromString<Outer>("""{"a":42, "i":{"foo":42}""") }
expectPath("$") { Json.decodeFromString<Outer>("""{"x":{}, "a": 42}""") }
// The only place we have misattribution in
// Json.decodeFromString<Outer>("""{"a":42, "x":{}}""")
expectPath("$") { Json.decodeFromString<Outer>("""{"a":42, "x":{}}""") }
}

@Test
Expand Down Expand Up @@ -117,26 +115,23 @@ class JsonPathTest : JsonTestBase() {
class DoubleNesting(val f: Sealed, val f2: Sealed) : Sealed()
}

// TODO use non-array polymorphism when https://github.com/Kotlin/kotlinx.serialization/issues/1839 is fixed
@Test
fun testHugeNestingToCheckResize() = jvmOnly {
fun testHugeNestingToCheckResize() {
val json = Json { useArrayPolymorphism = true }
var outer = Sealed.Nesting(Sealed.Box("value"))
repeat(100) {
outer = Sealed.Nesting(outer)
}
val str = json.encodeToString(Sealed.serializer(), outer)
// throw-away data
json.decodeFromString(Sealed.serializer(), str)

val malformed = str.replace("\"value\"", "42")
val expectedPath = "$" + ".value.f".repeat(101) + ".value.s"
expectPath(expectedPath) { json.decodeFromString(Sealed.serializer(), malformed) }
}

@Test
fun testDoubleNesting() = jvmOnly {
val json = Json { useArrayPolymorphism = true }
fun testDoubleNestingNoArrayPoly() {
val json = Json { useArrayPolymorphism = false }
var outer1 = Sealed.Nesting(Sealed.Box("correct"))
repeat(64) {
outer1 = Sealed.Nesting(outer1)
Expand All @@ -148,11 +143,9 @@ class JsonPathTest : JsonTestBase() {
}

val str = json.encodeToString(Sealed.serializer(), Sealed.DoubleNesting(outer1, outer2))
// throw-away data
json.decodeFromString(Sealed.serializer(), str)

val malformed = str.replace("\"incorrect\"", "42")
val expectedPath = "$.value.f2" + ".value.f".repeat(34) + ".value.s"
val expectedPath = "$.f2" + ".f".repeat(34) + ".s"
expectPath(expectedPath) { json.decodeFromString(Sealed.serializer(), malformed) }
}

Expand Down