diff options
author | Leonid Startsev <sandwwraith@users.noreply.github.com> | 2023-07-24 16:14:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-24 16:14:19 +0200 |
commit | 245030b1b8f2eefe41feb2e5d5baf4aeba37b08f (patch) | |
tree | 2f22f362be96bbd3841e4b793ceff531d2c28d00 /formats/json-tests | |
parent | e41097eb9abafcb7df818ca2d58cdc928bc22311 (diff) | |
download | kotlinx.serialization-245030b1b8f2eefe41feb2e5d5baf4aeba37b08f.tar.gz |
Update to Kotlin 1.9.0: (#2364)
- Apply @ExperimentalNativeApi on WeakReference usages
- Drop Legacy JS compiler as it is deprecated
- Update API Dump with .entries enum properties
- Update yarn.lock
Diffstat (limited to 'formats/json-tests')
23 files changed, 95 insertions, 130 deletions
diff --git a/formats/json-tests/build.gradle.kts b/formats/json-tests/build.gradle.kts index f84336ca..9ae4247b 100644 --- a/formats/json-tests/build.gradle.kts +++ b/formats/json-tests/build.gradle.kts @@ -12,14 +12,6 @@ plugins { apply(from = rootProject.file("gradle/native-targets.gradle")) apply(from = rootProject.file("gradle/configure-source-sets.gradle")) -tasks.withType<Kotlin2JsCompile> { - if (this.name == "compileTestKotlinJsLegacy") { - this.exclude("**/PropertyInitializerTest.kt") - // Partially custom serializers without 'implicit customisation by companion' annotation are not supported on Legacy JS - this.exclude("**/PartiallyCustomSerializerTest.kt", "**/JsonCustomSerializersTest.kt") - } -} - // disable kover tasks because there are no non-test classes in the project tasks.named("koverHtmlReport") { enabled = false diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializerForNullableTypeTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializerForNullableTypeTest.kt index 89ae8bb0..98f3f5e0 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializerForNullableTypeTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializerForNullableTypeTest.kt @@ -112,7 +112,6 @@ public class SerializerForNullableTypeTest : JsonTestBase() { @Test fun testGenericBoxNullable() { - if (isJsLegacy()) return val data = GenericBox<StringHolder?>(null) val json = Json.encodeToString(data) assertEquals("""{"value":"nullable"}""", Json.encodeToString(data)) @@ -121,13 +120,11 @@ public class SerializerForNullableTypeTest : JsonTestBase() { @Test fun testGenericNullableBoxFromNull() { - if (isJsLegacy()) return assertEquals(GenericBox(StringHolder("nullable")), Json.decodeFromString("""{"value":null}""")) } @Test fun testGenericNullableBoxNullable() { - if (isJsLegacy()) return val data = GenericNullableBox<StringHolder>(null) val json = Json.encodeToString(data) assertEquals("""{"value":"nullable"}""", Json.encodeToString(data)) @@ -136,7 +133,6 @@ public class SerializerForNullableTypeTest : JsonTestBase() { @Test fun testGenericBoxNullableFromNull() { - if (isJsLegacy()) return assertEquals(GenericNullableBox(StringHolder("nullable")), Json.decodeFromString("""{"value":null}""")) } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt index 3d95019f..4b4aebfd 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt @@ -53,7 +53,7 @@ class SerializersLookupTest : JsonTestBase() { } @Test - fun testUnsigned() = noLegacyJs { + fun testUnsigned() { assertSame(UByte.serializer(), serializer<UByte>()) assertSame(UShort.serializer(), serializer<UShort>()) assertSame(UInt.serializer(), serializer<UInt>()) @@ -130,19 +130,19 @@ class SerializersLookupTest : JsonTestBase() { } @Test - fun testTriple() = noLegacyJs { // because of Box + fun testTriple() { val myTriple = Triple("1", 2, Box(42)) assertSerializedWithType("""{"first":"1","second":2,"third":{"boxed":42}}""", myTriple) } @Test - fun testLookupDuration() = noLegacyJs { + fun testLookupDuration() { assertNotNull(serializerOrNull(typeOf<Duration>())) assertSame(Duration.serializer(), serializer<Duration>()) } @Test - fun testCustomGeneric() = noLegacyJs { + fun testCustomGeneric() { val intBox = Box(42) val intBoxSerializer = serializer<Box<Int>>() assertEquals(Box.serializer(Int.serializer()).descriptor, intBoxSerializer.descriptor) @@ -152,13 +152,13 @@ class SerializersLookupTest : JsonTestBase() { } @Test - fun testRecursiveGeneric() = noLegacyJs { + fun testRecursiveGeneric() { val boxBox = Box(Box(Box(IntData(42)))) assertSerializedWithType("""{"boxed":{"boxed":{"boxed":{"intV":42}}}}""", boxBox) } @Test - fun testMixedGeneric() = noLegacyJs { + fun testMixedGeneric() { val listOfBoxes = listOf(Box("foo"), Box("bar")) assertSerializedWithType("""[{"boxed":"foo"},{"boxed":"bar"}]""", listOfBoxes) val boxedList = Box(listOf("foo", "bar")) @@ -170,10 +170,8 @@ class SerializersLookupTest : JsonTestBase() { assertSerializedWithType("[1,2,3]", Array<Int>(3) { it + 1 }, default) assertSerializedWithType("""["1","2","3"]""", Array<String>(3) { (it + 1).toString() }, default) assertSerializedWithType("[[0],[1],[2]]", Array<Array<Int>>(3) { cnt -> Array(1) { cnt } }, default) - noLegacyJs { - assertSerializedWithType("""[{"boxed":"foo"}]""", Array(1) { Box("foo") }, default) - assertSerializedWithType("""[[{"boxed":"foo"}]]""", Array(1) { Array(1) { Box("foo") } }, default) - } + assertSerializedWithType("""[{"boxed":"foo"}]""", Array(1) { Box("foo") }, default) + assertSerializedWithType("""[[{"boxed":"foo"}]]""", Array(1) { Array(1) { Box("foo") } }, default) } @Test @@ -187,7 +185,7 @@ class SerializersLookupTest : JsonTestBase() { } @Test - fun testSerializableObject() = noLegacyJs { + fun testSerializableObject() { assertSerializedWithType("{}", SampleObject) } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonClassDiscriminatorTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonClassDiscriminatorTest.kt index 93719c31..5eebe218 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonClassDiscriminatorTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonClassDiscriminatorTest.kt @@ -8,7 +8,6 @@ import kotlinx.serialization.* import kotlinx.serialization.builtins.* import kotlinx.serialization.json.* import kotlinx.serialization.modules.* -import kotlinx.serialization.test.noLegacyJs import kotlin.test.* class JsonClassDiscriminatorTest : JsonTestBase() { @@ -38,7 +37,7 @@ class JsonClassDiscriminatorTest : JsonTestBase() { @Test - fun testSealedClassesHaveCustomDiscriminator() = noLegacyJs { + fun testSealedClassesHaveCustomDiscriminator() { val messages = listOf( SealedMessage.StringMessage("string message", "foo"), SealedMessage.EOF @@ -53,7 +52,7 @@ class JsonClassDiscriminatorTest : JsonTestBase() { } @Test - fun testAbstractClassesHaveCustomDiscriminator() = noLegacyJs { + fun testAbstractClassesHaveCustomDiscriminator() { val messages = listOf( AbstractMessage.StringMessage("string message", "foo"), AbstractMessage.IntMessage("int message", 42), @@ -67,7 +66,11 @@ class JsonClassDiscriminatorTest : JsonTestBase() { val json = Json { serializersModule = module } val expected = """[{"abstractType":"Message.StringMessage","description":"string message","message":"foo"},{"abstractType":"Message.IntMessage","description":"int message","message":42}]""" - assertJsonFormAndRestored(ListSerializer(AbstractMessage.serializer()), messages, expected, json) + assertJsonFormAndRestored( + ListSerializer( + AbstractMessage.serializer() + ), messages, expected, json + ) } @Serializable @@ -90,7 +93,7 @@ class JsonClassDiscriminatorTest : JsonTestBase() { @Test - fun testDocumentationInheritanceSample() = noLegacyJs { + fun testDocumentationInheritanceSample() { val module = SerializersModule { polymorphic(Base::class) { subclass(BaseMessage.serializer()) diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonEnumsCaseInsensitiveTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonEnumsCaseInsensitiveTest.kt index 2f4d4bd6..0e802c19 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonEnumsCaseInsensitiveTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonEnumsCaseInsensitiveTest.kt @@ -37,7 +37,7 @@ class JsonEnumsCaseInsensitiveTest: JsonTestBase() { val json = Json(default) { decodeEnumsCaseInsensitive = true } @Test - fun testCases() = noLegacyJs { parametrizedTest { mode -> + fun testCases() = parametrizedTest { mode -> val input = """{"cases":["ALL_CAPS","all_caps","mixed","MIXED","miXed","all_lower","ALL_LOWER","all_Lower","hasAltNames","HASALTNAMES","altname","ALTNAME","AltName","SERIAL_NAME","serial_name"]}""" val target = listOf( @@ -64,23 +64,23 @@ class JsonEnumsCaseInsensitiveTest: JsonTestBase() { """{"cases":["ALL_CAPS","ALL_CAPS","MiXed","MiXed","MiXed","all_lower","all_lower","all_lower","hasAltNames","hasAltNames","hasAltNames","hasAltNames","hasAltNames","SERIAL_NAME","SERIAL_NAME"]}""", encoded ) - }} + } @Test - fun testTopLevelList() = noLegacyJs { parametrizedTest { mode -> + fun testTopLevelList() = parametrizedTest { mode -> val input = """["all_caps","serial_name"]""" val decoded = json.decodeFromString<List<Cases>>(input, mode) assertEquals(listOf(Cases.ALL_CAPS, Cases.hasSerialName), decoded) assertEquals("""["ALL_CAPS","SERIAL_NAME"]""", json.encodeToString(decoded, mode)) - }} + } @Test - fun testTopLevelEnum() = noLegacyJs { parametrizedTest { mode -> + fun testTopLevelEnum() = parametrizedTest { mode -> val input = """"altName"""" val decoded = json.decodeFromString<Cases>(input, mode) assertEquals(Cases.hasAltNames, decoded) assertEquals(""""hasAltNames"""", json.encodeToString(decoded, mode)) - }} + } @Test fun testSimpleCase() = parametrizedTest { mode -> @@ -93,7 +93,7 @@ class JsonEnumsCaseInsensitiveTest: JsonTestBase() { enum class E { VALUE_A, @JsonNames("ALTERNATIVE") VALUE_B } @Test - fun testDocSample() = noLegacyJs { + fun testDocSample() { val j = Json { decodeEnumsCaseInsensitive = true } @Serializable @@ -152,11 +152,10 @@ class JsonEnumsCaseInsensitiveTest: JsonTestBase() { @Test fun testLowercaseClashThrowsException() = parametrizedTest { mode -> assertFailsWithMessage<SerializationException>("""The suggested name 'bad' for enum value BAD is already one of the names for enum value Bad""") { - // an explicit serializer is required for JSLegacy - json.decodeFromString(Box.serializer(BadEnum.serializer()),"""{"boxed":"bad"}""", mode) + json.decodeFromString<Box<BadEnum>>("""{"boxed":"bad"}""", mode) } assertFailsWithMessage<SerializationException>("""The suggested name 'bad' for enum value BAD is already one of the names for enum value Bad""") { - json.decodeFromString(Box.serializer(BadEnum.serializer()),"""{"boxed":"unrelated"}""", mode) + json.decodeFromString<Box<BadEnum>>("""{"boxed":"unrelated"}""", mode) } } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamesTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamesTest.kt index 6a4e33ad..34044191 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamesTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamesTest.kt @@ -54,7 +54,7 @@ class JsonNamesTest : JsonTestBase() { } @Test - fun testEnumSupportsAlternativeNames() = noLegacyJs { + fun testEnumSupportsAlternativeNames() { val input = """{"enumList":["VALUE_A", "someValue", "some_value", "VALUE_B"], "checkCoercion":"someValue"}""" val expected = WithEnumNames( listOf( @@ -70,14 +70,14 @@ class JsonNamesTest : JsonTestBase() { } @Test - fun topLevelEnumSupportAlternativeNames() = noLegacyJs { + fun topLevelEnumSupportAlternativeNames() { parameterizedCoercingTest { json, streaming, msg -> assertEquals(AlternateEnumNames.VALUE_A, json.decodeFromString("\"someValue\"", streaming), msg) } } @Test - fun testParsesAllAlternativeNames() = noLegacyJs { + fun testParsesAllAlternativeNames() { for (input in listOf(inputString1, inputString2)) { parameterizedCoercingTest { json, streaming, _ -> val data = json.decodeFromString(WithNames.serializer(), input, jsonTestingMode = streaming) @@ -87,7 +87,7 @@ class JsonNamesTest : JsonTestBase() { } @Test - fun testThrowsAnErrorOnDuplicateNames() = noLegacyJs { + fun testThrowsAnErrorOnDuplicateNames() { val serializer = CollisionWithAlternate.serializer() parameterizedCoercingTest { json, streaming, _ -> assertFailsWithMessage<SerializationException>( diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamingStrategyTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamingStrategyTest.kt index 68f36def..28a4d121 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamingStrategyTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonNamingStrategyTest.kt @@ -132,7 +132,7 @@ class JsonNamingStrategyTest : JsonTestBase() { data class CollisionCheckAlternate(val testCase: String, @JsonNames("test_case") val testCase2: String) @Test - fun testNamingStrategyPrioritizesOverAlternative() = noLegacyJs { // @JsonNames not supported on legacy + fun testNamingStrategyPrioritizesOverAlternative() { val json = Json(jsonWithNaming) { ignoreUnknownKeys = true } @@ -153,7 +153,7 @@ class JsonNamingStrategyTest : JsonTestBase() { data class OriginalAsFallback(@JsonNames("testCase") val testCase: String) @Test - fun testCanUseOriginalNameAsAlternative() = noLegacyJs { // @JsonNames not supported on legacy + fun testCanUseOriginalNameAsAlternative() { val json = Json(jsonWithNaming) { ignoreUnknownKeys = true } @@ -181,7 +181,7 @@ class JsonNamingStrategyTest : JsonTestBase() { data class Holder(val testBase: SealedBase, val testMid: SealedBase.SealedMid) @Test - fun testNamingStrategyDoesNotAffectPolymorphism() = noLegacyJs { // @JsonClassDiscriminator + fun testNamingStrategyDoesNotAffectPolymorphism() { val json = Json(jsonWithNaming) { classDiscriminator = "typeBase" } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/LocalClassesTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/LocalClassesTest.kt index b20c7193..82a5ca64 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/LocalClassesTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/LocalClassesTest.kt @@ -1,16 +1,11 @@ package kotlinx.serialization.features import kotlinx.serialization.* -import kotlinx.serialization.descriptors.PrimitiveKind -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.descriptors.buildSerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.Json -import kotlinx.serialization.test.jvmOnly -import kotlinx.serialization.test.noLegacyJs -import kotlin.test.Test -import kotlin.test.assertEquals +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* +import kotlinx.serialization.json.* +import kotlinx.serialization.test.* +import kotlin.test.* class LocalClassesTest { object ObjectCustomSerializer: KSerializer<Any?> { @@ -42,10 +37,8 @@ class LocalClassesTest { val origin = Local(42) - noLegacyJs { - val decoded: Local = Json.decodeFromString(Json.encodeToString(origin)) - assertEquals(origin, decoded) - } + val decoded: Local = Json.decodeFromString(Json.encodeToString(origin)) + assertEquals(origin, decoded) } @Test @@ -56,10 +49,8 @@ class LocalClassesTest { val origin = Local(it) - noLegacyJs { - val decoded: Local = Json.decodeFromString(Json.encodeToString(origin)) - assertEquals(origin, decoded) - } + val decoded: Local = Json.decodeFromString(Json.encodeToString(origin)) + assertEquals(origin, decoded) } } @@ -71,10 +62,8 @@ class LocalClassesTest { val origin: Local? = null - noLegacyJs { - val decoded: Local? = Json.decodeFromString(Json.encodeToString(origin)) - assertEquals(origin, decoded) - } + val decoded: Local? = Json.decodeFromString(Json.encodeToString(origin)) + assertEquals(origin, decoded) } @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/PolymorphicOnClassesTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/PolymorphicOnClassesTest.kt index 8e859ee2..ea59f32a 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/PolymorphicOnClassesTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/PolymorphicOnClassesTest.kt @@ -136,7 +136,7 @@ class PolymorphicOnClassesTest { fun testSerializerLookupForInterface() { // On JVM and JS IR it can be supported via reflection/runtime hacks // on Native, unfortunately, only with intrinsics. - if (currentPlatform == Platform.NATIVE || currentPlatform == Platform.JS_LEGACY) return + if (isNative()) return val msgSer = serializer<IMessage>() assertEquals(IMessage::class, (msgSer as AbstractPolymorphicSerializer).baseClass) } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/SkipDefaults.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/SkipDefaults.kt index ee37b4b8..a7fea75f 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/SkipDefaults.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/SkipDefaults.kt @@ -7,7 +7,6 @@ package kotlinx.serialization.features import kotlinx.serialization.* import kotlinx.serialization.EncodeDefault.Mode.* import kotlinx.serialization.json.* -import kotlinx.serialization.test.noLegacyJs import kotlin.test.* class SkipDefaultsTest { @@ -59,7 +58,7 @@ class SkipDefaultsTest { } @Test - fun encodeDefaultsAnnotationWithFlag() = noLegacyJs { + fun encodeDefaultsAnnotationWithFlag() { val data = DifferentModes() assertEquals("""{"a":"a","b":"b","c":"c"}""", jsonEncodeDefaults.encodeToString(data)) assertEquals("""{"b":"b","c":"c"}""", jsonDropDefaults.encodeToString(data)) diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/EncodeInlineElementTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/EncodeInlineElementTest.kt index 56a7f3d2..aa4866f4 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/EncodeInlineElementTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/EncodeInlineElementTest.kt @@ -41,8 +41,8 @@ object WithUnsignedSerializer : KSerializer<WithUnsigned> { class EncodeInlineElementTest { @Test - fun wrapper() = noLegacyJs { + fun wrapper() { val w = WithUnsigned(Int.MAX_VALUE.toUInt() + 1.toUInt()) - assertStringFormAndRestored("""{"u":2147483648}""", w, WithUnsignedSerializer, printResult = true) + assertStringFormAndRestored<WithUnsigned>("""{"u":2147483648}""", w, WithUnsignedSerializer, printResult = true) } } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesCompleteTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesCompleteTest.kt index 363bdaf9..96972f92 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesCompleteTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesCompleteTest.kt @@ -61,7 +61,7 @@ data class WithGenerics( class InlineClassesCompleteTest { @Test - fun testAllVariantsWithoutNull() = noLegacyJs { + fun testAllVariantsWithoutNull() { val withAll = WithAll( MyInt(1), MyInt(2), @@ -72,15 +72,15 @@ class InlineClassesCompleteTest { OverSerializableNullable(IntData(7)), OverSerializableNullable(IntData(8)), WithT(Box(9)), - WithT<Int>(Box(10)), - WithT<Int?>(Box(11)), - WithTNullable<Int?>(Box(12)) + WithT(Box(10)), + WithT(Box(11)), + WithTNullable(Box(12)) ) assertSerializedAndRestored(withAll, WithAll.serializer()) } @Test - fun testAllVariantsWithNull() = noLegacyJs { + fun testAllVariantsWithNull() { assertSerializedAndRestored( WithAll( MyInt(1), @@ -93,14 +93,14 @@ class InlineClassesCompleteTest { null, WithT(Box(9)), null, - WithT<Int?>(Box(null)), - WithTNullable<Int?>(Box(null)) + WithT(Box(null)), + WithTNullable(Box(null)) ), WithAll.serializer() ) } @Test - fun testAllGenericVariantsWithoutNull() = noLegacyJs { + fun testAllGenericVariantsWithoutNull() { assertSerializedAndRestored( WithGenerics( Box(MyInt(1)), @@ -117,7 +117,7 @@ class InlineClassesCompleteTest { } @Test - fun testAllGenericVariantsWithNull() = noLegacyJs { + fun testAllGenericVariantsWithNull() { assertSerializedAndRestored( WithGenerics( Box(MyInt(1)), diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesTest.kt index 0d30fc11..f3eb9511 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineClassesTest.kt @@ -95,25 +95,25 @@ class InlineClassesTest : JsonTestBase() { private val precedent: UInt = Int.MAX_VALUE.toUInt() + 10.toUInt() @Test - fun withList() = noLegacyJs { + fun withList() { val withList = WithList(listOf(1, 2, 3)) assertJsonFormAndRestored(WithList.serializer(), withList, """[1,2,3]""") } @Test - fun testOuterInner() = noLegacyJs { + fun testOuterInner() { val o = Outer(Inner(10)) assertJsonFormAndRestored(Outer.serializer(), o, """{"n":10}""") } @Test - fun testOuterOuterInner() = noLegacyJs { + fun testOuterOuterInner() { val o = OuterOuter(Outer(Inner(10))) assertJsonFormAndRestored(OuterOuter.serializer(), o, """{"outer":{"n":10}}""") } @Test - fun testTopLevel() = noLegacyJs { + fun testTopLevel() { assertJsonFormAndRestored( ResourceType.serializer(), ResourceType("foo"), @@ -122,7 +122,7 @@ class InlineClassesTest : JsonTestBase() { } @Test - fun testTopLevelOverEnum() = noLegacyJs { + fun testTopLevelOverEnum() { assertJsonFormAndRestored( ResourceKind.serializer(), ResourceKind(SampleEnum.OptionC), @@ -131,7 +131,7 @@ class InlineClassesTest : JsonTestBase() { } @Test - fun testTopLevelWrapper() = noLegacyJs { + fun testTopLevelWrapper() { assertJsonFormAndRestored( ValueWrapper.serializer(), ValueWrapper(ResourceType("foo")), @@ -140,7 +140,7 @@ class InlineClassesTest : JsonTestBase() { } @Test - fun testTopLevelContextual() = noLegacyJs { + fun testTopLevelContextual() { val module = SerializersModule { contextual<ResourceType>(ResourceType.serializer()) } @@ -155,7 +155,7 @@ class InlineClassesTest : JsonTestBase() { @Test - fun testSimpleContainer() = noLegacyJs { + fun testSimpleContainer() { assertJsonFormAndRestored( SimpleContainerForUInt.serializer(), SimpleContainerForUInt(precedent), @@ -171,7 +171,7 @@ class InlineClassesTest : JsonTestBase() { ) @Test - fun testSimpleContainerForList() = noLegacyJs { + fun testSimpleContainerForList() { assertJsonFormAndRestored( ContainerForList.serializer(UInt.serializer()), ContainerForList(MyList(listOf(precedent))), @@ -180,7 +180,7 @@ class InlineClassesTest : JsonTestBase() { } @Test - fun testInlineClassesWithStrings() = noLegacyJs { + fun testInlineClassesWithStrings() { assertJsonFormAndRestored( ResourceIdentifier.serializer(), ResourceIdentifier(ResourceId("resId"), ResourceType("resType"), ValueWrapper(ResourceType("wrappedType"))), diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineMapQuotedTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineMapQuotedTest.kt index 53461bfd..63157d12 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineMapQuotedTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/InlineMapQuotedTest.kt @@ -48,7 +48,7 @@ class InlineMapQuotedTest : JsonTestBase() { ) @Test - fun testInlineClassAsMapKey() = noLegacyJs { + fun testInlineClassAsMapKey() { println(Long.MAX_VALUE.toULong() + 2UL) val c = Carrier( mapOf(1L to 1L), @@ -58,7 +58,7 @@ class InlineMapQuotedTest : JsonTestBase() { mapOf(CustomULong(Long.MAX_VALUE.toULong() + 5UL) to 5L) ) assertJsonFormAndRestored( - serializer(), + serializer<Carrier>(), c, """{"mapLong":{"1":1},"mapULong":{"9223372036854775809":2},"wrappedLong":{"3":3},"mapWrappedU":{"9223372036854775811":4},"mapCustom":{"9223372036854775812":5}}""" ) diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/ValueClassesInSealedHierarchyTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/ValueClassesInSealedHierarchyTest.kt index f3b482f1..ed968298 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/ValueClassesInSealedHierarchyTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/inline/ValueClassesInSealedHierarchyTest.kt @@ -12,7 +12,7 @@ import kotlin.test.* class ValueClassesInSealedHierarchyTest : JsonTestBase() { @Test - fun testSingle() = noLegacyJs { + fun testSingle() { val single = "foo" assertJsonFormAndRestored( AnyValue.serializer(), @@ -22,7 +22,7 @@ class ValueClassesInSealedHierarchyTest : JsonTestBase() { } @Test - fun testComplex() = noLegacyJs { + fun testComplex() { val complexJson = """{"id":"1","name":"object"}""" assertJsonFormAndRestored( AnyValue.serializer(), @@ -32,9 +32,13 @@ class ValueClassesInSealedHierarchyTest : JsonTestBase() { } @Test - fun testMulti() = noLegacyJs { + fun testMulti() { val multiJson = """["list","of","strings"]""" - assertJsonFormAndRestored(AnyValue.serializer(), AnyValue.Multi(listOf("list", "of", "strings")), multiJson) + assertJsonFormAndRestored( + AnyValue.serializer(), + AnyValue.Multi(listOf("list", "of", "strings")), + multiJson + ) } } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesJsonSerializationTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesJsonSerializationTest.kt index da05cc0e..a2e6bb67 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesJsonSerializationTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesJsonSerializationTest.kt @@ -29,7 +29,7 @@ class SealedInterfacesJsonSerializationTest : JsonTestBase() { object NoResponse: I @Test - fun testSealedInterfaceJson() = noLegacyJs { + fun testSealedInterfaceJson() { val messages = listOf(Response.ResponseInt(10), NoResponse, Response.ResponseString("foo")) assertJsonFormAndRestored( serializer(), diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonMapKeysTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonMapKeysTest.kt index 868e3adc..61f31de9 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonMapKeysTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonMapKeysTest.kt @@ -71,10 +71,8 @@ class JsonMapKeysTest : JsonTestBase() { @Test fun testStructuredMapKeysShouldBeProhibitedByDefault() = parametrizedTest { streaming -> - noLegacyJs { - verifyProhibition(WithComplexKey(mapOf(IntData(42) to "42")), streaming) - verifyProhibition(WithComplexValueKey(mapOf(ComplexCarrier(IntData(42)) to "42")), streaming) - } + verifyProhibition(WithComplexKey(mapOf(IntData(42) to "42")), streaming) + verifyProhibition(WithComplexValueKey(mapOf(ComplexCarrier(IntData(42)) to "42")), streaming) } private inline fun <reified T: Any> verifyProhibition(value: T, streaming: JsonTestingMode) { @@ -92,7 +90,7 @@ class JsonMapKeysTest : JsonTestBase() { ) @Test - fun testStructuredValueMapKeysAllowedWithFlag() = noLegacyJs { + fun testStructuredValueMapKeysAllowedWithFlag() { assertJsonFormAndRestored( WithComplexValueKey.serializer(), WithComplexValueKey(mapOf(ComplexCarrier(IntData(42)) to "42")), @@ -110,7 +108,7 @@ class JsonMapKeysTest : JsonTestBase() { ) @Test - fun testPrimitivesAreAllowedAsValueMapKeys() = noLegacyJs { + fun testPrimitivesAreAllowedAsValueMapKeys() { assertJsonFormAndRestored( WithValueKeyMap.serializer(), WithValueKeyMap(mapOf(PrimitiveCarrier("fooKey") to 1)), @@ -120,7 +118,7 @@ class JsonMapKeysTest : JsonTestBase() { } @Test - fun testContextualValuePrimitivesAreAllowedAsValueMapKeys() = noLegacyJs { + fun testContextualValuePrimitivesAreAllowedAsValueMapKeys() { assertJsonFormAndRestored( WithContextualValueKey.serializer(), WithContextualValueKey(mapOf(PrimitiveCarrier("fooKey") to 1)), diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonModesTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonModesTest.kt index 97993802..e7f107c8 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonModesTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonModesTest.kt @@ -120,11 +120,9 @@ class JsonModesTest : JsonTestBase() { @Test fun testIgnoreUnknownKeysObject() = parametrizedTest { jsonTestingMode -> - noLegacyJs { - assertEquals(Holder(Object), lenient.decodeFromString("""{"o":{}}""", jsonTestingMode)) - assertEquals(Holder(Object), lenient.decodeFromString("""{"o":{"unknown":{"b":"c"}}}""", jsonTestingMode)) - assertEquals(Object, lenient.decodeFromString("""{}""", jsonTestingMode)) - assertEquals(Object, lenient.decodeFromString("""{"o":{"unknown":{"b":"c"}}}""", jsonTestingMode)) - } + assertEquals(Holder(Object), lenient.decodeFromString("""{"o":{}}""", jsonTestingMode)) + assertEquals(Holder(Object), lenient.decodeFromString("""{"o":{"unknown":{"b":"c"}}}""", jsonTestingMode)) + assertEquals(Object, lenient.decodeFromString("""{}""", jsonTestingMode)) + assertEquals(Object, lenient.decodeFromString("""{"o":{"unknown":{"b":"c"}}}""", jsonTestingMode)) } } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt index c4a6b986..92cf087f 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/test/CurrentPlatform.common.kt @@ -5,12 +5,11 @@ package kotlinx.serialization.test enum class Platform { - JVM, JS_LEGACY, JS_IR, NATIVE + JVM, JS, NATIVE } public expect val currentPlatform: Platform -public fun isJs(): Boolean = currentPlatform == Platform.JS_LEGACY || currentPlatform == Platform.JS_IR -public fun isJsLegacy(): Boolean = currentPlatform == Platform.JS_LEGACY +public fun isJs(): Boolean = currentPlatform == Platform.JS public fun isJvm(): Boolean = currentPlatform == Platform.JVM public fun isNative(): Boolean = currentPlatform == Platform.NATIVE diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/test/TestHelpers.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/test/TestHelpers.kt index 04af40c6..27ac19f1 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/test/TestHelpers.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/test/TestHelpers.kt @@ -34,10 +34,6 @@ inline fun noJs(test: () -> Unit) { if (!isJs()) test() } -inline fun noLegacyJs(test: () -> Unit) { - if (!isJsLegacy()) test() -} - inline fun jvmOnly(test: () -> Unit) { if (isJvm()) test() } diff --git a/formats/json-tests/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt b/formats/json-tests/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt index 0af00c66..3ff05ba0 100644 --- a/formats/json-tests/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt +++ b/formats/json-tests/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt @@ -8,7 +8,6 @@ import kotlinx.serialization.* import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.polymorphic import kotlinx.serialization.modules.subclass -import kotlinx.serialization.test.noLegacyJs import kotlin.test.Test import kotlin.test.assertEquals @@ -85,7 +84,7 @@ class DynamicPolymorphismTest { } @Test - fun testCustomClassDiscriminator() = noLegacyJs { + fun testCustomClassDiscriminator() { val value = SealedCustom.DataClassChild("custom-discriminator-test") encodeAndDecode(SealedCustom.serializer(), value, objectJson) { assertEquals("data_class", this["sealed_custom"]) diff --git a/formats/json-tests/jsTest/src/kotlinx/serialization/json/JsonNamesDynamicTest.kt b/formats/json-tests/jsTest/src/kotlinx/serialization/json/JsonNamesDynamicTest.kt index 09cf3d4a..0c519fc2 100644 --- a/formats/json-tests/jsTest/src/kotlinx/serialization/json/JsonNamesDynamicTest.kt +++ b/formats/json-tests/jsTest/src/kotlinx/serialization/json/JsonNamesDynamicTest.kt @@ -29,7 +29,7 @@ class JsonNamesDynamicTest { } @Test - fun testParsesAllAlternativeNamesDynamic() = noLegacyJs { + fun testParsesAllAlternativeNamesDynamic() { for (input in listOf(inputString1, inputString2)) { parameterizedCoercingTest { json, msg -> val data = json.decodeFromDynamic(JsonNamesTest.WithNames.serializer(), input) @@ -39,7 +39,7 @@ class JsonNamesDynamicTest { } @Test - fun testEnumSupportsAlternativeNames() = noLegacyJs { + fun testEnumSupportsAlternativeNames() { val input = js("""{"enumList":["VALUE_A", "someValue", "some_value", "VALUE_B"], "checkCoercion":"someValue"}""") val expected = JsonNamesTest.WithEnumNames( listOf( @@ -55,14 +55,14 @@ class JsonNamesDynamicTest { } @Test - fun topLevelEnumSupportAlternativeNames() = noLegacyJs { + fun topLevelEnumSupportAlternativeNames() { parameterizedCoercingTest { json, msg -> assertEquals(JsonNamesTest.AlternateEnumNames.VALUE_A, json.decodeFromDynamic(js("\"someValue\"")), msg) } } @Test - fun testThrowsAnErrorOnDuplicateNames2() = noLegacyJs { + fun testThrowsAnErrorOnDuplicateNames2() { val serializer = JsonNamesTest.CollisionWithAlternate.serializer() parameterizedCoercingTest { json, _ -> assertFailsWithMessage<SerializationException>( diff --git a/formats/json-tests/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt b/formats/json-tests/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt index b87276e8..23627d17 100644 --- a/formats/json-tests/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt +++ b/formats/json-tests/jsTest/src/kotlinx/serialization/test/CurrentPlatform.kt @@ -4,9 +4,4 @@ package kotlinx.serialization.test -public actual val currentPlatform: Platform = if (isLegacyBackend()) Platform.JS_LEGACY else Platform.JS_IR - -// from https://github.com/JetBrains/kotlin/blob/569187a7516e2e5ab217158a3170d4beb0c5cb5a/js/js.translator/testData/_commonFiles/testUtils.kt#L3 -private fun isLegacyBackend(): Boolean = - // Using eval to prevent DCE from thinking that following code depends on Kotlin module. - eval("(typeof Kotlin != \"undefined\" && typeof Kotlin.kotlin != \"undefined\")").unsafeCast<Boolean>() +public actual val currentPlatform: Platform = Platform.JS |