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

org.scalatest.words.ResultOfContainWord.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2001-2013 Artima, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.scalatest.words

import scala.collection.GenTraversable
import org.scalatest.enablers.Containing
import org.scalatest.enablers.Aggregating
import org.scalatest.enablers.Sequencing
import org.scalatest.enablers.KeyMapping
import org.scalatest.enablers.ValueMapping
import org.scalatest.MatchersHelper.newTestFailedException
import org.scalatest.FailureMessages
import org.scalatest.UnquotedString
import org.scalatest.exceptions.NotAllowedException
import org.scalatest.exceptions.StackDepthExceptionHelper.getStackDepthFun
import org.scalautils.Prettifier

/**
 * This class is part of the ScalaTest matchers DSL. Please see the documentation for Matchers for an overview of
 * the matchers DSL.
 *
 * @author Bill Venners
 */
class ResultOfContainWord[L](left: L, shouldBeTrue: Boolean = true) {

  /**
   * This method enables the following syntax: 
   *
   * 
   * xs should contain oneOf (1, 2)
   *                   ^
   * 
*/ def oneOf(right: Any*)(implicit containing: Containing[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("oneOfEmpty"), getStackDepthFun("ResultOfContainWord.scala", "oneOf")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("oneOfDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "oneOf")) if (containing.containsOneOf(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainOneOfElements" else "containedOneOfElements", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * xs should contain atLeastOneOf (1, 2)
   *                   ^
   * 
*/ def atLeastOneOf(right: Any*)(implicit aggregating: Aggregating[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("atLeastOneOfEmpty"), getStackDepthFun("ResultOfContainWord.scala", "atLeastOneOf")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("atLeastOneOfDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "atLeastOneOf")) if (aggregating.containsAtLeastOneOf(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainAtLeastOneOf" else "containedAtLeastOneOf", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * xs should contain noneOf (1, 2)
   *                   ^
   * 
*/ def noneOf(right: Any*)(implicit containing: Containing[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("noneOfEmpty"), getStackDepthFun("ResultOfContainWord.scala", "noneOf")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("noneOfDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "noneOf")) if (containing.containsNoneOf(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "containedOneOfElements" else "didNotContainOneOfElements", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * xs should contain theSameElementsAs (List(1, 2))
   *                   ^
   * 
*/ def theSameElementsAs(right: GenTraversable[_])(implicit aggregating: Aggregating[L]) { if (aggregating.containsTheSameElementsAs(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainSameElements" else "containedSameElements", left, right ) ) } /** * This method enables the following syntax: * *
   * xs should contain theSameElementsInOrderAs (List(1, 2))
   *                   ^
   * 
*/ def theSameElementsInOrderAs(right: GenTraversable[_])(implicit sequencing: Sequencing[L]) { if (sequencing.containsTheSameElementsInOrderAs(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainSameElementsInOrder" else "containedSameElementsInOrder", left, right ) ) } /** * This method enables the following syntax: * *
   * xs should contain only (1, 2)
   *                   ^
   * 
*/ def only(right: Any*)(implicit aggregating: Aggregating[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("onlyEmpty"), getStackDepthFun("ResultOfContainWord.scala", "only")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("onlyDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "only")) if (aggregating.containsOnly(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainOnlyElements" else "containedOnlyElements", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * xs should contain inOrderOnly (1, 2)
   *                   ^
   * 
*/ def inOrderOnly(right: Any*)(implicit sequencing: Sequencing[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("inOrderOnlyEmpty"), getStackDepthFun("ResultOfContainWord.scala", "inOrderOnly")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("inOrderOnlyDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "inOrderOnly")) if (sequencing.containsInOrderOnly(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainInOrderOnlyElements" else "containedInOrderOnlyElements", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * xs should contain allOf (1, 2)
   *                   ^
   * 
*/ def allOf(right: Any*)(implicit aggregating: Aggregating[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("allOfEmpty"), getStackDepthFun("ResultOfContainWord.scala", "allOf")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("allOfDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "allOf")) if (aggregating.containsAllOf(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainAllOfElements" else "containedAllOfElements", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * xs should contain inOrder (1, 2)
   *                   ^
   * 
*/ def inOrder(right: Any*)(implicit sequencing: Sequencing[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("inOrderEmpty"), getStackDepthFun("ResultOfContainWord.scala", "inOrder")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("inOrderDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "inOrder")) if (sequencing.containsInOrder(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainAllOfElementsInOrder" else "containedAllOfElementsInOrder", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } /** * This method enables the following syntax: * *
   * map should contain key ("one")
   *                    ^
   * 
*/ def key(expectedKey: Any)(implicit keyMapping: KeyMapping[L]) { if (keyMapping.containsKey(left, expectedKey) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainKey" else "containedKey", left, expectedKey) ) } /** * This method enables the following syntax: * *
   * map should contain value ("one")
   *                    ^
   * 
*/ def value(expectedValue: Any)(implicit valueMapping: ValueMapping[L]) { if (valueMapping.containsValue(left, expectedValue) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainValue" else "containedValue", left, expectedValue) ) } /** * This method enables the following syntax: * *
   * xs should contain atMostOneOf (1, 2)
   *                   ^
   * 
*/ def atMostOneOf(right: Any*)(implicit aggregating: Aggregating[L]) { if (right.isEmpty) throw new NotAllowedException(FailureMessages("atMostOneOfEmpty"), getStackDepthFun("ResultOfContainWord.scala", "atMostOneOf")) if (right.distinct.size != right.size) throw new NotAllowedException(FailureMessages("atMostOneOfDuplicate"), getStackDepthFun("ResultOfContainWord.scala", "atMostOneOf")) if (aggregating.containsAtMostOneOf(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainAtMostOneOf" else "containedAtMostOneOf", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } override def toString: String = "ResultOfContainWord(" + Prettifier.default(left) + ", " + Prettifier.default(shouldBeTrue) + ")" }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy