Skip to content

Commit

Permalink
Fix optics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev committed Aug 30, 2023
1 parent 797bcbe commit e60b627
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ internal fun adt(c: KSClassDeclaration, logger: KSPLogger): ADT =
OpticsTarget.LENS ->
evalAnnotatedDataClass(c, c.qualifiedNameOrSimpleName.lensErrorMessage, logger)
.let(::LensTarget)

OpticsTarget.ISO ->
evalAnnotatedValueClass(c, c.qualifiedNameOrSimpleName.isoErrorMessage, logger)
.let(::IsoTarget)

OpticsTarget.PRISM ->
evalAnnotatedPrismElement(c, c.qualifiedNameOrSimpleName.prismErrorMessage, logger)
.let(::PrismTarget)

OpticsTarget.DSL -> evalAnnotatedDslElement(c, logger)
}
},
Expand All @@ -37,25 +40,16 @@ internal fun KSClassDeclaration.targets(): List<OpticsTarget> =
targetsFromOpticsAnnotation().let { targets ->
when {
isSealed ->
if (targets.isEmpty()) {
listOf(OpticsTarget.PRISM, OpticsTarget.DSL)
} else {
targets.filter { it == OpticsTarget.PRISM || it == OpticsTarget.DSL }
}
listOf(OpticsTarget.PRISM, OpticsTarget.DSL)
.filter { targets.isEmpty() || it in targets }

isValue ->
listOf(OpticsTarget.ISO, OpticsTarget.DSL)
.filter { targets.isEmpty() || it in targets }

else ->
if (targets.isEmpty()) {
listOf(OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL)
} else {
targets.filter {
when (it) {
OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL -> true
else -> false
}
}
}
listOf(OpticsTarget.LENS, OpticsTarget.DSL)
.filter { targets.isEmpty() || it in targets }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ fun String.compilationFails() {

fun String.compilationSucceeds(allWarningsAsErrors: Boolean = false) {
val compilationResult = compile(this, allWarningsAsErrors = allWarningsAsErrors)
Assertions.assertThat(compilationResult.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
Assertions.assertThat(compilationResult.exitCode)
.withFailMessage(compilationResult.messages)
.isEqualTo(KotlinCompilation.ExitCode.OK)
}

fun String.evals(thing: Pair<String, Any?>) {
val compilationResult = compile(this)
Assertions.assertThat(compilationResult.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
Assertions.assertThat(compilationResult.exitCode)
.withFailMessage(compilationResult.messages)
.isEqualTo(KotlinCompilation.ExitCode.OK)
val classesDirectory = compilationResult.outputDirectory
val (variable, output) = thing
Assertions.assertThat(eval(variable, classesDirectory)).isEqualTo(output)
Expand Down

0 comments on commit e60b627

Please sign in to comment.