the
Finishes the specification of the sophisticated to contain expectation where the given values shall be searched, using a non-disjoint search.
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: toContain o exactly 2 the value "a" instead of: toContain o atLeast 1 the values("a", "a")
Return
an Expect for the subject of this expectation.
Parameters
The values which should not be found within the input of the search -- use the function values(t, ...) to create a Values.
Throws
in case one of the values is not a CharSequence, Number or Char.
Samples
// `values` is a final step in the CharSequence.toContain expectation-building process and can be used with
// various checkers (see CharSequenceToContainCheckerSamples)
expect("ABC") toContain o exactly 1 the values("A","B","C")
expect("AAABC") toContain o atMost 3 the values("A", "B", "C")
expect("ABBBCD") toContain o atLeast 1 the values("A", "B", "C", "D")
fails {
expect("AAAAAABBBB") toContain o atMost 3 the values("A", "B")
}
fails {
expect("AAABBBB") toContain o exactly 3 the values("A", "B")
}
fails {
expect("AAAAAABBBB") toContain o atLeast 3 the values("A", "B", "C")
}Finishes the specification of the sophisticated to contain expectation where the values shall be searched (ignoring case), using a non-disjoint search.
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: toContain o ignoring case exactly 2 the value "a" instead of: toContain o ignoring case atLeast 1 the values("a", "a")
Return
an Expect for the subject of this expectation.
Parameters
The values which are expected to be contained within the input of the search -- use the function values(t, ...) to create a Values.
Throws
in case one of the values is not a CharSequence, Number or Char.
Samples
expect("AbC") toContain o ignoring case the values("A", "B", "c")
fails {
expect("aabaabbb") toContain o ignoring case the values("A", "B", "C")
}Finishes the specification of the sophisticated to contain expectation where the values shall be searched (ignoring case), using a non-disjoint search where each need to be contained at least once.
Delegates to atLeast 1 the value.
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: toContain o ignoring case exactly 2 the value "a" instead of: toContain o ignoring case atLeast 1 the values("a", "a")
Return
an Expect for the subject of this expectation.
Parameters
The values which are expected to be contained within the input of the search -- use the function values(t, ...) to create a Values.
Throws
in case one of the values is not a CharSequence, Number or Char.
Samples
// `values` is a final step in the CharSequence.toContain expectation-building process and can be used with
// various checkers (see CharSequenceToContainCheckerSamples)
expect("ABc") toContain o ignoring case exactly 1 the values("A", "b", "C")
expect("AaaBC") toContain o ignoring case atMost 3 the values("A", "B", "c")
expect("ABBBcD") toContain o ignoring case atLeast 1 the values("a", "b", "C", "d")
fails {
expect("AAAAAABBBB") toContain o ignoring case atMost 3 the values("a", "b")
}
fails {
expect("AAABBBB") toContain o ignoring case exactly 3 the values("A", "b")
}
fails {
expect("AAAAAABBBB") toContain o ignoring case atLeast 3 the values("a", "b", "C")
}Finishes the specification of the sophisticated to contain expectation where the given regular expression patterns are expected to have a match, using a non-disjoint search.
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: toContain o exactly 2 regex "a(b)?" instead of: toContain o atLeast 1 the regexPatterns("a(b)?", "a(b)?")
Return
an Expect for the subject of this expectation.
Parameters
The patterns which are expected to have a match against the input of the search -- use the function regexPatterns(t, ...) to create a RegexPatterns.
Samples
expect("ABC") toContain o exactly 1 regex "A(BC|C/DC)"
expect("AAABC") toContain o atMost 3 regex "A(BC|C/DC)"
expect("ABBBCD") toContain o atLeast 1 regex "AB[BC]+"
fails {
expect("AAAAAABBBB") toContain o atMost 3 regex "A(BC|C/DC)"
}
fails {
expect("AAABBBB") toContain o exactly 3 regex "A(BC|C/DC)"
}
fails {
expect("AAAAAABBBB") toContain o atLeast 3 regex "A(BC|C/DC)"
}Finishes the specification of the sophisticated to contain expectation where the given regular expression patterns are expected to have a match (ignoring case), using a non-disjoint search.
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: toContain o ignoring case exactly 2 regex "a(b)?" instead of: toContain o ignoring case atLeast 1 the regexPatterns("a(b)?", "a(b)?")
Return
an Expect for the subject of this expectation.
Parameters
The patterns which are expected to have a match against the input of the search -- use the function regexPatterns(t, ...) to create a RegexPatterns.
Samples
// `regex` is a final step in the CharSequence.toContain expectation-building process and can be used with
// various checkers (see CharSequenceToContainCheckerSamples)
expect("ABc") toContain o ignoring case exactly 1 regex "A(BC|C/DC)"
expect("AaaBC") toContain o ignoring case atMost 3 regex "A(BC|C/DC)"
expect("ABBBcD") toContain o ignoring case atLeast 1 regex "AB[BC]+"
fails {
expect("AAAAAABBBB") toContain o ignoring case atMost 3 regex "A(BC|C/DC)"
}
fails {
expect("AAABBBB") toContain o ignoring case exactly 3 regex "A(BC|C/DC)"
}
fails {
expect("AAAAAABBBB") toContain o ignoring case atLeast 3 regex "A(BC|C/DC)"
}Finishes the specification of the sophisticated to contain expectation where the given regular expression patterns are expected to have at least one match (ignoring case), using a non-disjoint search.
Delegates to atLeast 1 the patterns.
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: toContain o ignoring case exactly 2 the regex "a(b)?" instead of: toContain o ignoring case atLeast 1 the RegexPatterns("a(b)?", "a(b)?")
Return
an Expect for the subject of this expectation.
Parameters
The patterns which are expected to have a match against the input of the search -- use the function regexPatterns(t, ...) to create a RegexPatterns.
Samples
expect("AbC") toContain o ignoring case regex "A(BC|C/DC)"
fails {
expect("aabaabbb") toContain o ignoring case regex "A(BC|C/DC)"
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain the expected values where it does not matter in which order they appear.
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: to contain inAny order exactly 2 value 'a' instead of: to contain inAny order exactly 1 the values('a', 'a')
Return
an Expect for the subject of this expectation.
Since
0.14.0 -- API existed for Iterable but not for IterableLike.
Parameters
The values which are expected to be contained within the IterableLike -- use the function values(t, ...) to create a Values.
Samples
expect(listOf("A", "B")) toContain o inAny order exactly 1 the values("B", "A")
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the values("B", "A")
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the values("B", "A")
fails {
expect(listOf("A", "B")) toContain o inAny order exactly 2 the values("B", "A")
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 the values("B", "A")
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the values("B", "A")
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain an entry for each in entries where it does not matter in which order they appear -- an entry is contained if it either holds all assertions entries.assertionCreatorOrNull creates or needs to be null in case entries.assertionCreatorOrNull is defined as null.
Return
an Expect for the subject of this expectation.
Since
0.14.0 -- API existed for Iterable but not for IterableLike.
Parameters
The entries which are expected to be contained within the IterableLike -- use the function entries(t, ...) to create an Entries.
Samples
expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries(
{ it toEqual "B" },
{ it toEqual "A" }
)
expect(listOf("A", null, "A", null)) toContain o inAny order exactly 2 the entries(
null,
{ it toEqual "A" }
)
expect(listOf(null, null)) toContain o inAny order exactly 2 the entries(
null
)
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the entries(
{ it toEqual "B" },
{ it toEqual "A" }
)
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the entries(
{ it toEqual "B" },
{ it toEqual "A" }
)
fails { // because the count of "A" is not 2
expect(listOf("A", "B", "B")) toContain o inAny order exactly 2 the entries(
{ it toEqual "A" },
{ it toEqual "B" }
)
}
fails { // because all elements are not null
expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 the entries(
{ it toEqual "A" },
null
)
}
fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation
expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries(
{ it toEqual "A" },
{ /* do nothing */ }
)
}
fails { // because the count of "A" is less than 2
expect(listOf("A", "B", "B")) toContain o inAny order atLeast 2 the entries(
{ it toEqual "B" },
{ it toEqual "A" }
)
}
fails { // because the count of "B" is more than 2
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the entries(
{ it toEqual "B" },
{ it toEqual "A" }
)
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the expected values where it does not matter in which order.
Return
an Expect for the subject of this expectation.
Parameters
The values which are expected to be contained within the IterableLike -- use the function values(t, ...) to create a Values.
Samples
expect(listOf("A", "B", "C")) toContain o inAny order but only the values(
"C", "B", "A"
)
fails { // because not all elements found
expect(listOf("A", "B", "C")) toContain o inAny order but only the values(
"B", "A"
)
}
fails { // because more elements expected than found
expect(listOf("A", "B", "C")) toContain o inAny order but only the values(
"D", "C", "B", "A"
)
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the expected values where it does not matter in which order.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The values which are expected to be contained within the IterableLike plus a lambda configuring the InAnyOrderOnlyReportingOptions -- use the function values(t, ..., reportOptionsInAnyOrderOnly = { ... }) to create a WithInAnyOrderOnlyReportingOptions with a wrapped Values.
Samples
expect(listOf("A", "B", "C")) toContain o inAny order but only the values(
"C", "B", "A"
)
fails { // because not all elements found
expect(listOf("A", "B", "C")) toContain o inAny order but only the values(
"B", "A"
)
}
fails { // because more elements expected than found
expect(listOf("A", "B", "C")) toContain o inAny order but only the values(
"D", "C", "B", "A"
)
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the given entries where it does not matter in which order they appear -- an entry is contained if it either holds all assertions entries.assertionCreatorOrNull creates or it needs to be null in case entries.assertionCreatorOrNull is defined as null
Notice, that a first-wins strategy applies which means your assertion creator lambdas -- which kind of serve as identification lambdas -- should be ordered in such a way that the most specific identification lambda appears first, not that a less specific lambda wins. For instance, given a setOf(1, 2) you should not search for entries({ isGreaterThan(0) }, { toEqual(1) }) but for entries({ toEqual(1) }, { isGreaterThan(0) }) otherwise isGreaterThan(0) matches 1 before toEqual(1) would match it. As a consequence toEqual(1) could only match the entry which is left -- in this case 2 -- and of course this would fail.
Return
an Expect for the subject of this expectation.
Parameters
The entries which are expected to be contained within the IterableLike -- use the function entries(t, ...) to create an Entries.
Samples
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("C") },
{ toEqual("B") },
{ toEqual("A") }
)
expect(listOf("A", null, "A", null)) toContain o inAny order but only the entries(
null,
null,
{ toEqual("A") },
{ toEqual("A") }
)
fails { // because the List contains additionally an "A" (not covered in entries)
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("C") },
{ toEqual("B") }
)
}
fails { // because the List does not contain a "D"
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("D") },
{ toEqual("C") },
{ toEqual("B") },
{ toEqual("A") }
)
}
fails { // because the List does not contain a null
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("C") },
{ toEqual("B") },
null
)
}
fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation
expect(listOf("A", "B")) toContain o inAny order but only the entries(
{ toEqual("A") },
{ /* do nothing */ }
)
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the given entries where it does not matter in which order they appear -- an entry is contained if it either holds all assertions entries.assertionCreatorOrNull creates or it needs to be null in case entries.assertionCreatorOrNull is defined as null
Notice, that a first-wins strategy applies which means your assertion creator lambdas -- which kind of serve as identification lambdas -- should be ordered in such a way that the most specific identification lambda appears first, not that a less specific lambda wins. For instance, given a setOf(1, 2) you should not search for entries({ isGreaterThan(0) }, { toEqual(1) }) but for entries({ toEqual(1) }, { isGreaterThan(0) }) otherwise isGreaterThan(0) matches 1 before toEqual(1) would match it. As a consequence toEqual(1) could only match the entry which is left -- in this case 2 -- and of course this would fail.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The entries which are expected to be contained within the IterableLike plus a lambda configuring the InAnyOrderOnlyReportingOptions -- use the function entries(t, ..., reportOptionsInAnyOrderOnly = { ... }) to create a WithInAnyOrderOnlyReportingOptions with a wrapped Entries.
Samples
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("C") },
{ toEqual("B") },
{ toEqual("A") }
)
expect(listOf("A", null, "A", null)) toContain o inAny order but only the entries(
null,
null,
{ toEqual("A") },
{ toEqual("A") }
)
fails { // because the List contains additionally an "A" (not covered in entries)
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("C") },
{ toEqual("B") }
)
}
fails { // because the List does not contain a "D"
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("D") },
{ toEqual("C") },
{ toEqual("B") },
{ toEqual("A") }
)
}
fails { // because the List does not contain a null
expect(listOf("A", "B", "C")) toContain o inAny order but only the entries(
{ toEqual("C") },
{ toEqual("B") },
null
)
}
fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation
expect(listOf("A", "B")) toContain o inAny order but only the entries(
{ toEqual("A") },
{ /* do nothing */ }
)
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only and all elements of the given IterableLike in the specified order.
Delegates to values.
Notice that a runtime check applies which assures that only Iterable, Sequence or one of the Array types are passed (this can be changed via IterableLikeToIterableTransformer). This function expects IterableLike (which is a typealias for Any) to avoid cluttering the API.
Return
an Expect for the subject of this expectation.
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The IterableLike whose elements are expected to be contained within this IterableLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function elementsOf(iterableLike, report = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped IterableLike.
Throws
in case the wrapped IterableLike is not an Iterable, Sequence or one of the Array types or the wrapped IterableLike does not have elements (is empty).
Samples
expect(listOf("A", "B", "C")) toContain o inGiven order and only elementsOf (listOf("A", "B", "C"))
fails { // although same elements but not in same order
expect(listOf("A", "B", "C")) toContain o inGiven order and only elementsOf (listOf("A", "C", "B"))
}
fails { // because not all elements found
expect(listOf("A", "B", "C")) toContain o inGiven order and only elementsOf (listOf("A", "B"))
}
fails { // because more elements expected than found
expect(listOf("A", "B", "C")) toContain o inGiven order and only elementsOf (listOf("A", "B", "C", "D"))
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the expected values in the specified order.
Return
an Expect for the subject of this expectation.
Since
0.14.0 -- API existed for Iterable but not for IterableLike.
Parameters
The values which are expected to be contained within the IterableLike -- use the function values(t, ...) to create a Values.
Samples
expect(listOf("A", "B", "C")) toContain o inGiven order and only the values("A", "B", "C")
fails { // although same elements but not in same order
expect(listOf("A", "B", "C")) toContain o inGiven order and only the values("A", "C", "B")
}
fails { // because not all elements found
expect(listOf("A", "B", "C")) toContain o inGiven order and only the values("A", "B")
}
fails { // because more elements expected than found
expect(listOf("A", "B", "C")) toContain o inGiven order and only the values("A", "B", "C", "D")
}
fails { // because order is wrong
expect(listOf("A", "B", "C")) toContain o inGiven order and only the values("B", "A")
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the expected values in the specified order.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The values which are expected to be contained within the IterableLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function values(t, ..., reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped Values.
Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the given entries in the specified order -- an entry is contained if it either holds all assertions entries.assertionCreatorOrNull creates or it needs to be null in case entries.assertionCreatorOrNull is defined as null
Return
an Expect for the subject of this expectation.
Since
0.14.0 -- API existed for Iterable but not for IterableLike.
Parameters
The entries which are expected to be contained within the IterableLike -- use the function entries(t, ...) to create an Entries.
Samples
expect(listOf("A", "B", "C")) toContain o inGiven order and only the entries(
{ it toEqual "A" },
{ it toEqual "B" },
{ it toEqual "C" })
expect(listOf(null, "A", null, "A")) toContain o inGiven order and only the entries(
null,
{ it toEqual "A" },
null,
{ it toEqual "A" })
fails { // because the List contains an additional "A" at the beginning
expect(listOf("A", "B", "C")) toContain o inGiven order and only the entries(
{ it toEqual "B" },
{ it toEqual "C" })
}
fails { // because the List does not contain a "D" at the end
expect(listOf("A", "B", "C")) toContain o inGiven order and only the entries(
{ it toEqual "A" },
{ it toEqual "B" },
{ it toEqual "C" },
{ it toEqual "D" })
}
fails { // because the List contains a "C" and not null at the end
expect(listOf("A", "B", "C")) toContain o inGiven order and only the entries(
{ it toEqual "A" },
{ it toEqual "B" },
null
)
}
fails { // because order is wrong
expect(listOf("A", "B", "C")) toContain o inGiven order and only the entries(
{ it toEqual "C" },
{ it toEqual "B" },
{ it toEqual "A" })
}
fails { // because order is wrong
expect(listOf(null, "A", null)) toContain o inGiven order and only the entries(
null,
null,
{ it toEqual "A" },
)
}
fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation
expect(listOf("A", "B")) toContain o inGiven order and only the entries(
{ it toEqual "A" },
{ /* do nothing */ })
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the given entries in the specified order -- an entry is contained if it either holds all assertions entries.assertionCreatorOrNull creates or it needs to be null in case entries.assertionCreatorOrNull is defined as null
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The entries which are expected to be contained within the IterableLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function entries(t, ..., reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped Entries.
Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only and all elements of the given IterableLike in the specified order.
Delegates to values.
Notice that a runtime check applies which assures that only Iterable, Sequence or one of the Array types are passed (this can be changed via IterableLikeToIterableTransformer). This function expects IterableLike (which is a typealias for Any) to avoid cluttering the API.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The IterableLike whose elements are expected to be contained within this IterableLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function elementsOf(iterableLike, report = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped IterableLike.
Throws
in case the wrapped IterableLike is not an Iterable, Sequence or one of the Array types or the wrapped IterableLike does not have elements (is empty).
Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain the given key-value pairs where it does not matter in which order they appear.
Notice, that it does not search for unique matches. Meaning, if the map is mapOf('a' to 1) and one of the Pair in pairs 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.
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order the pairs(
2 to "b"
)
fails { // because the value ("b") of key 1 (which exists in the subject) is not "b"
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order the pairs(1 to "b")
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain the given keyValues where it does not matter in which order they appear -- an entry is contained if it has a key as defined by keyValue's KeyWithValueCreator.key and 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.
Notice, that it does not search for unique matches. Meaning, if the map is mapOf('a' to 1) and one KeyWithValueCreator in keyValues 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
Since
0.15.0
Parameters
The KeyWithValueCreators -- use the function keyValues(keyValue(key1) { ... }, keyValue(key2) { ... }, ...) to create a KeyValues.
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order the entries(keyValue(2) { this toEqual "b" })
fails { // because the value ("b") of key 1 (which exists in the subject) is not "b"
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order the entries(keyValue(1) { this toEqual "b" })
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given key-value pairs where it does not matter in which order they appear.
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order but only the pairs(
2 to "b", 1 to "a"
)
fails { // because subject has additional entries
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order but only the pairs(1 to "a")
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given entries where it does not matter in which order they appear -- an entry is contained if it has a key as defined by keyValue's KeyWithValueCreator.key and 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.
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
The KeyWithValueCreators -- use the function keyValues(keyValue(key1) { ... }, keyValue(key2) { ... }, ...) to create a KeyValues.
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order but only the entries(
keyValue(2) { this toEqual "b" },
keyValue(1) { this toEqual "a" },
)
fails { // because subject has additional entries
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order but only the entries(
keyValue(1) { this toEqual "a" }
)
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given key-value pairs in the specified order.
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inGiven order and only the pairs(
1 to "a", 2 to "b"
)
fails { // because the pair entries (which all exist in the subject) do not have the same order
expect(mapOf(1 to "a", 2 to "b")) toContain o inGiven order and only the pairs(
2 to "b",
1 to "a",
)
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given pairs in the specified order.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The key-value pairs which are expected to be contained within the MapLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function pairs(t, ..., reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped Pairs.
Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given entries in the specified order -- an entry is contained if it has a key as defined by keyValue's KeyWithValueCreator.key and 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.
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
The KeyWithValueCreators -- use the function entries(keyValue(key1) { ... }, keyValue(key2) { ... }, ...) to create a KeyValues.
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inGiven order and only the entries(
keyValue(1) { this toEqual "a" },
keyValue(2) { this toEqual "b" },
)
fails { // because the pair entries (which all exist in the subject) do not have the same order
expect(mapOf(1 to "a", 2 to "b")) toContain o inGiven order and only the entries(
keyValue(2) { this toEqual "b" },
keyValue(1) { this toEqual "a" },
)
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given entries in the specified order -- an entry is contained if it has a key as defined by keyValue's KeyWithValueCreator.key and 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.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The KeyWithValueCreators plus a lambda configuring the InOrderOnlyReportingOptions -- use the function entries(keyValue(key1) { ... }, keyValue(key2) { ... }, ..., reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped KeyValues.
Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only and all entries of the given MapLike in the specified order.
Delegates to the pairs
Notice that a runtime check applies which assures that only Map and IterableLike (i.e. Iterable, Sequence or one of the Array types) are passed (this can be changed via MapLikeToIterablePairTransformer and IterableLikeToIterableTransformer). This function expects MapLike (which is a typealias for Any) to avoid cluttering the API.
Return
an Expect for the subject of this expectation.
Since
0.18.0
Parameters
The MapLike whose elements are expected to be contained within this MapLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function entriesOf(mapLike, report = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped MapLike.