Skip to content

Commit

Permalink
Merge pull request #1813 from hubtanaka/hubtanaka/samples/Iterable-to…
Browse files Browse the repository at this point in the history
…Contain-entry

add samples for Iterable.toContain....entry
  • Loading branch information
robstoll authored Aug 14, 2024
2 parents 0201c11 + bfb4bc3 commit fd0706e
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fun <E, T: IterableLike> CheckerStep<E, T, InAnyOrderSearchBehaviour>.values(
* @return an [Expect] for the subject of `this` expectation.
*
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.entry
*/
fun <E : Any, T: IterableLike> CheckerStep<out E?, T, InAnyOrderSearchBehaviour>.entry(
assertionCreatorOrNull: (Expect<E>.() -> Unit)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ fun <E, T : IterableLike> EntryPointStep<E, T, InAnyOrderOnlySearchBehaviour>.va
* @return an [Expect] for the subject of `this` expectation.
*
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableLikeToContainInAnyOrderOnlyCreatorSamples.entry
*/
fun <E : Any, T : IterableLike> EntryPointStep<out E?, T, InAnyOrderOnlySearchBehaviour>.entry(
assertionCreatorOrNull: (Expect<E>.() -> Unit)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ fun <E, T : IterableLike> EntryPointStep<E, T, InOrderOnlySearchBehaviour>.value
* @return an [Expect] for the subject of `this` expectation.
*
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableLikeToContainInOrderOnlyCreatorSamples.entry
*/
fun <E : Any, T : IterableLike> EntryPointStep<out E?, T, InOrderOnlySearchBehaviour>.entry(
assertionCreatorOrNull: (Expect<E>.() -> Unit)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,51 @@ class IterableLikeToContainInAnyOrderCreatorSamples {
}
}

@Test
fun entry() {
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(1).entry {
toEqual("A")
}

expect(listOf("A", null, null)).toContain.inAnyOrder.exactly(2).entry(null) // null is identified

expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(2).entry {
toEqual("A")
}

expect(listOf("A", "B", "B")).toContain.inAnyOrder.atMost(2).entry {
toEqual("A")
}

fails { // because the count of "A" is not 2
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(2).entry {
toEqual("A")
}
}

fails { // because all elements are not null
expect(listOf("A", "B", "C")).toContain.inAnyOrder.exactly(1).entry(null)
}

fails { // because assertionCreatorOrNull is non-null and has no expectation
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.exactly(1).entry {
/* do nothing */
}
}

fails { // because the count of "A" is less than 3
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(3).entry {
toEqual("A")
}
}

fails { // because the count of "B" is more than 2
expect(listOf("A", "B", "B", "B")).toContain.inAnyOrder.atMost(2).entry {
toEqual("B")
}
}
}

@Test
fun elementsOf() {
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(1).elementsOf(listOf("A", "B"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class IterableLikeToContainInAnyOrderOnlyCreatorSamples {
fun value() {
expect(listOf("A")).toContain.inAnyOrder.only.value("A")

fails { // because subject list does not contain expected value
fails { // because the List does not contain expected value
expect(listOf("B")).toContain.inAnyOrder.only.value("A")
}

fails { // because subject list contains multiple elements
fails { // because the List contains multiple elements
expect(listOf("A", "A")).toContain.inAnyOrder.only.value("A")
}
}
Expand All @@ -37,6 +37,37 @@ class IterableLikeToContainInAnyOrderOnlyCreatorSamples {
}
}

@Test
fun entry() {
expect(listOf("A")).toContain.inAnyOrder.only.entry {
toEqual("A")
}

expect(listOf(null)).toContain.inAnyOrder.only.entry(null)

fails { // because the List does not contain "A"
expect(listOf("B")).toContain.inAnyOrder.only.entry {
toEqual("A")
}
}

fails { // because the List does not contain null
expect(listOf("A")).toContain.inAnyOrder.only.entry(null)
}

fails { // because the List contains multiple elements
expect(listOf("A", "A")).toContain.inAnyOrder.only.entry {
toEqual("A")
}
}

fails { // because assertionCreatorOrNull is non-null and has no expectation
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.entry {
/* do nothing */
}
}
}

@Test
fun elementsOf() {
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.elementsOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class IterableLikeToContainInOrderOnlyCreatorSamples {
fun value() {
expect(listOf("A")).toContain.inOrder.only.value("A")

fails { // because subject list does not contain expected value
fails { // because the List does not contain expected value
expect(listOf("B")).toContain.inOrder.only.value("A")
}

fails { // because subject list contains multiple elements
fails { // because the List contains multiple elements
expect(listOf("A", "A")).toContain.inOrder.only.value("A")
}
}
Expand Down Expand Up @@ -49,6 +49,37 @@ class IterableLikeToContainInOrderOnlyCreatorSamples {
}
}

@Test
fun entry() {
expect(listOf("A")).toContain.inOrder.only.entry {
toEqual("A")
}

expect(listOf(null)).toContain.inOrder.only.entry(null)

fails { // because the List does not contain "A"
expect(listOf("B")).toContain.inOrder.only.entry {
toEqual("A")
}
}

fails { // because the List does not contain null
expect(listOf("A")).toContain.inOrder.only.entry(null)
}

fails { // because the List contains multiple elements
expect(listOf("A", "A")).toContain.inOrder.only.entry {
toEqual("A")
}
}

fails { // because assertionCreatorOrNull is non-null and has no expectation
expect(listOf("A", "B", "C")).toContain.inOrder.only.entry {
/* do nothing */
}
}
}

@Test
fun elementsOf() {
expect(listOf("A", "B", "C")).toContain.inOrder.only.elementsOf(
Expand Down

0 comments on commit fd0706e

Please sign in to comment.