Skip to content

Commit

Permalink
Merge pull request #1575 from danherrera/add-map-tocontain-entries-in…
Browse files Browse the repository at this point in the history
…fix-samples

add Map.toContain...entries infix samples
  • Loading branch information
robstoll authored Oct 16, 2023
2 parents 33a62fa + 1f6e201 commit 4180560
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ infix fun <K, V, T : MapLike> EntryPointStep<K, V, T, InAnyOrderSearchBehaviour>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapLikeToContainInAnyOrderCreatorSamples.entries
*
* @since 0.15.0
*/
infix fun <K, V, T : MapLike> EntryPointStep<K, V, T, InAnyOrderSearchBehaviour>.the(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ infix fun <K, V, T : MapLike> EntryPointStep<K, V, T, InAnyOrderOnlySearchBehavi
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapLikeToContainInAnyOrderOnlyCreatorSamples.entries
*
* @since 0.15.0
*/
infix fun <K, V, T : MapLike> EntryPointStep<K, V, T, InAnyOrderOnlySearchBehaviour>.the(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ infix fun <K, V, T : MapLike> EntryPointStep<K, V, T, InOrderOnlySearchBehaviour
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapLikeToContainInOrderOnlyCreatorSamples.entries
*
* @since 0.15.0
*/
infix fun <K, V, T : MapLike> EntryPointStep<K, V, T, InOrderOnlySearchBehaviour>.the(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ class MapLikeToContainInAnyOrderCreatorSamples {
}
}

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

@Test
fun entriesKeyValue() {
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order the entries(keyValue(2) { this toEqual "b" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class MapLikeToContainInAnyOrderOnlyCreatorSamples {
}
}

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

@Test
fun entryKeyValue() {
expect(mapOf(1 to "apple")) toContain o inAny order but only entry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ class MapLikeToContainInOrderOnlyCreatorSamples {
}
}

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

@Test
fun entriesKeyValue() {
expect(mapOf(1 to "a", 2 to "b")) toContain o inGiven order and only the entries(
Expand Down

0 comments on commit 4180560

Please sign in to comment.