11package dev.fritz2.lens
22
3- import com.tschuchort.compiletesting.KotlinCompilation
4- import com.tschuchort.compiletesting.SourceFile
5- import com.tschuchort.compiletesting.symbolProcessorProviders
3+ import com.tschuchort.compiletesting.*
64import org.assertj.core.api.Assertions.assertThat
75import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
86import org.junit.jupiter.api.DisplayName
@@ -22,22 +20,21 @@ class LensesProcessorTests {
2220
2321 @ExperimentalPathApi
2422 private fun compileSource (vararg source : SourceFile ) = KotlinCompilation ().apply {
25- sources = source.toList()
26- symbolProcessorProviders = listOf (LensesProcessorProvider ())
27- workingDir = createTempDirectory(" fritz2-tests" ).toFile()
28- inheritClassPath = true
29- verbose = false
23+ configureKsp(useKsp2 = true ) {
24+ jvmTarget = " 21"
25+ languageVersion = " 2.1"
26+ sources = source.toList()
27+ symbolProcessorProviders + = LensesProcessorProvider ()
28+ workingDir = createTempDirectory(" fritz2-tests" ).toFile()
29+ inheritClassPath = true
30+ verbose = false
31+ }
3032 }.compile()
3133
32- // workaround copied by https://github.com/tschuchortdev/kotlin-compile-testing/issues/129#issuecomment-804390310
33- internal val KotlinCompilation .Result .workingDir: File
34- get() =
35- outputDirectory.parentFile!!
36-
3734 // workaround inspired by https://github.com/tschuchortdev/kotlin-compile-testing/issues/129#issuecomment-804390310
38- val KotlinCompilation . Result .kspGeneratedSources: List <File >
35+ private val CompilationResult .kspGeneratedSources: List <File >
3936 get() {
40- val kspWorkingDir = workingDir .resolve(" ksp" )
37+ val kspWorkingDir = outputDirectory.parentFile !! .resolve(" ksp" )
4138 val kspGeneratedDir = kspWorkingDir.resolve(" sources" )
4239 val kotlinGeneratedDir = kspGeneratedDir.resolve(" kotlin" )
4340 val javaGeneratedDir = kspGeneratedDir.resolve(" java" )
@@ -81,13 +78,13 @@ class LensesProcessorTests {
8178 // lenses will appear in `BarLenses.kt`
8279 @Lenses
8380 sealed class Bar {
84- val bar: Int
81+ abstract val bar: Int
8582 companion object
8683 }
8784
8885 data class BarImpl(
8986 override val bar: Int,
90- ) : Bar
87+ ) : Bar()
9188 """
9289 )
9390
@@ -224,7 +221,7 @@ class LensesProcessorTests {
224221 import dev.fritz2.core.Lenses
225222
226223 @Lenses
227- data class Foo(private val foo: Int, param: String ) { // no public property defined in ctor!
224+ data class Foo(private val foo: Int) { // no public property defined in ctor!
228225 companion object
229226 val someNoneCtorProp: Int = foo + 1
230227 }
@@ -355,7 +352,7 @@ class LensesProcessorTests {
355352 // private field -> no lens possible!
356353 companion object {
357354 // should not disturb
358- fun toJson (foo: Foo) = Json.decodeFromString(serializer(), foo )
355+ fun displayValue (foo: Foo) = foo.toString( )
359356 }
360357 val ignored = bar + 1 // must not appear in lens!
361358 val ignoredDelegated by lazy { bar + 1 } // must not appear in lens!
@@ -635,8 +632,7 @@ class LensesProcessorTests {
635632 | }
636633 |)
637634 |
638- |public fun <PARENT> Lens<PARENT, Framework>.fooBar(): Lens<PARENT, MyType> = this +
639- | Framework.fooBar()
635+ |public fun <PARENT> Lens<PARENT, Framework>.fooBar(): Lens<PARENT, MyType> = this + Framework.fooBar()
640636 |
641637 |public fun Framework.Companion.baz(): Lens<Framework, MyGenericType<Int>> = lensOf(
642638 | "baz",
@@ -654,14 +650,11 @@ class LensesProcessorTests {
654650 | }
655651 |)
656652 |
657- |public fun <PARENT> Lens<PARENT, Framework>.baz(): Lens<PARENT, MyGenericType<Int>> = this +
658- | Framework.baz()
653+ |public fun <PARENT> Lens<PARENT, Framework>.baz(): Lens<PARENT, MyGenericType<Int>> = this + Framework.baz()
659654 |
660- |public fun Framework.Companion.fritz2(): Lens<Framework, Fritz2> =
661- | lensForUpcasting<Framework,Fritz2>()
655+ |public fun Framework.Companion.fritz2(): Lens<Framework, Fritz2> = lensForUpcasting<Framework,Fritz2>()
662656 |
663- |public fun Framework.Companion.spring(): Lens<Framework, Spring> =
664- | lensForUpcasting<Framework,Spring>()
657+ |public fun Framework.Companion.spring(): Lens<Framework, Spring> = lensForUpcasting<Framework,Spring>()
665658 """ .trimMargin()
666659
667660 @JvmStatic
@@ -720,17 +713,15 @@ class LensesProcessorTests {
720713 | { p, v -> p.copy(fooBar = v)}
721714 | )
722715 |
723- |public fun <PARENT> Lens<PARENT, Framework>.fooBar(): Lens<PARENT, MyType> = this +
724- | Framework.fooBar()
716+ |public fun <PARENT> Lens<PARENT, Framework>.fooBar(): Lens<PARENT, MyType> = this + Framework.fooBar()
725717 |
726718 |public fun Framework.Companion.baz(): Lens<Framework, MyGenericType<Int>> = lensOf(
727719 | "baz",
728720 | { it.baz },
729721 | { p, v -> p.copy(baz = v)}
730722 | )
731723 |
732- |public fun <PARENT> Lens<PARENT, Framework>.baz(): Lens<PARENT, MyGenericType<Int>> = this +
733- | Framework.baz()
724+ |public fun <PARENT> Lens<PARENT, Framework>.baz(): Lens<PARENT, MyGenericType<Int>> = this + Framework.baz()
734725 """ .trimMargin()
735726 ),
736727 arguments(
@@ -744,25 +735,24 @@ class LensesProcessorTests {
744735
745736 class MyType
746737 class MyGenericType<T>
747-
738+
748739 @Lenses
749- sealed class Framework(
750- val bar: Int,
751- val foo: String
752- ) {
740+ sealed class Framework {
741+ abstract val bar: Int
742+ abstract val foo: String
753743 abstract val fooBar: MyType
754744 abstract val baz: MyGenericType<Int>
755745 companion object
756746 }
757-
747+
758748 data class Fritz2 (
759749 override val bar: Int,
760750 override val foo: String,
761751 override val fooBar: MyType,
762752 override val baz: MyGenericType<Int>,
763753 val usesFlows: Boolean,
764754 ) : Framework()
765-
755+
766756 data class Spring (
767757 override val bar: Int,
768758 override val foo: String,
@@ -963,6 +953,7 @@ class LensesProcessorTests {
963953 package dev.fritz2.lenstest
964954
965955 import dev.fritz2.core.Lenses
956+ import dev.fritz2.core.NoLens
966957
967958 @Lenses
968959 sealed class Foo(
@@ -971,11 +962,14 @@ class LensesProcessorTests {
971962 ) {
972963 companion object
973964 }
974-
975- @Lens
965+
966+ @Lenses
976967 data class FooImpl (
977968 val something: String
978- ) : Foo {
969+ ) : Foo(
970+ alsoIgnored = "ignored",
971+ ignored = 42
972+ ) {
979973 companion object
980974 }
981975 """
@@ -998,19 +992,19 @@ class LensesProcessorTests {
998992 package dev.fritz2.lenstest
999993
1000994 import dev.fritz2.core.Lenses
995+ import dev.fritz2.core.NoLens
1001996
1002997 @Lenses
1003998 sealed interface Foo {
1004- protected val ignored: Int
1005-
1006999 @NoLens
1007- val alsoIgnored: String
1008-
1000+ val ignored: Int
1001+
10091002 companion object
10101003 }
1011-
1012- @Lens
1004+
1005+ @Lenses
10131006 data class FooImpl (
1007+ override val ignored: Int,
10141008 val something: String
10151009 ) : Foo {
10161010 companion object
@@ -1361,11 +1355,9 @@ class LensesProcessorTests {
13611355 |
13621356 |public fun <PARENT> Lens<PARENT, Framework>.foo(): Lens<PARENT, String> = this + Framework.foo()
13631357 |
1364- |public fun Framework.Companion.fritz2(): Lens<Framework, Fritz2> =
1365- | lensForUpcasting<Framework,Fritz2>()
1358+ |public fun Framework.Companion.fritz2(): Lens<Framework, Fritz2> = lensForUpcasting<Framework,Fritz2>()
13661359 |
1367- |public fun Framework.Companion.spring(): Lens<Framework, Spring> =
1368- | lensForUpcasting<Framework,Spring>()
1360+ |public fun Framework.Companion.spring(): Lens<Framework, Spring> = lensForUpcasting<Framework,Spring>()
13691361 """ .trimMargin()
13701362
13711363
@@ -1379,28 +1371,31 @@ class LensesProcessorTests {
13791371 package dev.fritz2.lenstest
13801372
13811373 import dev.fritz2.core.Lenses
1374+ import dev.fritz2.core.NoLens
13821375
13831376 @Lenses
13841377 sealed class Framework(
13851378 @NoLens val ignore: String
13861379 ) {
13871380 @NoLens
1388- val alsoIgnore: String
1381+ abstract val alsoIgnore: String
13891382 abstract val foo: String
13901383 companion object
13911384 }
1392-
1385+
13931386 data class Fritz2 (
13941387 override val foo: String,
1395- ) : Framework {
1396- override val ignore: String = "Fritz2"
1388+ ) : Framework(
1389+ ignore = "Fritz2"
1390+ ) {
13971391 override val alsoIgnore: String = "Fritz2"
13981392 }
1399-
1393+
14001394 data class Spring (
14011395 override val foo: String,
1402- ) : Framework {
1403- override val ignore: String = "Spring"
1396+ ) : Framework(
1397+ ignore = "Spring"
1398+ ) {
14041399 override val alsoIgnore: String = "Fritz2"
14051400 }
14061401 """
@@ -1415,6 +1410,7 @@ class LensesProcessorTests {
14151410 package dev.fritz2.lenstest
14161411
14171412 import dev.fritz2.core.Lenses
1413+ import dev.fritz2.core.NoLens
14181414
14191415 @Lenses
14201416 sealed interface Framework {
0 commit comments