AbstractStringUniformity

org.scalactic.AbstractStringUniformity
trait AbstractStringUniformity extends Uniformity[String]

Convenience base trait for string Uniformitys.

This trait defines a normalizedCanHandle method that returns true if the passed Any is a String and a normalizedOrSame method that normalizes any passed Strings via the normalized method, which is left abstract for subclasses to fill in.

Here's an example in which AbstractStringUniformity is used to normalize strings by ensuring the first character, if any, is capitalized:

val capitalized: Uniformity[String] =
 new AbstractStringUniformity {
   def normalized(s: String): String =
     if (s.isEmpty) "" else s.charAt(0).toUpper + s.substring(1)
 }

Here's an example of using the capitalized Uniformity with a Matcher expression:

scala> import org.scalatest._
import org.scalatest._

scala> import Matchers._
import Matchers._

scala> import org.scalactic._
import org.scalactic._

scala> val capitalized: Uniformity[String] =
    |   new AbstractStringUniformity {
    |     def normalized(s: String): String =
    |       if (s.isEmpty) "" else s.charAt(0).toUpper + s.substring(1)
    |   }
capitalized: org.scalactic.Uniformity[String] = $anon$1@65601e00

scala> "Hello" should equal ("hello") (after being capitalized)

Attributes

Source
AbstractStringUniformity.scala
Graph
Supertypes
trait Uniformity[String]
trait Normalization[String]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

final def normalizedCanHandle(b: Any): Boolean

Returns true if the passed Any is a String.

Returns true if the passed Any is a String.

Attributes

Returns

true if the passed Any is a String.

Source
AbstractStringUniformity.scala
final def normalizedOrSame(b: Any): Any

Normalizes the passed object if it is a String.

Normalizes the passed object if it is a String.

This method returns either:

  • if the passed object is a String, the result of passing that string to normalized

  • else, the same exact object that was passed

Attributes

Returns

a normalized form of any passed String, or the same object if not a String.

Source
AbstractStringUniformity.scala

Inherited methods

final def and(other: Uniformity[String]): Uniformity[A]

Returns a new Uniformity that combines this and the passed Uniformity.

Returns a new Uniformity that combines this and the passed Uniformity.

The normalized and normalizedOrSame methods of the Uniformity returned by this method return a result obtained by forwarding the passed value first to this Uniformity's implementation of the method, then passing that result to the other Uniformity's implementation of the method, respectively. Essentially, the body of the composed normalized method is:

uniformityPassedToAnd.normalized(uniformityOnWhichAndWasInvoked.normalized(a))

And the body of the composed normalizedOrSame method is:

uniformityPassedToAnd.normalizedOrSame(uniformityOnWhichAndWasInvoked.normalizedOrSame(a))

The normalizeCanHandle method of the Uniformity returned by this method returns a result obtained by anding the result of forwarding the passed value to this Uniformity's implementation of the method with the result of forwarding it to the passed Uniformity's implementation. Essentially, the body of the composed normalizeCanHandle method is:

uniformityOnWhichAndWasInvoked.normalizeCanHandle(a) && uniformityPassedToAnd.normalizeCanHandle(a)

Value parameters

other

a Uniformity to 'and' with this one

Attributes

Returns

a Uniformity representing the composition of this and the passed Uniformity

Inherited from:
Uniformity
Source
Uniformity.scala
final def and(other: Normalization[String]): Normalization[A]

Returns a new Normalization that composes this and the passed Normalization.

Returns a new Normalization that composes this and the passed Normalization.

The normalized method of the Normalization returned by this method returns a normalized form of the passed object obtained by forwarding the passed value first to this Normalization's normalized method, then passing that result to the other Normalization's normalized method. Essentially, the body of the composed normalized method is:

normalizationPassedToAnd.normalized(normalizationOnWhichAndWasInvoked.normalized(a))

Value parameters

other

a Normalization to 'and' with this one

Attributes

Returns

a Normalization representing the composition of this and the passed Normalization

Inherited from:
Normalization
Source
Normalization.scala
def normalized(a: String): A

Returns a normalized form of the passed object.

Returns a normalized form of the passed object.

If the passed object is already in normal form, this method may return the same instance passed.

Type parameters

A

the type of the object to normalize

Value parameters

a

the object to normalize

Attributes

Returns

the normalized form of the passed object

Inherited from:
Normalization
Source
Normalization.scala
final def toEquality(implicit equality: Equality[String]): NormalizingEquality[A]

Converts this Uniformity to a NormalizingEquality[A] whose normalized, normalizedCanHandle, and normalizedOrSame methods delegate to this Uniformity[A] and whose afterNormalizationEquality field returns the implicitly passed Equality[A].

Converts this Uniformity to a NormalizingEquality[A] whose normalized, normalizedCanHandle, and normalizedOrSame methods delegate to this Uniformity[A] and whose afterNormalizationEquality field returns the implicitly passed Equality[A].

Value parameters

equality

the Equality that the returned NormalizingEquality will delegate to determine equality after normalizing both left and right (if appropriate) sides.

Attributes

Inherited from:
Uniformity
Source
Uniformity.scala
final def toEquivalence(implicit equivalence: Equivalence[String]): NormalizingEquivalence[A]

Converts this Normalization to a NormalizingEquivalence[A] whose normalized method delegates to this Normalization[A] and whose afterNormalizationEquivalence field returns the implicitly passed Equivalence[A].

Converts this Normalization to a NormalizingEquivalence[A] whose normalized method delegates to this Normalization[A] and whose afterNormalizationEquivalence field returns the implicitly passed Equivalence[A].

Value parameters

equivalence

the Equivalence that the returned NormalizingEquivalence will delegate to determine equality after normalizing both left and right (if appropriate) sides.

Attributes

Inherited from:
Normalization
Source
Normalization.scala