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

commonMain.io.kotest.matchers.collections.startwith.kt Maven / Gradle / Ivy

package io.kotest.matchers.collections

import io.kotest.assertions.show.show
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot

infix fun  Iterable.shouldStartWith(element: T) = toList().shouldStartWith(listOf(element))
infix fun  Iterable.shouldStartWith(slice: Iterable) = toList().shouldStartWith(slice.toList())
infix fun  Iterable.shouldStartWith(slice: Array) = toList().shouldStartWith(slice.asList())

infix fun  Array.shouldStartWith(element: T) = asList().shouldStartWith(listOf(element))
infix fun  Array.shouldStartWith(slice: Collection) = asList().shouldStartWith(slice)
infix fun  Array.shouldStartWith(slice: Array) = asList().shouldStartWith(slice.asList())

infix fun  List.shouldStartWith(element: T) = this should startWith(listOf(element))
infix fun  List.shouldStartWith(slice: Collection) = this should startWith(slice)

infix fun  Iterable.shouldNotStartWith(element: T) = toList().shouldNotStartWith(listOf(element))
infix fun  Iterable.shouldNotStartWith(slice: Iterable) = toList().shouldNotStartWith(slice.toList())
infix fun  Iterable.shouldNotStartWith(slice: Array) = toList().shouldNotStartWith(slice.asList())

infix fun  Array.shouldNotStartWith(element: T) = asList().shouldNotStartWith(listOf(element))
infix fun  Array.shouldNotStartWith(slice: Collection) = asList().shouldNotStartWith(slice)
infix fun  Array.shouldNotStartWith(slice: Array) = asList().shouldNotStartWith(slice.asList())

infix fun  List.shouldNotStartWith(element: T) = this shouldNot startWith(listOf(element))
infix fun  List.shouldNotStartWith(slice: Collection) = this shouldNot startWith(slice)

fun  startWith(slice: Collection) = object : Matcher> {
   override fun test(value: List) =
      MatcherResult(
         value.subList(0, slice.size) == slice,
         { "List should start with ${slice.printed().value} but was ${value.take(slice.size).printed().value}" },
         { "List should not start with ${slice.printed().value}" }
      )
}

infix fun  Iterable.shouldEndWith(element: T) = toList().shouldEndWith(listOf(element))
infix fun  Iterable.shouldEndWith(slice: Iterable) = toList().shouldEndWith(slice.toList())
infix fun  Iterable.shouldEndWith(slice: Array) = toList().shouldEndWith(slice.asList())

infix fun  Array.shouldEndWith(element: T) = asList().shouldEndWith(listOf(element))
infix fun  Array.shouldEndWith(slice: Collection) = asList().shouldEndWith(slice)
infix fun  Array.shouldEndWith(slice: Array) = asList().shouldEndWith(slice.asList())

infix fun  List.shouldEndWith(element: T) = this.shouldEndWith(listOf(element))
infix fun  List.shouldEndWith(slice: Collection) = this should endWith(slice)
infix fun  List.shouldEndWith(slice: Array) = this.shouldEndWith(slice.toList())

infix fun  Iterable.shouldNotEndWith(element: T) = toList().shouldNotEndWith(listOf(element))
infix fun  Iterable.shouldNotEndWith(slice: Iterable) = toList().shouldNotEndWith(slice.toList())
infix fun  Iterable.shouldNotEndWith(slice: Array) = toList().shouldNotEndWith(slice.asList())

infix fun  Array.shouldNotEndWith(element: T) = asList().shouldNotEndWith(listOf(element))
infix fun  Array.shouldNotEndWith(slice: Collection) = asList().shouldNotEndWith(slice)
infix fun  Array.shouldNotEndWith(slice: Array) = asList().shouldNotEndWith(slice.asList())

infix fun  List.shouldNotEndWith(element: T) = this shouldNot endWith(listOf(element))
infix fun  List.shouldNotEndWith(slice: Collection) = this shouldNot endWith(slice)

fun  endWith(slice: Collection) = object : Matcher> {
   override fun test(value: List) =
      MatcherResult(
         value.subList(value.size - slice.size, value.size) == slice,
         { "List should end with ${slice.printed().value} but was ${value.take(slice.size).printed().value}" },
         { "List should not end with ${slice.printed().value}" }
      )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy