Skip to content

Commit

Permalink
Fixed bugs and structured tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoppier committed Jul 3, 2024
1 parent d056f48 commit 00a3ff1
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ class MappieIrTransformer(private val symbols: List<MappieDefinition>) : IrEleme
}
}
} else {
logAll(invalids.first().second.problems, location(declaration))
val first = invalids.firstOrNull()
if (first != null) {
logAll(invalids.first().second.problems, location(declaration))
} else {
logError("No constructor visible to use", location(declaration))
}
}
}
return declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private class MapperReferenceCollector : BaseVisitor<IrFunctionExpression, Unit>
putValueArgument(0, irGet(itParameter))
})
},
IrStatementOrigin.ANONYMOUS_FUNCTION
IrStatementOrigin.LAMBDA
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import java.io.File

class MaperClassCanContainPropertiesTest {
class MapperClassCanContainPropertiesTest {

data class Input(val text: String)
data class Output(val text: String, val int: Int)
Expand All @@ -24,7 +24,7 @@ class MaperClassCanContainPropertiesTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.MaperClassCanContainPropertiesTest.*
import tech.mappie.testing.MapperClassCanContainPropertiesTest.*
class Mapper(private val int: Int) : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import java.io.File

class MaperClassCanContainPropertiesUsedInForListTest {
class MapperClassCanContainPropertiesUsedInForListTest {

data class Input(val text: List<InnerInput>)
data class InnerInput(val text: String)
Expand All @@ -26,7 +26,7 @@ class MaperClassCanContainPropertiesUsedInForListTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.MaperClassCanContainPropertiesUsedInForListTest.*
import tech.mappie.testing.MapperClassCanContainPropertiesUsedInForListTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package tech.mappie.testing
package tech.mappie.testing.enums

import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.containsError
import tech.mappie.testing.loadEnumMappieClass
import java.io.File
import kotlin.test.Test

Expand All @@ -25,7 +27,7 @@ class EnumsWithDifferentEntriesTest {
kotlin("Test.kt",
"""
import tech.mappie.api.EnumMappie
import tech.mappie.testing.EnumsWithDifferentEntriesTest.*
import tech.mappie.testing.enums.EnumsWithDifferentEntriesTest.*
class Mapper : EnumMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down Expand Up @@ -59,7 +61,7 @@ class EnumsWithDifferentEntriesTest {
kotlin("Test.kt",
"""
import tech.mappie.api.EnumMappie
import tech.mappie.testing.EnumsWithDifferentEntriesTest.*
import tech.mappie.testing.enums.EnumsWithDifferentEntriesTest.*
class Mapper : EnumMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down Expand Up @@ -94,7 +96,7 @@ class EnumsWithDifferentEntriesTest {
kotlin("Test.kt",
"""
import tech.mappie.api.EnumMappie
import tech.mappie.testing.EnumsWithDifferentEntriesTest.*
import tech.mappie.testing.enums.EnumsWithDifferentEntriesTest.*
class Mapper : EnumMappie<Input, Output>()
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package tech.mappie.testing
package tech.mappie.testing.enums

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.containsWarning
import tech.mappie.testing.loadEnumMappieClass
import java.io.File
import kotlin.test.Test

Expand All @@ -24,7 +26,7 @@ class EnumsWithSameEntriesTest {
kotlin("Test.kt",
"""
import tech.mappie.api.EnumMappie
import tech.mappie.testing.EnumsWithSameEntriesTest.*
import tech.mappie.testing.enums.EnumsWithSameEntriesTest.*
class Mapper : EnumMappie<Input, Output>()
"""
Expand Down Expand Up @@ -55,7 +57,7 @@ class EnumsWithSameEntriesTest {
kotlin("Test.kt",
"""
import tech.mappie.api.EnumMappie
import tech.mappie.testing.EnumsWithSameEntriesTest.*
import tech.mappie.testing.enums.EnumsWithSameEntriesTest.*
class Mapper : EnumMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tech.mappie.testing
package tech.mappie.testing.enums

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ObjectWithNestedEnumTest {
Expand All @@ -26,7 +27,7 @@ class ObjectWithNestedEnumTest {
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.api.EnumMappie
import tech.mappie.testing.ObjectWithNestedEnumTest.*
import tech.mappie.testing.enums.ObjectWithNestedEnumTest.*
class Mapper : ObjectMappie<Input, Output>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tech.mappie.testing
package tech.mappie.testing.enums

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ObjectWithNestedNullableEnumTest {
Expand All @@ -26,7 +27,7 @@ class ObjectWithNestedNullableEnumTest {
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.api.EnumMappie
import tech.mappie.testing.ObjectWithNestedNullableEnumTest.*
import tech.mappie.testing.enums.ObjectWithNestedNullableEnumTest.*
class Mapper : ObjectMappie<Input, Output>()
Expand Down Expand Up @@ -59,7 +60,7 @@ class ObjectWithNestedNullableEnumTest {
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.api.EnumMappie
import tech.mappie.testing.ObjectWithNestedNullableEnumTest.*
import tech.mappie.testing.enums.ObjectWithNestedNullableEnumTest.*
class Mapper : ObjectMappie<Input, Output>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
package tech.mappie.testing
package tech.mappie.testing.lists

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ObjectWithNestedNonNullToNullTest {
data class Input(val text: InnerInput, val int: Int)
class NonNullListToNullListTest {
data class Input(val text: List<InnerInput>, val int: Int)
data class InnerInput(val value: String)
data class Output(val text: InnerOutput?, val int: Int)
data class Output(val text: List<InnerOutput>?, val int: Int)
data class InnerOutput(val value: String)

@TempDir
private lateinit var directory: File

@Test
fun `map data classes with nested null to non-null using object InnerMapper without declaring mapping should succeed`() {
fun `map data classes with nested null list to non-null list using object InnerMapper without declaring mapping should succeed`() {
KotlinCompilation(directory).apply {
sources = buildList {
add(
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ObjectWithNestedNonNullToNullTest.*
import tech.mappie.testing.lists.NonNullListToNullListTest.*
class Mapper : ObjectMappie<Input, Output>()
object InnerMapper : ObjectMappie<InnerInput, InnerOutput>()
object SecondInnerMapper : ObjectMappie<InnerOutput, InnerInput>()
"""
)
)
Expand All @@ -44,8 +47,8 @@ class ObjectWithNestedNonNullToNullTest {
.first()
.call()

assertThat(mapper.map(Input(InnerInput("value"), 20)))
.isEqualTo(Output(InnerOutput("value"), 20))
assertThat(mapper.map(Input(listOf(InnerInput("first"), InnerInput("second")), 20)))
.isEqualTo(Output(listOf(InnerOutput("first"), InnerOutput("second")), 20))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package tech.mappie.testing
package tech.mappie.testing.lists

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.containsError
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ObjectWithNullToNonNullTest {
class NullToNonNullTest {
data class Input(val value: String?)
data class Output(val value: String)

Expand All @@ -23,7 +25,7 @@ class ObjectWithNullToNonNullTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ObjectWithNullToNonNullTest.*
import tech.mappie.testing.lists.NullToNonNullTest.*
class Mapper : ObjectMappie<Input, Output>()
"""
Expand All @@ -45,7 +47,7 @@ class ObjectWithNullToNonNullTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ObjectWithNullToNonNullTest.*
import tech.mappie.testing.lists.NullToNonNullTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tech.mappie.testing
package tech.mappie.testing.lists

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ObjectWithNestedListTest {
Expand All @@ -25,7 +26,7 @@ class ObjectWithNestedListTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ObjectWithNestedListTest.*
import tech.mappie.testing.lists.ObjectWithNestedListTest.*
class Mapper : ObjectMappie<Input, Output>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tech.mappie.testing
package tech.mappie.testing.lists

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ViaListTest {
Expand All @@ -24,7 +25,7 @@ class ViaListTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ViaListTest.*
import tech.mappie.testing.lists.ViaListTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.mappie.testing
package tech.mappie.testing.objects

import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.com.google.common.base.Objects
Expand All @@ -7,6 +7,8 @@ import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.containsError
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ConstructorParameterNotAFieldTest {
Expand All @@ -30,7 +32,7 @@ class ConstructorParameterNotAFieldTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ConstructorParameterNotAFieldTest.*
import tech.mappie.testing.objects.ConstructorParameterNotAFieldTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand All @@ -55,7 +57,7 @@ class ConstructorParameterNotAFieldTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ConstructorParameterNotAFieldTest.*
import tech.mappie.testing.objects.ConstructorParameterNotAFieldTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tech.mappie.testing
package tech.mappie.testing.objects

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.KotlinCompilation
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin
import tech.mappie.testing.loadObjectMappieClass
import java.io.File

class ConstructorSelectionTest {
Expand All @@ -26,7 +27,7 @@ class ConstructorSelectionTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ConstructorSelectionTest.*
import tech.mappie.testing.objects.ConstructorSelectionTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Expand Down Expand Up @@ -60,7 +61,7 @@ class ConstructorSelectionTest {
kotlin("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.ConstructorSelectionTest.*
import tech.mappie.testing.objects.ConstructorSelectionTest.*
class Mapper : ObjectMappie<Input, Output>()
"""
Expand Down
Loading

0 comments on commit 00a3ff1

Please sign in to comment.