Skip to content

Commit

Permalink
Commonize new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Jun 1, 2023
1 parent 7fb7803 commit 8742bdf
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.livefront.sealedenum.compilation.usecases

import kotlin.test.Test
import kotlin.test.assertEquals

class FlagTests {
@Test
fun two_objects_sealed_class() {
assertEquals(
listOf(Flag.FirstFlag, Flag.SecondFlag),
FlagSealedEnum.values
)
}

@Test
fun two_enums_for_sealed_class() {
assertEquals(
listOf(
FlagEnum.Flag_FirstFlag,
FlagEnum.Flag_SecondFlag
),
enumValues<FlagEnum>().toList()
)
}

@Test
fun two_enums_for_sealed_class_with_mapping() {
assertEquals(
Flag.values.map(Flag::enum),
enumValues<FlagEnum>().toList()
)
}

@Test
fun correct_enum_class() {
assertEquals(FlagEnum::class, FlagSealedEnum.enumClass)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.livefront.sealedenum.compilation.usecases

import kotlin.test.Test
import kotlin.test.assertEquals

class MultiInterfaceFlagTests {
@Test
fun three_objects_sealed_interface() {
assertEquals(
listOf(MultiInterfaceFlag.BothFlags, MultiInterfaceFlag.FirstFlag, MultiInterfaceFlag.SecondFlag),
MultiInterfaceFlag.values
)
}

@Test
fun three_enums_for_sealed_class() {
assertEquals(
listOf(
MultiInterfaceFlagEnum.MultiInterfaceFlag_BothFlags,
MultiInterfaceFlagEnum.MultiInterfaceFlag_FirstFlag,
MultiInterfaceFlagEnum.MultiInterfaceFlag_SecondFlag
),
enumValues<MultiInterfaceFlagEnum>().toList()
)
}

@Test
fun three_enums_for_sealed_interface_with_mapping() {
assertEquals(
MultiInterfaceFlag.values.map(MultiInterfaceFlag::enum),
enumValues<MultiInterfaceFlagEnum>().toList()
)
}

@Test
fun correct_enum_class() {
assertEquals(MultiInterfaceFlagEnum::class, MultiInterfaceFlagSealedEnum.enumClass)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,9 @@ import com.livefront.sealedenum.testing.assertCompiles
import com.livefront.sealedenum.testing.assertGeneratedFileMatches
import com.livefront.sealedenum.testing.compile
import com.livefront.sealedenum.testing.getSourceFile
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class FlagTests {
@Test
fun `two objects sealed class`() {
assertEquals(
listOf(Flag.FirstFlag, Flag.SecondFlag),
FlagSealedEnum.values
)
}

@Test
fun `two enums for sealed class`() {
assertEquals(
listOf(
FlagEnum.Flag_FirstFlag,
FlagEnum.Flag_SecondFlag
),
enumValues<FlagEnum>().toList()
)
}

@Test
fun `two enums for sealed class with mapping`() {
assertEquals(
Flag.values.map(Flag::enum),
enumValues<FlagEnum>().toList()
)
}

@Test
fun `correct enum class`() {
assertEquals(FlagEnum::class, FlagSealedEnum.enumClass)
}

class FlagCompilationTests {
@Test
fun `compilation generates correct code`() {
val result = compile(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.livefront.sealedenum.compilation.usecases

import com.livefront.sealedenum.testing.PlatformSourceType
import com.livefront.sealedenum.testing.SharableProcessingSourceType
import com.livefront.sealedenum.testing.assertCompiles
import com.livefront.sealedenum.testing.assertGeneratedFileMatches
import com.livefront.sealedenum.testing.compile
import com.livefront.sealedenum.testing.getSourceFile
import org.junit.jupiter.api.Test

class MultiInterfaceFlagCompilationTests {
@Test
fun `compilation generates correct code`() {
val result = compile(
getSourceFile(
SharableProcessingSourceType.COMMMON,
PlatformSourceType.COMMON,
"compilation",
"usecases",
"MultiInterfaceFlag.kt"
)
)

assertCompiles(result)
assertGeneratedFileMatches("MultiInterfaceFlag_SealedEnum.kt", multiInterfaceFlagGenerated, result)
}
}

This file was deleted.

0 comments on commit 8742bdf

Please sign in to comment.