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

org.specs2.matcher.BeHaveMatchers.scala Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
package org.specs2
package matcher

/**
 * This trait provides special matchers to be used in expressions like
 * 
 * 1 must be equalTo(1) and not be equalTo(2)
 */
private[specs2]
trait BeHaveMatchers {
  def be = new NeutralMatcher[Any]
  def have = be
  def not = new NotMatcher[Any]
}
/**
 * This special matcher always return a NeutralMatch MatchResult (an implicit Success)
 */
class NeutralMatcher[T] extends Matcher[T] {
  def apply[S <: T](s: Expectable[S]): MatchResult[S] =
    NeutralMatch(MatchSuccess("ok", "ko", s))

  def apply[S <: T](r: MatchResult[S]): MatchResult[S] =
    NeutralMatch(r)

}

/**
 * This special matcher always return a NotMatch MatchResult. It will negate the next match applied to it.
 */
class NotMatcher[T] extends Matcher[T] {

  def apply[S <: T](s: Expectable[S]): MatchResult[S] =
    NotMatch(MatchSuccess("ok", "ko", s))

  def apply[S <: T](r: MatchResult[S]): MatchResult[S] =
    MatchResultCombinators.combineMatchResult(r).not

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy