infix fun <T : CharSequence> Expect<T>.contains(o: o): CharSequenceContains.EntryPointStep<T, NoOpSearchBehaviour>
(source)
Starts a sophisticated contains
assertion building process based on this Expect.
expect("ABC") contains o exactly 1 value "A"
expect("ABBC") contains o atLeast 2 value "B"
fails {
expect("AAAAAA") contains o atMost 3 value "A"
}
o
- The filler object o.
Return
The newly created builder.
infix fun <T : CharSequence> Expect<T>.contains(expected: CharSequenceOrNumberOrChar): Expect<T>
(source)
Expects that the subject of this
expectation (a CharSequence) contains the expected's toString representation.
It is a shortcut for contains o atLeast 1 value expected
.
Notice that a runtime check applies which assures that only CharSequence, Number and Char are passed. This function expects CharSequenceOrNumberOrChar (which is a typealias for Any) for your convenience, so that you can mix String and Int for instance.
expect("ABC") contains "B"
expect("ABC123") contains values("AB", 'C', 12)
// holds because `contains` does not search for unique matches
// use `contains o exactly 2 value "A"` to check if subject contains two "A"s
expect("ABC") contains values("A", "A")
fails {
expect("ABC") contains "X"
}
fails { // because subject does not contain all values
expect("ABC") contains values("A", 99)
}
IllegalArgumentException
- in case expected is not a CharSequence, Number or Char.
Return
This assertion container to support a fluent API.
infix fun <T : CharSequence> Expect<T>.contains(values: Values<CharSequenceOrNumberOrChar>): Expect<T>
(source)
Expects that the subject of this
expectation (a CharSequence) contains the toString representation of the
given values using a non disjoint search.
It is a shortcut for contains o atLeast 1 the values(expected, *otherExpected)
.
Notice that a runtime check applies which assures that only CharSequence, Number and Char are passed. This function expects CharSequenceOrNumberOrChar (which is a typealias for Any) for your convenience, so that you can mix String and Int for instance.
By non disjoint is meant that "aa"
in "aaaa"
is found three times and not only two times.
Also notice, that it does not search for unique matches. Meaning, if the input of the search is "a"
and
Values is defined as values("a", "a")
, then both match,
even though they match the same sequence in the input of the search.
Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.
Meaning you might want to use:
contains o exactly 2 value "a"
instead of:
contains values("a", "a")
expect("ABC") contains "B"
expect("ABC123") contains values("AB", 'C', 12)
// holds because `contains` does not search for unique matches
// use `contains o exactly 2 value "A"` to check if subject contains two "A"s
expect("ABC") contains values("A", "A")
fails {
expect("ABC") contains "X"
}
fails { // because subject does not contain all values
expect("ABC") contains values("A", 99)
}
values
- The values which are expected to be contained within the input of the search
-- use the function values(t, ...)
to create a Values.
IllegalArgumentException
- in case one of the values is not a
CharSequence, Number or Char.
Return
This assertion container to support a fluent API.
infix fun <T : CharSequence> Expect<T>.contains(pattern: Regex): Expect<T>
(source)
Expects that the subject of this
expectation (a CharSequence) contains a sequence which matches the given
regular expression pattern.
It is a shortcut for contains o atLeast 1 matchFor pattern
.
expect("ABC") contains "(B)?C".toRegex()
fails {
expect("ABC") contains "X".toRegex()
}
pattern
- The pattern which is expected to have a match against the input of the search.
Return
This assertion container to support a fluent API.
infix fun <T : CharSequence> Expect<T>.contains(regexPatterns: RegexPatterns): Expect<T>
(source)
Expects that the subject of this
expectation (a CharSequence) contains a sequence which matches the given
regular expression regexPatterns, using a non disjoint search.
It is a shortcut for contains o atLeast 1 the regexPatterns(pattern, *otherPatterns)
.
By non disjoint is meant that "aa"
in "aaaa"
is found three times and not only two times.
Also notice, that it does not search for unique matches. Meaning, if the input of the search is "ab"
and
RegexPatterns is defined as regexPatterns("a(b)?", "a(b)?")
as well, then both match,
even though they match the same sequence in the input of the search.
Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.
Meaning you might want to use:
contains o exactly 2 regex "a(b)?"
instead of:
contains o atLeast 1 the regexPatterns("a(b)?", "a(b)?")
// all regex patterns match
expect("ABC") contains regexPatterns("A(B)?", "(B)?C")
// holds because `contains regexPatterns(...)` does not search for unique matches
// use `contains exactly 2 regex "A(B)?"` to check if subject contains the regex two times
expect("ABC") contains regexPatterns("A(B)?", "A(B)?")
fails { // because second regex doesn't match
expect("ABC") contains regexPatterns("A", "X")
}
regexPatterns
- The patterns which are expected to have a match against the input of the search --
use the function regexPatterns(t, ...)
to create a RegexPatterns.
Return
This assertion container to support a fluent API.
infix fun <T : CharSequence> Expect<T>.contains(patterns: All<Regex>): Expect<T>
(source)
Expects that the subject of this
expectation (a CharSequence) contains a sequence which matches the given
regular expression patterns, using a non disjoint search.
It is a shortcut for contains o atLeast 1 regex All(pattern, *otherPatterns)
.
By non disjoint is meant that "aa"
in "aaaa"
is found three times and not only two times.
Also notice, that it does not search for unique matches. Meaning, if the input of the search is "ab"
and
All is defined as all(Regex("a(b)?"), Regex("a(b)?"))
as well, then both match,
even though they match the same sequence in the input of the search.
Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.
Meaning you might want to use:
contains o exactly 2 regex "a(b)?"
instead of:
contains o atLeast 1 the all(Regex("a(b)?"), Regex("a(b)?"))
// all regex patterns match
expect("ABC") contains all("A".toRegex(), "B".toRegex())
// holds because `contains all(...)` does not search for unique matches
// use `contains exactly 2 regex regex` to check if subject contains the regex two times
val regex = "A(B)?".toRegex()
expect("ABC") contains all(regex, regex)
fails { // because second regex doesn't match
expect("ABC") contains all("A".toRegex(), "X".toRegex())
}
patterns
- The patterns which are expected to have a match against the input of the search --
use the function all(Regex(...), ...)
to create a All.
Return
This assertion container to support a fluent API.
infix fun <E, T : Iterable<E>> Expect<T>.contains(expected: E): Expect<T>
(source)
Expects that the subject of this
expectation (an Iterable) contains the expected value.
It is a shortcut for contains o inAny order atLeast 1 value expected
Return
an Expect for the subject of this
expectation.
infix fun <E, T : Iterable<E>> Expect<T>.contains(values: Values<E>): Expect<T>
(source)
Expects that the subject of this
expectation (an Iterable) contains the expected values.
It is a shortcut for contains o inAny order atLeast 1 the values(...)
Notice, that it does not search for unique matches. Meaning, if the iterable is setOf('a', 'b')
and
Values is defined as values("a", "a")
, then both match,
even though they match the same sequence in the input of the search.
Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.
Meaning you might want to use:
contains o inAny order exactly 2 value 'a'
instead of:
contains values('a', 'a')`
values
- The values which are expected to be contained within the Iterable
-- use the function values(t, ...)
to create a Values.
Return
an Expect for the subject of this
expectation.
infix fun <E : Any, T : Iterable<E?>> Expect<T>.contains(assertionCreatorOrNull: (Expect<E>.() -> Unit)?): Expect<T>
(source)
Expects that the subject of this
expectation (an Iterable) contains an entry holding the
assertions created by assertionCreatorOrNull or an entry which is null
in case assertionCreatorOrNull
is defined as null
.
It is a shortcut for contains o inAny order atLeast 1 entry assertionCreatorOrNull
assertionCreatorOrNull
- The identification lambda which creates the assertions which the entry we are looking
for has to hold; or in other words, the function which defines whether an entry is the one we are looking for
or not. In case it is defined as null
, then an entry is identified if it is null
as well.
Return
an Expect for the subject of this
expectation.
infix fun <E : Any, T : Iterable<E?>> Expect<T>.contains(entries: Entries<E>): Expect<T>
(source)
Expects that the subject of this
expectation (an Iterable) contains an entry holding the
assertions created by entries.assertionCreatorOrNull or an entry
which is null
in case entries.assertionCreatorOrNull
is defined as null
-- likewise an entry (can be the same) is searched for each of the
entries.otherAssertionCreatorsOrNulls.
It is a shortcut for contains o inAny order atLeast 1 the entries({ ... }, ...)
entries
- The entries which are expected to be contained within the Iterable
-- use the function entries(t, ...)
to create an Entries.
Return
an Expect for the subject of this
expectation.
infix fun <E, T : Iterable<E>> Expect<T>.contains(noDuplicates: noDuplicates): Expect<T>
(source)
Expects that the subject of this
expectation (an Iterable) does not have duplicate elements.
Return
an Expect for the subject of this
expectation.
Since
0.14.0
infix fun <K, V, T : Map<out K, V>> Expect<T>.contains(keyValuePair: Pair<K, V>): Expect<T>
(source)
Expects that the subject of this
expectation (a Map) contains a key as defined by keyValuePair's Pair.first
with a corresponding value as defined by keyValuePair's Pair.second
Delegates to 'it contains o inAny order entry keyValuePair'.
Return
an Expect for the subject of this
expectation.
infix fun <K, V, T : Map<out K, V>> Expect<T>.contains(keyValuePairs: Pairs<K, V>): Expect<T>
(source)
Expects the subject of this
expectation (a Map) contains for each entry in keyValuePairs,
a key as defined by that entry's Pair.first with a corresponding value as defined by entry's Pair.second.
Delegates to it contains o inAny order keyValuePairs keyValuePairs
Notice, that it does not search for unique matches. Meaning, if the map is mapOf('a' to 1)
and one of the Pair
in keyValuePairs is defined as 'a' to 1
and another one is defined as 'a' to 1
as well, then both match,
even though they match the same entry.
keyValuePairs
- The key-value Pairs expected to be contained within this Map
-- use the function pairs(x to y, ...)
to create a Pairs.
Return
an Expect for the subject of this
expectation.
inline infix fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(keyValue: KeyWithValueCreator<K, V>): Expect<T>
(source)
Expects that the subject of this
expectation (a Map) contains a key as defined by keyValue's KeyWithValueCreator.key
with a corresponding value which either holds all assertions keyValue's
KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null
in case
KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null
Delegates to it contains o inAny order keyValue keyValue
keyValue
- The KeyWithValueCreator whose key is expected to be contained within this Map and
where the corresponding value holds all assertions the KeyWithValueCreator.valueAssertionCreatorOrNull creates
or needs to be null
in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null
-- use the function keyValue(x) { ... }
to create a KeyWithValueCreator.
Return
an Expect for the subject of this
expectation.
inline infix fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(allKeyValues: KeyValues<K, V>): Expect<T>
(source)
Expects that the subject of this
expectation (a Map) contains for each KeyWithValueCreator in allKeyValues,
a key as defined by KeyWithValueCreator.key with a corresponding value which either holds all
assertions KeyWithValueCreator's KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs
to be null
in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null
Delegates to it contains o inAny order the keyValues
Notice, that it does not search for unique matches. Meaning, if the map is mapOf('a' to 1)
and
one KeyWithValueCreator in allKeyValues is defined as Key('a') { isGreaterThan(0) }
and
another one is defined as Key('a') { isLessThan(2) }
, then both match, even though they match the same entry.
Return
an Expect for the subject of this
expectation.
inline infix fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(all: All<KeyWithValueCreator<K, V>>): Expect<T>
(source)