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

commonMain.io.kotest.matchers.string.match.kt Maven / Gradle / Ivy

package io.kotest.matchers.string

import io.kotest.assertions.print.print
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.neverNullMatcher
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot

infix fun  A?.shouldMatch(regex: String): A {
   this should match(regex)
   return this!!
}

infix fun  A?.shouldMatch(regex: Regex): A {
   this should match(regex)
   return this!!
}

infix fun  A?.shouldNotMatch(regex: String): A {
   this shouldNot match(regex)
   return this!!
}

fun match(regex: Regex): Matcher = neverNullMatcher { value ->
   MatcherResult(
      value.matches(regex),
      { "${value.print().value} should match regex $regex" },
      {
         "${value.print().value} should not match regex $regex"
      })
}

fun match(regex: CharSequence): Matcher = match(regex.toString().toRegex())




© 2015 - 2025 Weber Informatics LLC | Privacy Policy