All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.zegreatrob.minspy.SpyFunction.kt Maven / Gradle / Ivy

There is a newer version: 12.1.41
Show newest version
package com.zegreatrob.minspy

import kotlin.test.fail

fun Spy.spyFunction() {
    spyReceivedValues.add(Unit)
}

fun  Spy.spyFunction() = spyFunction(Unit)
fun  Spy.spyFunction(input: I) {
    spyReceivedValues.add(input)
}

fun  Spy.spyFunction(input: I): O = spyReturnWhenGivenValues.fixedGetOrElse(input) {
    safePop(input)
}.also { spyReceivedValues.add(input) }

private fun  Spy.safePop(input: I): O = if (spyReturnValues.size > 0) {
    spyReturnValues[0].also { spyReturnValues.removeAt(0) }
} else {
    fail("No values remaining given input $input")
}

private fun  Map.fixedGetOrElse(input: K, function: () -> V) = if (containsKey(input)) {
    getValue(input)
} else {
    function()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy