Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nedtwigg opened this issue Feb 11, 2024 · 0 comments
Open

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

nedtwigg opened this issue Feb 11, 2024 · 0 comments
Labels
enhancement New feature or request jvm

Comments

@nedtwigg
Copy link
Member

Kotest has a very nice shouldBe method:

someFunction() shouldBe "some value"

It would be handy if Selfie had an infix version:

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:

// 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

fun parseToBe_TODO(lineOneIndexed: Int): ToBeLiteral {
return parseToBeLike(".toBe_TODO(", lineOneIndexed)
}
fun parseToBe(lineOneIndexed: Int): ToBeLiteral {
return parseToBeLike(".toBe(", lineOneIndexed)
}
private fun parseToBeLike(prefix: String, lineOneIndexed: Int): ToBeLiteral {

@nedtwigg nedtwigg added jvm enhancement New feature or request labels Feb 11, 2024
Kantis pushed a commit to kotest/kotest that referenced this issue Feb 14, 2024
Selfie just released its `1.2.0` version which added support for Kotest.

- add
`testImplementation("com.diffplug.selfie:selfie-runner-junit5:1.2.0")`
- add `override fun extensions() = listOf(SelfieExtension(this))` to
your `AbstractProjectConfig`
- do snapshot testing! https://github.com/diffplug/selfie

It's written in KMP, but there are some stubs which have only been
implemented for JVM so far. If anyone is interested in helping with
other platforms:

- diffplug/selfie#186

Also perhaps of interest to Kotest folks:

- diffplug/selfie#214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jvm
Projects
None yet
Development

No branches or pull requests

1 participant