Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Long parameters for ordinal arguments #235

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
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 @@ -65,7 +65,7 @@ internal fun resolveArgumentType(tokenTypes: List<TokenType>): KClass<*>? =
DateTimeWithZone -> ZonedDateTime::class
Offset -> ZoneOffset::class
Duration -> KotlinDuration::class
Ordinal, SelectOrdinal -> Int::class
Ordinal, SelectOrdinal -> Long::class
Select -> String::class
NoArg -> Nothing::class
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ArgumentTypeResolverTest {
Number.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
Ordinal, SelectOrdinal -> Long::class
else -> null
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ class ArgumentTypeResolverTest {
SpellOut.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
Ordinal, SelectOrdinal -> Long::class
else -> null
}
}
Expand All @@ -169,7 +169,7 @@ class ArgumentTypeResolverTest {
fun resolveOrdinal() {
Ordinal.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Ordinal, Plural, SelectOrdinal, SpellOut -> Int::class
None, Choice, Number, Ordinal, Plural, SelectOrdinal, SpellOut -> Long::class
else -> null
}
}
Expand All @@ -190,7 +190,7 @@ class ArgumentTypeResolverTest {
Choice.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
Ordinal, SelectOrdinal -> Long::class
else -> null
}
}
Expand All @@ -201,7 +201,7 @@ class ArgumentTypeResolverTest {
Plural.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
Ordinal, SelectOrdinal -> Long::class
else -> null
}
}
Expand All @@ -221,7 +221,7 @@ class ArgumentTypeResolverTest {
fun resolveSelectOrdinal() {
SelectOrdinal.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Ordinal, Plural, SelectOrdinal, SpellOut -> Int::class
None, Choice, Number, Ordinal, Plural, SelectOrdinal, SpellOut -> Long::class
else -> null
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/src/main/kotlin/app/cash/paraphrase/tests/TypesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.paraphrase.tests

import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import app.cash.paraphrase.getString
import com.google.common.truth.Truth.assertThat
Expand Down Expand Up @@ -324,6 +325,14 @@ class TypesTest {
assertThat(formattedThree).isEqualTo("A 3rd B")
val formattedFour = context.getString(FormattedResources.type_ordinal(4))
assertThat(formattedFour).isEqualTo("A 4th B")
val formattedLong = context.getString(FormattedResources.type_ordinal(Long.MAX_VALUE))
val expected = if (Build.VERSION.SDK_INT >= 26) {
"9,223,372,036,854,775,807th"
} else {
// ICU versions on older Android platforms lose bits by internally converting Long to Double:
"9,223,372,036,854,776,000th"
}
assertThat(formattedLong).isEqualTo("A $expected B")
}

@Test fun typeSpellout() {
Expand Down