Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalactic
    Definition Classes
    org
  • trait TripleEqualsSupport extends AnyRef

    Trait that defines abstract methods used to enforce compile-time type constraints for equality comparisons, and defines === and !== operators used by matchers.

    Trait that defines abstract methods used to enforce compile-time type constraints for equality comparisons, and defines === and !== operators used by matchers.

    The abstract methods of this trait are selectively implemented as implicit by subclasses to enable a spectrum of type constraints for the === and !== operators. As an illustration, if in the expression, a === b, the type of a is A and b is B, the following three levels of compile-time checking can be obtained from TripleEqualsSupport subtraits:

    Unchecked - A and B can be any two types. This (weakest) constraint level is available from subtraits TripleEquals and LegacyTripleEquals.

    Conversion checked - A must be a subtype of B, or vice versa, or an implicit conversion must be available that converts A to B, or vice versa. (Both A and B can be the same type, because a type is considered a subtype of itself.) This (intermediate) constraint level is available from subtraits ConversionCheckedTripleEquals and ConversionCheckedLegacyTripleEquals.

    Type checked - A must be a subtype of B, or vice versa. (Both A and B can be the same type, because a type is considered a subtype of itself.) This (strongest) constraint level is available from subtraits TypeCheckedTripleEquals and TypeCheckedLegacyTripleEquals.

    The difference between the regular and “legacy” variants of each pair of traits is that the === and !== operators provided by the regular variants result in Boolean, whereas those of the legacy variants result in Option[String]. For example, were you to mix in TripleEquals, the expression 1 + 1 === 3 would return false. Were you to mix in LegacyTripleEquals, by contrast, the expression 1 + 1 === 3 would return Some("2 did not equal 3").

    The purpose of the legacy variants is to maintain compatibility with existing code that uses ScalaTest's original === defined in trait org.scalatest.Assertions. This === operator returned an Option[String] to facilitate better error messages. With the advent of macros in Scala 2.10, it is possible to obtain good error messages by making assert a macro. Once ScalaTest no longer supports Scala 2.9, the legacy variants (LegacyTripleEquals, ConversionCheckedLegacyTripleEquals, and TypeCheckedLegacyTripleEquals) will be deprecated and eventually removed, === will return only Boolean, and good error messages will be obtained via macros.

    This trait defines all methods that need to be defined implicitly by the six subtraits so that if multiple subtraits are used together, the inner-most subtrait in scope can not only enable the implicits it needs by overriding or hiding those methods (currently-in-scope as regular, non-implicit methods) and making them implicit, it can also disable any implicits enabled by its sibling subtraits in enclosing scopes. For example, if your test class mixes in TypeCheckedTripleEquals, inside your test class the following methods will be implicit:

    • convertToCheckingEqualizer
    • typeCheckedConstraint
    • lowPriorityTypeCheckedConstraint
    • convertEquivalenceToAToBConstraint
    • convertEquivalenceToBToAConstraint

    If in the body of a test you want to turn off the type checking, you can import the members of TripleEquals in the body of that test. This will not only hide non-implicit methods convertToEqualizer unconstrainedEquality of TypeCheckedTripleEquals, replacing those with implicit ones defined in TripleEquals, it will also hide the three methods made implicit in TypeCheckedTripleEquals (and listed above), replacing them by non-implicit ones.

    In short, you should be able to select a primary constraint level via either a mixin or import, then change that in nested scopes however you want, again either through a mixin or import, without getting any implicit conversion ambiguity. The innermost constraint level in scope will always be in force.

    Definition Classes
    scalactic
  • CheckingEqualizer
  • Equalizer
  • LegacyCheckingEqualizer
  • LegacyEqualizer

class LegacyEqualizer[L] extends AnyRef

Class used via an implicit conversion to enable any two objects to be compared with === and !== with an Option[String] result and no enforced type constraint between two object types. For example:

assert(a === b)
assert(c !== d)

You can also check numeric values against another with a tolerance. Here are some examples:

assert(a === (2.0 +- 0.1))
assert(c !== (2.0 +- 0.1))

The benefit of using assert(a === b) rather than assert(a == b) in ScalaTest code is that a TestFailedException produced by the former will include the values of a and b in its detail message.

Note: This class has "Legacy" in its name because its approach to error messages will eventually be replaced by macros. Once ScalaTest no longer supports Scala 2.9, this class will be deprecated in favor of class Equalizer. Instead of obtaining nice error messages via the Option[String] returned by the methods of this class, the error messages will be obtained by a macro. The "legacy" approach to good error messages will continue to be used, however, until ScalaTest no longer supports Scala 2.9, since macros were introduced to Scala (in experimental form) in 2.10.

The primary constructor takes one object, left, whose type is being converted to Equalizer. The left value may be a null reference, because this is allowed by Scala's == operator.

Source
TripleEqualsSupport.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LegacyEqualizer
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new LegacyEqualizer(left: L)

    left

    An object to convert to Equalizer, which represents the left value of a === or !== equality check.

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. def !==(spread: Spread[L]): Option[String]

    Determine whether a numeric object is outside the passed Spread, returning an Option[String].

    Determine whether a numeric object is outside the passed Spread, returning an Option[String].

    spread

    the Spread against which to compare the value passed to the constructor as left

    returns

    true if the value passed to the constructor as left is not within the Spread passed to this method. else returns an error message string wrapped in a Some.

  3. def !==(right: Any)(implicit equality: Equality[L]): Option[String]

    Compare two objects for inequality, returning an Option[String], using the Equality type class passed as equality.

    Compare two objects for inequality, returning an Option[String], using the Equality type class passed as equality.

    right

    the object to compare for inequality with left, passed to the constructor

    equality

    an implicit Equality type class that defines a way of calculating equality for objects of type L

    returns

    None if the left and right objects are not equal according to the passed Equality type class. else returns an error message string wrapped in a Some.

  4. final def ##(): Int
    Definition Classes
    AnyRef → Any
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def ===(spread: Spread[L]): Option[String]

    Determine whether a numeric object is within the passed Spread, returning an Option[String].

    Determine whether a numeric object is within the passed Spread, returning an Option[String].

    spread

    the Spread against which to compare the value passed to the constructor as left

    returns

    None if the value passed to the constructor as left is not within the Spread passed to this method, else returns an error message string wrapped in a Some.

  7. def ===(right: Any)(implicit equality: Equality[L]): Option[String]

    Compare two objects for equality, returning an Option[String], using the Equality type class passed as equality.

    Compare two objects for equality, returning an Option[String], using the Equality type class passed as equality.

    right

    the object to compare for equality with left, passed to the constructor

    equality

    an implicit Equality type class that defines a way of calculating equality for objects of type L

    returns

    None if the left and right objects are equal according to the passed Equality type class. else returns an error message string wrapped in a Some.

  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  19. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped