Skip to content

Commit eb74666

Browse files
authored
Add some JSON tests (#6741)
1 parent 1e12753 commit eb74666

File tree

1 file changed

+25
-0
lines changed
  • libraries/apollo-api/src/commonTest/kotlin/test

1 file changed

+25
-0
lines changed

libraries/apollo-api/src/commonTest/kotlin/test/JsonTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
@file:OptIn(ApolloInternal::class)
2+
13
package test
24

5+
import com.apollographql.apollo.annotations.ApolloInternal
36
import com.apollographql.apollo.api.AnyAdapter
47
import com.apollographql.apollo.api.CustomScalarAdapters
58
import com.apollographql.apollo.api.LongAdapter
@@ -8,9 +11,11 @@ import com.apollographql.apollo.api.json.MapJsonWriter
811
import com.apollographql.apollo.api.json.buildJsonString
912
import com.apollographql.apollo.api.json.jsonReader
1013
import com.apollographql.apollo.api.json.readAny
14+
import com.apollographql.apollo.exception.JsonEncodingException
1115
import okio.Buffer
1216
import kotlin.test.Test
1317
import kotlin.test.assertEquals
18+
import kotlin.test.assertFailsWith
1419

1520
class JsonTest {
1621
@Test
@@ -63,4 +68,24 @@ class JsonTest {
6368

6469
MapJsonReader(root).readAny()
6570
}
71+
72+
@Test
73+
fun unquotedKeysFails() {
74+
try {
75+
Buffer().writeUtf8("{ foo: \"bar\"}").jsonReader().readAny()
76+
error("an error was expected")
77+
} catch (e: JsonEncodingException) {
78+
assertEquals("Unexpected character: f at path []", e.message)
79+
}
80+
}
81+
82+
@Test
83+
fun singleQuoteStringFails() {
84+
try {
85+
Buffer().writeUtf8("{ \"foo\": 'bar'}").jsonReader().readAny()
86+
error("an error was expected")
87+
} catch (e: JsonEncodingException) {
88+
assertEquals("Unexpected value at path [foo]", e.message)
89+
}
90+
}
6691
}

0 commit comments

Comments
 (0)