Skip to content

Commit

Permalink
(#19) Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasuryat committed Apr 13, 2024
1 parent 351b005 commit 49e124c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 71 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.activity:activity-compose:1.5.1'

implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")

// Dowel
implementation project(":dowel")
ksp project(":dowel-processor")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import com.jayasuryat.dowel.sample.ui.home.model.meta.SomeStaticInfo
import com.jayasuryat.dowel.sample.ui.home.model.sealed.Vehicle
import com.jayasuryat.dowel.sample.ui.home.model.status.Status
import com.jayasuryat.dowel.sample.ui.home.model.unsupported.UnsupportedType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.PersistentSet
import kotlinx.coroutines.flow.Flow

@DowelList(count = 5)
Expand Down Expand Up @@ -59,6 +65,12 @@ data class Person(
@Size(value = 1) val mutablePreferences: MutableMap<Long, Location>,
@Size(value = 2) val preferredLocations: Map<Long, Set<Location>>,
@Size(value = 2) val mutablePreferredLocations: Map<Long, MutableSet<Location>>,
@Size(value = 2) val immutableList: ImmutableList<Int>,
@Size(value = 2) val immutableSet: ImmutableSet<Int>,
@Size(value = 2) val immutableMap: ImmutableMap<Int, Int>,
@Size(value = 2) val persistentList: PersistentList<Int>,
@Size(value = 2) val persistentSet: PersistentSet<Int>,
@Size(value = 2) val persistentMap: PersistentMap<Int, Int>,
val title: Char,
@Size(value = 1) val interests: List<Float>,
val onClick: suspend (a: Person, b: Int) -> Unit,
Expand Down
31 changes: 0 additions & 31 deletions app/src/test/java/com/jayasuryat/dowel/sample/ExampleUnitTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ internal class DowelProcessingTest {
""".trimIndent()
SourceFile.kotlin(name = "PreviewParameterProvider.kt", contents = source)
}

private val ImmutableCollectionsStub: SourceFile by lazy {
val source = """
@file:Suppress("UNUSED_PARAMETER")
package kotlinx.collections.immutable
interface ImmutableList<out E>
interface PersistentList<out E> : ImmutableList<E>
interface ImmutableSet<out E>
interface PersistentSet<out E> : ImmutableSet<E>
interface ImmutableMap<K, out V>
interface PersistentMap<K, out V> : ImmutableMap<K, V>
@Suppress("TestFunctionName", "RedundantSuppression")
fun <E> persistentListOf(vararg elements: E): PersistentList<E> = object : PersistentList<E> {}
fun <E> persistentSetOf(vararg elements: E): PersistentSet<E> = object : PersistentSet<E> {}
fun <K, V> persistentMapOf(vararg pairs: Pair<K, V>): PersistentMap<K, V> = object : PersistentMap<K, V> {}
""".trimIndent()
SourceFile.kotlin(name = "ImmutableCollections.kt", contents = source)
}
// endregion

@Test
Expand Down Expand Up @@ -150,7 +170,11 @@ internal class DowelProcessingTest {
""".trimIndent()

val kotlinSource: SourceFile = SourceFile.kotlin(name = "Person.kt", contents = source)
val result: KotlinCompilation.Result = compile(kotlinSource, PreviewParameterProviderStub)
val result: KotlinCompilation.Result = compile(
kotlinSource,
PreviewParameterProviderStub,
ImmutableCollectionsStub,
)

Assert.assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
Assert.assertEquals("", result.messages)
Expand Down Expand Up @@ -184,7 +208,11 @@ internal class DowelProcessingTest {
}
""".trimIndent()
val kotlinSource: SourceFile = SourceFile.kotlin(name = "Person.kt", contents = source)
val result: KotlinCompilation.Result = compile(kotlinSource, PreviewParameterProviderStub)
val result: KotlinCompilation.Result = compile(
kotlinSource,
PreviewParameterProviderStub,
ImmutableCollectionsStub,
)

Assert.assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
Assert.assertEquals("", result.messages)
Expand Down Expand Up @@ -472,6 +500,7 @@ internal class DowelProcessingTest {
val result: KotlinCompilation.Result = compile(
kotlinSource,
PreviewParameterProviderStub,
ImmutableCollectionsStub,
)

val expectedMessage = """
Expand Down Expand Up @@ -513,6 +542,7 @@ internal class DowelProcessingTest {
val result: KotlinCompilation.Result = compile(
kotlinSource,
PreviewParameterProviderStub,
ImmutableCollectionsStub,
)

val expectedMessage = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,39 @@ internal class DowelWholeEnchiladaProcessingTest {
interface StateFlow<T> : SharedFlow<T>
interface MutableStateFlow<T> : StateFlow<T>, MutableSharedFlow<T>
@Suppress("TestFunctionName", "RedundantSuppression")
@Suppress("TestFunctionName", "RedundantSuppression", "UNUSED_PARAMETER")
fun <T> MutableStateFlow(vararg elements: T): MutableStateFlow<T> = object : MutableStateFlow<T> {}
""".trimIndent()
SourceFile.kotlin(name = "Flow.kt", contents = source)
}

private val ImmutableCollectionsStub: SourceFile by lazy {
val source = """
@file:Suppress("UNUSED_PARAMETER")
package kotlinx.collections.immutable
interface ImmutableList<out E>
interface PersistentList<out E> : ImmutableList<E>
interface ImmutableSet<out E>
interface PersistentSet<out E> : ImmutableSet<E>
interface ImmutableMap<K, out V>
interface PersistentMap<K, out V> : ImmutableMap<K, V>
@Suppress("TestFunctionName", "RedundantSuppression")
fun <E> persistentListOf(vararg elements: E): PersistentList<E> = object : PersistentList<E> {}
fun <E> persistentSetOf(vararg elements: E): PersistentSet<E> = object : PersistentSet<E> {}
fun <K, V> persistentMapOf(vararg pairs: Pair<K, V>): PersistentMap<K, V> = object : PersistentMap<K, V> {}
""".trimIndent()
SourceFile.kotlin(name = "ImmutableCollections.kt", contents = source)
}

private val StateStub: SourceFile by lazy {
val source = """
package androidx.compose.runtime
interface State<T>
interface MutableState<T> : State<T>
@Suppress("UNUSED_PARAMETER")
fun <T> mutableStateOf(value: T): MutableState<T> = object : MutableState<T> {}
""".trimIndent()
SourceFile.kotlin(name = "SnapshotState.kt", contents = source)
Expand Down Expand Up @@ -208,6 +229,7 @@ internal class DowelWholeEnchiladaProcessingTest {
import androidx.compose.runtime.State
import androidx.compose.runtime.MutableState
import kotlinx.coroutines.flow.*
import kotlinx.collections.immutable.*
import dowel.status.Status
import dowel.vehicle.Vehicle
import dowel.static.info.SomeStaticInfo
Expand Down Expand Up @@ -250,6 +272,12 @@ internal class DowelWholeEnchiladaProcessingTest {
val flow3: MutableSharedFlow<Int>,
val flow4: StateFlow<Int>,
val flow5: MutableStateFlow<Int>,
val immutableList: ImmutableList<Int>,
val persistentList: PersistentList<Int>,
val immutableSet: ImmutableSet<Int>,
val persistentSet: PersistentSet<Int>,
val immutableMap: ImmutableMap<Int, Int>,
val persistentMap: PersistentMap<Int, Int>,
val onClick: suspend (a: Person, b: Int) -> Unit,
){
Expand All @@ -269,6 +297,7 @@ internal class DowelWholeEnchiladaProcessingTest {
PreviewParameterProviderStub,
SizeStub,
FlowStub,
ImmutableCollectionsStub,
StateStub,
VehicleSource,
StatusSource,
Expand All @@ -279,6 +308,7 @@ internal class DowelWholeEnchiladaProcessingTest {
)

Assert.assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
Assert.assertEquals("", result.messages)
}

// spotless:on
Expand Down

0 comments on commit 49e124c

Please sign in to comment.