Skip to content

Commit

Permalink
Add expectSelfies for suspend fun (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Jun 5, 2024
2 parents d3b55fe + f926dfb commit 2e44b90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> items, Function<T, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ object Selfie {
@JvmStatic fun expectSelfie(actual: Boolean) = BooleanSelfie(actual)

@JvmStatic
fun <T> expectSelfies(items: Iterable<T>, toString: (T) -> String): StringSelfie {
val snapshots = items.joinToString("\n", transform = toString)
return expectSelfie(snapshots)
}
fun <T> expectSelfies(items: Iterable<T>, toString: (T) -> String): StringSelfie =
expectSelfie(items.joinToString("\n", transform = toString))

@JvmStatic
fun cacheSelfie(toCache: Cacheable<String>) = cacheSelfie(Roundtrip.identity(), toCache)

@JvmStatic
fun <T> cacheSelfie(roundtrip: Roundtrip<T, String>, toCache: Cacheable<T>) =
CacheSelfie(deferredDiskStorage, roundtrip, toCache)

/**
* Memoizes any type which is marked with `@kotlinx.serialization.Serializable` as pretty-printed
* json.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ suspend fun preserveSelfiesOnDisk(vararg subsToKeep: String) {
subsToKeep.forEach { disk.keep(it) }
}
}
suspend fun <T> expectSelfies(items: Iterable<T>, toString: (T) -> String): StringSelfie =
expectSelfie(items.joinToString("\n", transform = toString))
suspend fun cacheSelfie(toCache: suspend () -> String) = cacheSelfie(Roundtrip.identity(), toCache)
suspend fun <T> cacheSelfie(roundtrip: Roundtrip<T, String>, toCache: suspend () -> T) =
CacheSelfieSuspend(disk(), roundtrip, toCache)

/**
* Memoizes any type which is marked with `@kotlinx.serialization.Serializable` as pretty-printed
* json.
Expand Down

0 comments on commit 2e44b90

Please sign in to comment.