Skip to content

Commit

Permalink
Allow 0 as value on Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jurmous committed Dec 11, 2023
1 parent bc762d0 commit 972f38e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ package maryk.core.properties.enum
interface IndexedEnumComparable<in E> : Comparable<E>, IndexedEnum {
companion object {
internal operator fun invoke(index: UInt, name: String, alternativeNames: Set<String>? = null) = object : IndexedEnumImpl<IndexedEnumComparable<Any>>(index, alternativeNames) {
init {
require(index > 0u) { "Only indices of 1 and higher are allowed" }
}

override val name = name

override fun equals(other: Any?) = other is IndexedEnum && other.index == this.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import maryk.core.query.changes.VersionedChanges
import maryk.core.query.changes.change
import maryk.core.query.pairs.with
import maryk.lib.extensions.initByteArrayByHex
import maryk.test.models.Option.V1
import maryk.test.models.Option.V0
import maryk.test.models.Option.V2
import maryk.test.models.TestMarykModel
import kotlin.test.Test
Expand All @@ -24,7 +24,7 @@ private val valuesAsStorablesWithVersion = arrayOf(
"19" to arrayOf(HLC(1235uL) to 3u),
"21" to arrayOf(HLC(1233uL) to null),
"29" to arrayOf(HLC(1233uL) to LocalDateTime(2018, 7, 18, 0, 0), HLC(1235uL) to null),
"39" to arrayOf(HLC(1234uL) to V2, HLC(1235uL) to V1),
"39" to arrayOf(HLC(1234uL) to V2, HLC(1235uL) to V0),
"4b" to arrayOf(HLC(1233uL) to 1, HLC(1235uL) to 2, HLC(1236uL) to 2),
"4b0480004577" to arrayOf(HLC(1233uL) to LocalDate(2018, 9, 9)),
"4b0480001104" to arrayOf(HLC(1235uL) to LocalDate(1981, 12, 5)),
Expand Down Expand Up @@ -125,7 +125,7 @@ class ReadStorageToChangesKtTest {
TestMarykModel { string::ref } with "hello universe",
TestMarykModel { int::ref } with 7,
TestMarykModel { uint::ref } with 3u,
TestMarykModel { enum::ref } with V1
TestMarykModel { enum::ref } with V0
),
Delete(
TestMarykModel { dateTime::ref },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package maryk.core.properties.enum

import maryk.test.models.MarykEnumEmbedded.E1
import maryk.test.models.Option
import maryk.test.models.Option.V0
import maryk.test.models.Option.V1
import maryk.test.models.Option.V2
import maryk.test.models.Option.V3
Expand All @@ -20,8 +20,8 @@ class IndexedEnumDefinitionTest {
@Test
fun isCompatible() {
assertTrue {
IndexedEnumDefinition("Test", { listOf(V1, V2, V3)}).compatibleWith(
IndexedEnumDefinition("Test", { listOf(V1, V2)})
IndexedEnumDefinition("Test", { listOf(V0, V1, V2, V3)}).compatibleWith(
IndexedEnumDefinition("Test", { listOf(V0, V1, V2)})
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ object CompleteMarykModel : RootDataModel<CompleteMarykModel>(
final = true,
unique = true,
enum = Option,
minValue = Option.V1,
minValue = Option.V0,
maxValue = Option.V3,
default = Option.V1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object CompleteMarykModel : RootDataModel<CompleteMarykModel>(
final = true,
unique = true,
enum = Option,
minValue = Option.V1,
minValue = Option.V0,
maxValue = Option.V3,
default = Option.V1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sealed class Option(
index: UInt,
alternativeNames: Set<String>? = null
) : IndexedEnumImpl<Option>(index, alternativeNames) {
object V0: Option(0u)
object V1: Option(1u)
object V2: Option(2u, setOf("VERSION2"))
object V3: Option(3u, setOf("VERSION3"))
Expand Down

0 comments on commit 972f38e

Please sign in to comment.