trait Containing[-C] extends AnyRef
Supertrait for typeclasses that enable certain contain
matcher syntax for containers.
A Containing[C]
provides access to the "containing nature" of type C
in such
a way that relevant contain
matcher syntax can be used with type C
. A C
can be any type of "container," a type that in some way can contains one or more other objects. ScalaTest provides
implicit implementations for several types. You can enable the contain
matcher syntax on your own
type U
by defining an Containing[U]
for the type and making it available implicitly.
ScalaTest provides implicit Containing
instances for scala.collection.GenTraversable
,
java.util.Collection
, java.util.Map
, String
, Array
,
and scala.Option
in the Containing
companion object.
Containing
versus Aggregating
The difference between Containing
and Aggregating
is that
Containing
enables contain
matcher syntax that makes sense for "box" types that can
contain at most one value (for example, scala.Option
),
whereas Aggregating
enables contain
matcher syntax for full-blown collections and other
aggregations of potentially more than one object. For example, it makes sense to make assertions like these, which
are enabled by Containing
, for scala.Option
:
val option: Option[Int] = Some(7) option should contain (7) option should contain oneOf (6, 7, 8) option should contain noneOf (3, 4, 5)
However, given a scala.Option
can only ever contain at most one object, it doesn't make
sense to make assertions like the following, which are enabled via Aggregation
:
// Could never succeed, so does not compile option should contain allOf (6, 7, 8)
The above assertion could never succceed, because an option cannot contain more than
one value. By default the above statement does not compile, because contain
allOf
is enabled by Aggregating
, and ScalaTest provides no implicit Aggregating
instance
for type scala.Option
.
- Source
- Containing.scala
- Alphabetic
- By Inheritance
- Containing
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def contains(container: C, element: Any): Boolean
Implements
contain
<value>
syntax for containers of typeC
.Implements
contain
<value>
syntax for containers of typeC
.- container
a container about which an assertion is being made
- element
an element that should be contained in the passed container
- returns
true if the passed container contains the passed element
- abstract def containsNoneOf(container: C, elements: Seq[Any]): Boolean
Implements
contain
noneOf
syntax for containers of typeC
.Implements
contain
noneOf
syntax for containers of typeC
.- container
a container about which an assertion is being made
- elements
elements none of which should be contained in the passed container
- returns
true if the passed container contains none of the passed elements
- abstract def containsOneOf(container: C, elements: Seq[Any]): Boolean
Implements
contain
oneOf
syntax for containers of typeC
.Implements
contain
oneOf
syntax for containers of typeC
.- container
a container about which an assertion is being made
- elements
elements exactly one (i.e., one and only one) of which should be contained in the passed container
- returns
true if the passed container contains exactly one of the passed elements
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()