diffplug / diffplug/selfie

Add `infix fun String.selfieIs` (similar to Kotest `shouldBe`)

Open
#214 0 comments 0 reactions 0 assignees View on GitHub
enhancement jvm
Dominant language
Kotlin
Stars
101
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Kotest has a very nice `shouldBe` method:

```kotlin
someFunction() shouldBe "some value"
```

It would be handy if Selfie had an infix version:

```kotlin
someFunction() selfieIs null // equivalent to `toBe_TODO`, run and it becomes
someFunction() selfieIs "some value"
```

And all the `//selfieonce`, `//SELFIEWRITE` would work too if implemented roughly like so:

```kotlin
// in com.diffplug.selfie
infix fun String.selfieIs(expected: String?) : Unit {
if (expected == null) {
Selfie.expectSelfie(this).toBe_TODO()
} else {
Selfie.expectSelfie(this).toBe(expected)
}
}

// in com.diffplug.selfie.coroutines
suspend infix fun String.selfieIs(expected: String?) : Unit {
if (expected == null) {
Selfie.expectSelfie(this).toBe_TODO()
} else {
Selfie.expectSelfie(this).toBe(expected)
}
}
```

The main challenge will be adapting this code to parse infix multiline literals

https://github.com/diffplug/selfie/blob/952a4ebfdf4911deeb08a7378048c80a0a9bb3ff/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/guts/SourceFile.kt#L105-L111

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.