Skip to content

Commit

Permalink
add inline value class tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Sep 11, 2022
1 parent dee8dec commit 688139f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TestData>(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,6 +34,7 @@ internal class UriBundleDecoderTest {
val l: SubClass,
val m: SubObject,
val n: SubSealed,
val o: ArticleId,
) : Destination

@Test
Expand All @@ -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)
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -34,6 +35,7 @@ internal class UriEncoderTest {
val l: SubClass,
val m: SubObject,
val n: SubSealed,
val o: ArticleId,
)

val url = Uri.Builder()
Expand All @@ -53,6 +55,7 @@ internal class UriEncoderTest {
l = SubClass(12),
m = SubObject,
n = SubSealed.B(13),
o = ArticleId("14"),
)

encoder.encodeSerializableValue(serializer(), testData)
Expand All @@ -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())
}
Expand All @@ -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()
Expand All @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kiwi.navigationcompose.typed.internal.helpers

import kotlinx.serialization.Serializable

@Serializable
@JvmInline
internal value class ArticleId(
val id: String,
)

0 comments on commit 688139f

Please sign in to comment.