AbstractStringUniformity
Convenience base trait for string Uniformity
s.
This trait defines a normalizedCanHandle
method that returns true if the passed
Any
is a String
and a normalizedOrSame
method that
normalizes any passed String
s 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)
Value members
Concrete methods
Returns true if the passed Any
is a String
.
Returns true if the passed Any
is a String
.
- Returns:
true if the passed
Any
is aString
.- Source:
- AbstractStringUniformity.scala
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 tonormalized
-
else, the same exact object that was passed
- Returns:
a normalized form of any passed
String
, or the same object if not aString
.- Source:
- AbstractStringUniformity.scala
Inherited methods
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
- Returns:
a
Uniformity
representing the composition of this and the passedUniformity
- Inherited from:
- Uniformity
- Source:
- Uniformity.scala
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
- Returns:
a
Normalization
representing the composition of this and the passedNormalization
- Inherited from:
- Normalization
- Source:
- Normalization.scala
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
- Returns:
the normalized form of the passed object
- Inherited from:
- Normalization
- Source:
- Normalization.scala
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 returnedNormalizingEquality
will delegate to determine equality after normalizing both left and right (if appropriate) sides.
- Inherited from:
- Uniformity
- Source:
- Uniformity.scala
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 returnedNormalizingEquivalence
will delegate to determine equality after normalizing both left and right (if appropriate) sides.
- Inherited from:
- Normalization
- Source:
- Normalization.scala