infix fun <T : CharSequence> Expect<T>.contains(o: o): CharSequenceContains.EntryPointStep<T, NoOpSearchBehaviour>
Starts a sophisticated contains
assertion building process based on this Expect.
o
- The filler object o.
Return
The newly created builder.
infix fun <T : CharSequence> Expect<T>.contains(expected: CharSequenceOrNumberOrChar): Expect<T>
Expects that the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
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>
Expects that the subject of the assertion (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")
values
- The values which are expected to be contained within the input of the search
-- use the function values(t, ...)
to create a Values.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
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>
Expects that the subject of the assertion (a CharSequence) contains a sequence which matches the given regular expression pattern.
It is a shortcut for contains o atLeast 1 matchFor pattern
.
pattern
- The pattern which is expected to have a match against the input of the search.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
This assertion container to support a fluent API.
infix fun <T : CharSequence> Expect<T>.contains(regexPatterns: RegexPatterns): Expect<T>
Expects that the subject of the assertion (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)?")
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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
This assertion container to support a fluent API.
infix fun <T : CharSequence> Expect<T>.contains(patterns: All<Regex>): Expect<T>
Expects that the subject of the assertion (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)?"))
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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
This assertion container to support a fluent API.
infix fun <E, T : Iterable<E>> Expect<T>.contains(expected: E): Expect<T>
Expects that the subject of the assertion (an Iterable) contains the expected value.
It is a shortcut for contains o inAny order atLeast 1 value expected
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
infix fun <E, T : Iterable<E>> Expect<T>.contains(values: Values<E>): Expect<T>
Expects that the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
infix fun <E : Any, T : Iterable<E?>> Expect<T>.contains(assertionCreatorOrNull: (Expect<E>.() -> Unit)?): Expect<T>
Expects that the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
infix fun <E : Any, T : Iterable<E?>> Expect<T>.contains(entries: Entries<E>): Expect<T>
Expects that the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
infix fun <E, T : Iterable<E>> Expect<T>.contains(noDuplicates: noDuplicates): Expect<T>
Expects that the subject of the assertion (an Iterable) does not have duplicate elements.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
Since
0.14.0
infix fun <K, V, T : Map<out K, V>> Expect<T>.contains(keyValuePair: Pair<K, V>): Expect<T>
Expects that the subject of the assertion (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'.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
infix fun <K, V, T : Map<out K, V>> Expect<T>.contains(keyValuePairs: Pairs<K, V>): Expect<T>
Expects the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
inline infix fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(keyValue: KeyWithValueCreator<K, V>): Expect<T>
Expects that the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.
inline infix fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(allKeyValues: KeyValues<K, V>): Expect<T>
Expects that the subject of the assertion (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.
AssertionError
- Might throw an AssertionError if the assertion made is not correct.
Return
An Expect for the current subject of the assertion.