Skip to content

Commit

Permalink
Merge pull request #8 from SimonMarquis/patch/tests
Browse files Browse the repository at this point in the history
🧪 Add new tests with bounded types
  • Loading branch information
SimonMarquis authored Feb 3, 2023
2 parents 899cd8f + a7755ff commit 851081b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions processor/src/test/kotlin/fr/smarquis/sealed/SealedGenericsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class SealedGenericsTest {
actual = SealedCovariantGeneric::class.sealedObjectInstances(),
)

@SealedObjectInstances
sealed class SealedCovariantBoundedGeneric<out T : Number> {
object INSTANCE : SealedCovariantBoundedGeneric<Long>()
}

@Test
fun `generic covariant with bounded`() = assertEquals(
expected = setOf(SealedCovariantBoundedGeneric.INSTANCE),
actual = SealedCovariantBoundedGeneric::class.sealedObjectInstances(),
)

@SealedObjectInstances
sealed class SealedContravariantGeneric<in T> {
object INSTANCE : SealedContravariantGeneric<String>()
Expand All @@ -50,6 +61,17 @@ class SealedGenericsTest {
actual = SealedContravariantGeneric::class.sealedObjectInstances(),
)

@SealedObjectInstances
sealed class SealedContravariantBoundedGeneric<in T : Number> {
object INSTANCE : SealedContravariantBoundedGeneric<Long>()
}

@Test
fun `generic contravariant bounded`() = assertEquals(
expected = setOf(SealedContravariantBoundedGeneric.INSTANCE),
actual = SealedContravariantBoundedGeneric::class.sealedObjectInstances(),
)

@SealedObjectInstances
sealed class SealedBoundedSingleGeneric<T : Exception> {
object INSTANCE : SealedBoundedSingleGeneric<RuntimeException>()
Expand Down

0 comments on commit 851081b

Please # to comment.