org.scalautils.LegacyTripleEquals.scala Maven / Gradle / Ivy
/* * Copyright 2001-2008 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.scalautils trait LegacyTripleEquals extends EqualityConstraints { implicit override def defaultEquality[A]: Equality[A] = new DefaultEquality[A] override def convertToEqualizer[T](left: T): Equalizer[T] = new Equalizer(left) override def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T] = new CheckingEqualizer(left) implicit override def convertToLegacyEqualizer[T](left: T): LegacyEqualizer[T] = new LegacyEqualizer(left) override def convertToLegacyCheckingEqualizer[T](left: T): LegacyCheckingEqualizer[T] = new LegacyCheckingEqualizer(left) override def lowPriorityTypeCheckedEqualityConstraint[A, B](implicit equalityOfA: Equality[A], ev: A <:< B): EqualityConstraint[A, B] = new BasicEqualityConstraint[A, B](equalityOfA) override def typeCheckedEqualityConstraint[A, B](implicit equalityOfA: Equality[A], ev: B <:< A): EqualityConstraint[A, B] = new BasicEqualityConstraint[A, B](equalityOfA) override def lowPriorityConversionCheckedEqualityConstraint[A, B](implicit equalityOfB: Equality[B], cnv: A => B): EqualityConstraint[A, B] = new AToBEqualityConstraint[A, B](equalityOfB, cnv) override def conversionCheckedEqualityConstraint[A, B](implicit equalityOfA: Equality[A], cnv: B => A): EqualityConstraint[A, B] = new BToAEqualityConstraint[A, B](equalityOfA, cnv) /** * Implicit conversion from
Equalizer. * * *Any
toEqualizer
, used to enable * assertions with===
comparisons. * ** For more information * on this mechanism, see the documentation for
* Because trait
* *Suite
mixes inAssertions
, this implicit conversion will always be * available by default in ScalaTestSuite
s. This is the only implicit conversion that is in scope by default in every * ScalaTestSuite
. Other implicit conversions offered by ScalaTest, such as those that support the matchers DSL * orinvokePrivate
, must be explicitly invited into your test code, either by mixing in a trait or importing the * members of its companion object. The reason ScalaTest requires you to invite in implicit conversions (with the exception of the * implicit conversion for===
operator) is because if one of ScalaTest's implicit conversions clashes with an * implicit conversion used in the code you are trying to test, your program won't compile. Thus there is a chance that if you * are ever trying to use a library or test some code that also offers an implicit conversion involving a===
operator, * you could run into the problem of a compiler error due to an ambiguous implicit conversion. If that happens, you can turn off * the implicit conversion offered by thisconvertToEqualizer
method simply by overriding the method in your *Suite
subclass, but not marking it as implicit: ** // In your Suite subclass * override def convertToEqualizer(left: Any) = new Equalizer(left) ** * @param left the object whose type to convert toEqualizer
. * @throws NullPointerException ifleft
isnull
. */ // implicit override def convertToEqualizer[T](left: T): Equalizer[T] = new Equalizer(left) } object LegacyTripleEquals extends LegacyTripleEquals