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

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

Go to download

ScalaTest is a free, open-source testing toolkit for Scala and Java programmers.

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.MatchersHelper.newTestFailedException
import org.scalatest.FailureMessages
import org.scalatest.UnquotedString

/*
 * 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 (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 (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 (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 aggregating: Aggregating[L]) { if (aggregating.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 (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 aggregating: Aggregating[L]) { if (aggregating.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 (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 aggregating: Aggregating[L]) { if (aggregating.containsInOrder(left, right) != shouldBeTrue) throw newTestFailedException( FailureMessages( if (shouldBeTrue) "didNotContainAllOfElementsInOrder" else "containedAllOfElementsInOrder", left, UnquotedString(right.map(FailureMessages.decorateToStringValue).mkString(", ")) ) ) } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy