All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.io.kotest.assertions.arrow.order.matchers.kt Maven / Gradle / Ivy

package io.kotest.assertions.arrow.order

import arrow.typeclasses.Eq
import arrow.typeclasses.Order
import io.kotest.assertions.arrow.eq.EqAssertions
import io.kotest.assertions.arrow.matcher
import io.kotest.matchers.Matcher
import io.kotest.matchers.should

/**
 * Provides assertions for [Order]
 *
 * ```kotlin
 * Int.order().assert {
 *   0 shouldBeEqvTo 0
 *   0 shouldNotBeEqvTo -1
 *   0 shouldBeGreaterThan -1
 *   0 shouldBeGreaterThanOrEqual 0
 *   0 shouldBeSmallerThan 1
 *   0 shouldBeSmallerThanOrEqual 0
 * }
 * ```
 */
interface OrderAssertions : EqAssertions {

  fun OA(): Order

  override fun EQA(): Eq = OA()

  infix fun A.shouldBeGreaterThan(b: A): Unit =
    this should beGreaterThan(b)

  infix fun A.shouldBeGreaterThanOrEqual(b: A): Unit =
    this should beGreaterThanOrEqual(b)

  infix fun A.shouldBeSmallerThan(b: A): Unit =
    this should beSmallerThan(b)

  infix fun A.shouldBeSmallerThanOrEqual(b: A): Unit =
    this should beSmallerThanOrEqual(b)

  fun A.beGreaterThan(b: A): Matcher =
    OA().run { matcher(gt(b), "value ${this@beGreaterThan} not greater than $b") }

  fun A.beGreaterThanOrEqual(b: A): Matcher =
    OA().run { matcher(gte(b), "value ${this@beGreaterThanOrEqual} not greater or equal than $b") }

  fun A.beSmallerThan(b: A): Matcher =
    OA().run { matcher(lt(b), "value ${this@beSmallerThan} not smaller than $b") }

  fun A.beSmallerThanOrEqual(b: A): Matcher =
    OA().run { matcher(lte(b), "value ${this@beSmallerThanOrEqual} not smaller or equal than $b") }

  companion object {
    operator fun  invoke(OA: Order, f: (OrderAssertions).() -> Unit): Unit = f(object : OrderAssertions {
      override fun OA(): Order = OA
    })
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy