Skip to content

Commit

Permalink
Add samples for CharSequence.toContain...regex/matchFor #1521
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos-Tsiougranas committed Aug 30, 2023
1 parent f95fd93 commit 3409d1f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ fun <T : CharSequence> EntryPointStep<T, IgnoringCaseSearchBehaviour>.values(
* @param otherPatterns Additional patterns which are expected to have a match against the input of the search.
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.CharSequenceToContainCreatorSamples.regex
*
*/
fun <T : CharSequence> CheckerStep<T, NoOpSearchBehaviour>.regex(
pattern: String,
Expand Down Expand Up @@ -268,6 +271,9 @@ fun <T : CharSequence> CheckerStep<T, NoOpSearchBehaviour>.regex(
* @return an [Expect] for the subject of `this` expectation.
*
* @since 1.1.0
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.CharSequenceToContainCreatorSamples.matchFor
*
*/
fun <T : CharSequence> CheckerStep<T, NoOpSearchBehaviour>.matchFor(
pattern: Regex,
Expand All @@ -293,6 +299,9 @@ fun <T : CharSequence> CheckerStep<T, NoOpSearchBehaviour>.matchFor(
* @param otherPatterns Additional patterns which are expected to have a match against the input of the search.
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.CharSequenceToContainCreatorSamples.regexIgnoringCaseWithChecker
*
*/
@JvmName("regexIgnoringCase")
fun <T : CharSequence> CheckerStep<T, IgnoringCaseSearchBehaviour>.regex(
Expand Down Expand Up @@ -322,6 +331,9 @@ fun <T : CharSequence> CheckerStep<T, IgnoringCaseSearchBehaviour>.regex(
* @param otherPatterns Additional patterns which are expected to have a match against the input of the search.
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.CharSequenceToContainCreatorSamples.regexIgnoringCase
*
*/
fun <T : CharSequence> EntryPointStep<T, IgnoringCaseSearchBehaviour>.regex(
pattern: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,66 @@ class CharSequenceToContainCreatorSamples {
expect("AAAAAABBBB").toContain.ignoringCase.atLeast(3).values("a", "b", "C")
}
}

@Test
fun regex() {
expect("ABC").toContain.exactly(1).regex("A", "B", "C")
expect("AAABC").toContain.atMost(3).regex("A", "B", "C")
expect("ABBBCD").toContain.atLeast(1).regex("A", "B", "C", "D")
fails {
expect("AAAAAABBBB").toContain.atMost(3).regex("A", "B")
}

fails {
expect("AAABBBB").toContain.exactly(3).regex("A", "B")
}

fails {
expect("AAAAAABBBB").toContain.atLeast(3).regex("A", "B", "C")
}
}

@Test
fun regexIgnoringCase() {
expect("AbC").toContain.ignoringCase.regex("A", "B", "c")
fails {
expect("aabaabbb").toContain.ignoringCase.regex("A", "B", "C")
}
}

@Test
fun regexIgnoringCaseWithChecker() {
expect("ABc").toContain.ignoringCase.exactly(1).regex("A", "b", "C")
expect("AaaBC").toContain.ignoringCase.atMost(3).regex("A", "B", "c")
expect("ABBBcD").toContain.ignoringCase.atLeast(1).regex("a", "b", "C", "d")
fails {
expect("AAAAAABBBB").toContain.ignoringCase.atMost(3).regex("a", "b")
}

fails {
expect("AAABBBB").toContain.ignoringCase.exactly(3).regex("A", "b")
}

fails {
expect("AAAAAABBBB").toContain.ignoringCase.atLeast(3).regex("a", "b", "C")
}
}

@Test
fun matchFor() {
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"))
}
}
}

0 comments on commit 3409d1f

Please sign in to comment.