matchFor

Finishes the specification of the sophisticated to contain expectation where the given Regex is expected to have a match.

Delegates to matchFor all(pattern)

Return

an Expect for the subject of this expectation.

Since

0.12.0

Parameters

pattern

The pattern which is 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 o exactly 1 matchFor Regex("A(BC|C/DC)")
expect("AAABC") toContain o atMost 3 matchFor Regex("A(BC|C/DC)")
expect("ABBBCD") toContain o atLeast 1 matchFor Regex("AB[BC]+")

fails {
    expect("AAAAAABBBB") toContain o atMost 3 matchFor Regex("A(BC|C/DC)")
}
fails {
    expect("AAABBBB") toContain o exactly 3 matchFor Regex("A(BC|C/DC)")
}
fails {
    expect("AAAAAABBBB") toContain o atLeast 3 matchFor Regex("A(BC|C/DC)")
}

Finishes the specification of the sophisticated to contain expectation where the given Regex 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 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: toContain o exactly 2 matchFor "a(b)?" instead of: toContain o atLeast 1 matchFor all(Regex("a(b)?"), Regex("a(b)?"))

Return

an Expect for the subject of this expectation.

Since

0.12.0

Parameters

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.

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 o exactly 1 matchFor Regex("A(BC|C/DC)")
expect("AAABC") toContain o atMost 3 matchFor Regex("A(BC|C/DC)")
expect("ABBBCD") toContain o atLeast 1 matchFor Regex("AB[BC]+")

fails {
    expect("AAAAAABBBB") toContain o atMost 3 matchFor Regex("A(BC|C/DC)")
}
fails {
    expect("AAABBBB") toContain o exactly 3 matchFor Regex("A(BC|C/DC)")
}
fails {
    expect("AAAAAABBBB") toContain o atLeast 3 matchFor Regex("A(BC|C/DC)")
}