Skip to content

Commit

Permalink
Version 2.0.0-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan McGregor committed Apr 6, 2021
1 parent 19721e4 commit 0b891f5
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .idea/limited-wip.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/minutest.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/core/minutest.core.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/core/minutest.core.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/core/minutest.core.samples.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/modules/core/minutest.core.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/docs/minutest.docs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/minutest.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/modules/minutest.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

allprojects {
group = "dev.minutest"
version = "2.0.0-rc1"
version = "2.0.0-rc2"

repositories {
mavenCentral()
Expand Down
47 changes: 47 additions & 0 deletions core/src/main/kotlin/dev/minutest/experimental/mutation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.minutest.experimental

import dev.minutest.combinedWith
import dev.minutest.internal.duplicatorFor
import kotlin.reflect.KProperty1

typealias Mutation<T> = (T) -> T

fun <T> mutation(name: String, mutation: Mutation<T>) = object : Mutation<T> by mutation {
override fun toString() = name
}

fun <T, V> mutation(name: String, value: V, mutation: Mutation<T>) =
mutation("$name = $value", mutation)

infix fun <T> Mutation<T>.andThen(another: Mutation<T>): Mutation<T> =
mutation("($this) and ($another)") {
another(this(it))
}

fun <T> Iterable<Mutation<T>>.combined(
other: Iterable<Mutation<T>>
): List<Mutation<T>> = combinedWith(other).map { (a, b) -> a andThen b }

fun <T : Any, V> mutation(
property: KProperty1<T, V>,
value: V
): Mutation<T> {
// outside the lambda so that we don't keep doing the reflective lookups
val duplicator = duplicatorFor(property)
return mutation(property.name, value) {
duplicator(it, value)
}
}

fun <T : Any, V> Iterable<V>.asMutationsOf(
property: KProperty1<T, V>
) = map { mutation(property, it) }


/**
* Something that has been mutated - the [name] says how.
*/
data class Mutant<T>(
val name: String,
val value: T
)
Loading

0 comments on commit 0b891f5

Please sign in to comment.