Skip to content

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

Open
@nedtwigg

Description

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 {

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions