From 688139f9bf8afdebe1346e7e263d78c01955c277 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sun, 11 Sep 2022 16:47:12 +0200 Subject: [PATCH] add inline value class tests --- .../navigationcompose/typed/internal/RoutePatternTest.kt | 4 +++- .../typed/internal/UriBundleDecoderTest.kt | 4 ++++ .../navigationcompose/typed/internal/UriEncoderTest.kt | 6 ++++++ .../typed/internal/helpers/ArticleId.kt | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/helpers/ArticleId.kt diff --git a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/RoutePatternTest.kt b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/RoutePatternTest.kt index 33750c9..f5ba52f 100644 --- a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/RoutePatternTest.kt +++ b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/RoutePatternTest.kt @@ -2,6 +2,7 @@ package com.kiwi.navigationcompose.typed.internal import com.kiwi.navigationcompose.typed.Destination import com.kiwi.navigationcompose.typed.createRoutePattern +import com.kiwi.navigationcompose.typed.internal.helpers.ArticleId import com.kiwi.navigationcompose.typed.internal.helpers.SubClass import com.kiwi.navigationcompose.typed.internal.helpers.SubObject import com.kiwi.navigationcompose.typed.internal.helpers.SubSealed @@ -31,10 +32,11 @@ internal class RoutePatternTest { val l: SubClass = SubClass(12), val m: SubObject, val n: SubSealed = SubSealed.B(13), + val o: ArticleId, ) : Destination Assert.assertEquals( - "com.kiwi.navigationcompose.typed.internal.RoutePatternTest.test.TestData/{a}/{c}/{g}/{i}/{k}/{m}?b={b}&d={d}&e={e}&f={f}&h={h}&j={j}&l={l}&n={n}", + "com.kiwi.navigationcompose.typed.internal.RoutePatternTest.test.TestData/{a}/{c}/{g}/{i}/{k}/{m}/{o}?b={b}&d={d}&e={e}&f={f}&h={h}&j={j}&l={l}&n={n}", createRoutePattern(), ) } diff --git a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriBundleDecoderTest.kt b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriBundleDecoderTest.kt index 4006ae7..fb1d49b 100644 --- a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriBundleDecoderTest.kt +++ b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriBundleDecoderTest.kt @@ -2,6 +2,7 @@ package com.kiwi.navigationcompose.typed.internal import androidx.core.os.bundleOf import com.kiwi.navigationcompose.typed.Destination +import com.kiwi.navigationcompose.typed.internal.helpers.ArticleId import com.kiwi.navigationcompose.typed.internal.helpers.SubClass import com.kiwi.navigationcompose.typed.internal.helpers.SubObject import com.kiwi.navigationcompose.typed.internal.helpers.SubSealed @@ -33,6 +34,7 @@ internal class UriBundleDecoderTest { val l: SubClass, val m: SubObject, val n: SubSealed, + val o: ArticleId, ) : Destination @Test @@ -48,6 +50,7 @@ internal class UriBundleDecoderTest { "l" to """{"int":12}""", "m" to "{}", "n" to """{"type":"com.kiwi.navigationcompose.typed.internal.helpers.SubSealed.B","int":13}""", + "o" to "\"14\"", ) val decoder = UriBundleDecoder(bundle) @@ -67,5 +70,6 @@ internal class UriBundleDecoderTest { Assert.assertEquals(12, data.l.int) Assert.assertEquals(SubObject, data.m) Assert.assertEquals(13, (data.n as? SubSealed.B)?.int) + Assert.assertEquals(ArticleId("14"), data.o) } } diff --git a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriEncoderTest.kt b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriEncoderTest.kt index c30a620..b05f4f1 100644 --- a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriEncoderTest.kt +++ b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/UriEncoderTest.kt @@ -1,6 +1,7 @@ package com.kiwi.navigationcompose.typed.internal import android.net.Uri +import com.kiwi.navigationcompose.typed.internal.helpers.ArticleId import com.kiwi.navigationcompose.typed.internal.helpers.SubClass import com.kiwi.navigationcompose.typed.internal.helpers.SubObject import com.kiwi.navigationcompose.typed.internal.helpers.SubSealed @@ -34,6 +35,7 @@ internal class UriEncoderTest { val l: SubClass, val m: SubObject, val n: SubSealed, + val o: ArticleId, ) val url = Uri.Builder() @@ -53,6 +55,7 @@ internal class UriEncoderTest { l = SubClass(12), m = SubObject, n = SubSealed.B(13), + o = ArticleId("14"), ) encoder.encodeSerializableValue(serializer(), testData) @@ -72,6 +75,7 @@ internal class UriEncoderTest { appendPath("""{"int":12}""") appendPath("{}") appendPath("""{"type":"com.kiwi.navigationcompose.typed.internal.helpers.SubSealed.B","int":13}""") + appendPath("\"14\"") } Assert.assertEquals(expectedUrl.toString(), url.toString()) } @@ -95,6 +99,7 @@ internal class UriEncoderTest { val l: SubClass? = null, val m: SubObject? = SubObject, val n: SubSealed? = null, + val o: ArticleId? = ArticleId("14"), ) val url = Uri.Builder() @@ -111,6 +116,7 @@ internal class UriEncoderTest { appendQueryParameter("i", "7") appendQueryParameter("k", """{"10":"11"}""") appendQueryParameter("m", "{}") + appendQueryParameter("o", "\"14\"") } Assert.assertEquals(expectedUrl.toString(), url.toString()) } diff --git a/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/helpers/ArticleId.kt b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/helpers/ArticleId.kt new file mode 100644 index 0000000..ab325ff --- /dev/null +++ b/core/src/test/kotlin/com/kiwi/navigationcompose/typed/internal/helpers/ArticleId.kt @@ -0,0 +1,9 @@ +package com.kiwi.navigationcompose.typed.internal.helpers + +import kotlinx.serialization.Serializable + +@Serializable +@JvmInline +internal value class ArticleId( + val id: String, +)