diff --git a/jvm/CHANGELOG.md b/jvm/CHANGELOG.md index 4593a502..ed768900 100644 --- a/jvm/CHANGELOG.md +++ b/jvm/CHANGELOG.md @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Added `Selfie.expectSelfies(Iterable items, Function toString)` for doing easy "multi-asserts" in `suspend fun` also. ([#421](https://github.com/diffplug/selfie/pull/421)) ## [2.2.0] - 2024-06-04 ### Added diff --git a/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt b/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt index d360ada4..49b31e9c 100644 --- a/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt +++ b/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt @@ -64,10 +64,8 @@ object Selfie { @JvmStatic fun expectSelfie(actual: Boolean) = BooleanSelfie(actual) @JvmStatic - fun expectSelfies(items: Iterable, toString: (T) -> String): StringSelfie { - val snapshots = items.joinToString("\n", transform = toString) - return expectSelfie(snapshots) - } + fun expectSelfies(items: Iterable, toString: (T) -> String): StringSelfie = + expectSelfie(items.joinToString("\n", transform = toString)) @JvmStatic fun cacheSelfie(toCache: Cacheable) = cacheSelfie(Roundtrip.identity(), toCache) @@ -75,6 +73,7 @@ object Selfie { @JvmStatic fun cacheSelfie(roundtrip: Roundtrip, toCache: Cacheable) = CacheSelfie(deferredDiskStorage, roundtrip, toCache) + /** * Memoizes any type which is marked with `@kotlinx.serialization.Serializable` as pretty-printed * json. diff --git a/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/coroutines/Coroutines.kt b/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/coroutines/Coroutines.kt index 5edd39f2..3d41196d 100644 --- a/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/coroutines/Coroutines.kt +++ b/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/coroutines/Coroutines.kt @@ -63,9 +63,12 @@ suspend fun preserveSelfiesOnDisk(vararg subsToKeep: String) { subsToKeep.forEach { disk.keep(it) } } } +suspend fun expectSelfies(items: Iterable, toString: (T) -> String): StringSelfie = + expectSelfie(items.joinToString("\n", transform = toString)) suspend fun cacheSelfie(toCache: suspend () -> String) = cacheSelfie(Roundtrip.identity(), toCache) suspend fun cacheSelfie(roundtrip: Roundtrip, toCache: suspend () -> T) = CacheSelfieSuspend(disk(), roundtrip, toCache) + /** * Memoizes any type which is marked with `@kotlinx.serialization.Serializable` as pretty-printed * json.