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

strikt.arrow.Option.kt Maven / Gradle / Ivy

@file:Suppress("DEPRECATION")
package strikt.arrow

import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import strikt.api.Assertion

/**
 * Asserts that the [Option] is [None]
 * @return Assertion builder over the same subject that is now known to be
 * a [None].
 */
@Suppress("UNCHECKED_CAST")
fun  Assertion.Builder>.isNone() =
  assert("should be None") {
    when (it) {
      is Some -> fail()
      is None -> pass()
    }
  } as Assertion.Builder

/**
 * Asserts that the [Option] is [Some]
 * @return Assertion builder over the same subject that is now known to be
 * a [Some].
 */
@Suppress("UNCHECKED_CAST")
fun  Assertion.Builder>.isSome() =
  assert("should be Some") {
    when (it) {
      is Some -> pass()
      is None -> fail()
    }
  } as Assertion.Builder>

/**
 * Asserts that the [Option] is [Some] and that it contains the exact value
 * @param value Value to compare to the [Option]'s wrapped value
 * @return Assertion builder over the same subject that is now known to be
 * a [Some].
 */
@Suppress("UNCHECKED_CAST")
infix fun  Assertion.Builder>.isSome(value: T) =
  assert("should be Some($value)") {
    when (it) {
      is Some -> {
        if (it.value == value) {
          pass()
        } else {
          fail()
        }
      }
      is None -> fail()
    }
  } as Assertion.Builder>

/**
 * Unwraps the containing value of the [Some]
 * @return Assertion builder over the unwrapped subject
 */
@Deprecated("Use value instead", replaceWith = ReplaceWith("value"))
val  Assertion.Builder>.t: Assertion.Builder
  get() = value

/**
 * Unwraps the containing value of the [Some]
 * @return Assertion builder over the unwrapped subject
 */
val  Assertion.Builder>.value: Assertion.Builder
  get() = get("some value", Some::value)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy