Skip to content

Commit

Permalink
Use Number instead of Int for choice arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
theisenp committed Aug 24, 2023
1 parent 826bcb7 commit f8591a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal fun resolveArgumentType(tokenTypes: List<TokenType>): KClass<*>? =
when (resolveCompatibleTokenType(tokenTypes)) {
null -> null
None -> Any::class
Number, Plural, SpellOut -> KotlinNumber::class
Choice, Number, Plural, SpellOut -> KotlinNumber::class
Date -> LocalDate::class
Time -> LocalTime::class
TimeWithOffset -> OffsetTime::class
Expand All @@ -65,7 +65,7 @@ internal fun resolveArgumentType(tokenTypes: List<TokenType>): KClass<*>? =
DateTimeWithZone -> ZonedDateTime::class
Offset -> ZoneOffset::class
Duration -> KotlinDuration::class
Choice, Ordinal, SelectOrdinal -> Int::class
Ordinal, SelectOrdinal -> Int::class
Select -> String::class
NoArg -> Nothing::class
}
Expand Down Expand Up @@ -109,11 +109,11 @@ private val compatibleTokenTypes: Map<TokenType, List<TokenType>> = mapOf(
DateTimeWithZone to emptyList(),
Offset to listOf(TimeWithOffset, DateTimeWithOffset, DateTimeWithZone),
SpellOut to listOf(Choice, Number, Ordinal, Plural, SelectOrdinal),
Ordinal to listOf(Choice, SelectOrdinal),
Ordinal to listOf(SelectOrdinal),
Duration to emptyList(),
Choice to listOf(Ordinal, SelectOrdinal),
Choice to listOf(Number, Ordinal, Plural, SelectOrdinal, SpellOut),
Plural to listOf(Choice, Number, Ordinal, SelectOrdinal, SpellOut),
Select to emptyList(),
SelectOrdinal to listOf(Choice, Ordinal),
SelectOrdinal to listOf(Ordinal),
NoArg to emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class ArgumentTypeResolverTest {
fun resolveNumber() {
Number.assertArgumentTypes { other ->
when (other) {
None, Number, Plural, SpellOut -> KotlinNumber::class
Choice, Ordinal, SelectOrdinal -> Int::class
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
else -> null
}
}
Expand Down Expand Up @@ -158,8 +158,8 @@ class ArgumentTypeResolverTest {
fun resolveSpellOut() {
SpellOut.assertArgumentTypes { other ->
when (other) {
None, Number, Plural, SpellOut -> KotlinNumber::class
Choice, Ordinal, SelectOrdinal -> Int::class
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
else -> null
}
}
Expand Down Expand Up @@ -189,7 +189,8 @@ class ArgumentTypeResolverTest {
fun resolveChoice() {
Choice.assertArgumentTypes { other ->
when (other) {
None, Choice, Number, Ordinal, Plural, SelectOrdinal, SpellOut -> Int::class
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
else -> null
}
}
Expand All @@ -199,8 +200,8 @@ class ArgumentTypeResolverTest {
fun resolvePlural() {
Plural.assertArgumentTypes { other ->
when (other) {
None, Number, Plural, SpellOut -> KotlinNumber::class
Choice, Ordinal, SelectOrdinal -> Int::class
None, Choice, Number, Plural, SpellOut -> KotlinNumber::class
Ordinal, SelectOrdinal -> Int::class
else -> null
}
}
Expand Down

0 comments on commit f8591a9

Please sign in to comment.