matchFor

Finishes the specification of the sophisticated to contain expectation where the given Regex as well as the otherPatterns 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 pattern is defined as "a(b)?" and one of the otherPatterns is defined as "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.exactly(2).matchFor(Regex("a(b)?")) instead of: toContain.atLeast(1).matchFor(Regex("a(b)?"), Regex("a(b)?"))

Return

an Expect for the subject of this expectation.

Since

1.1.0

Parameters

pattern

The pattern which is expected to have a match against the input of the search.

otherPatterns

Additional patterns which are expected to have a match against the input of the search.

Samples

// `matchFor` is a final step in the CharSequence.toContain expectation-building process and can be used with
// various checkers (see CharSequenceToContainCheckerSamples)

expect("ABC").toContain.exactly(1).matchFor(Regex("A"), Regex("B"), Regex("C"))
expect("AAABC").toContain.atMost(3).matchFor(Regex("A"), Regex("B"), Regex("C"))
expect("ABBBCD").toContain.atLeast(1).matchFor(Regex("A"), Regex("B"), Regex("C"), Regex("D"))

fails {
    expect("AAAAAABBBB").toContain.atMost(3).matchFor(Regex("A"), Regex("B"))
}
fails {
    expect("AAABBBB").toContain.exactly(3).matchFor(Regex("A"), Regex("B"))
}
fails {
    expect("AAAAAABBBB").toContain.atLeast(3).matchFor(Regex("A"), Regex("B"), Regex("C"))
}