-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix contain exactly verifier draft (#60)
- Loading branch information
1 parent
b612160
commit ccaa723
Showing
3 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ore/src/jvmTest/kotlin/io/kotest/matchers/collections/MatchCollectionsWithVerifierTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.kotest.matchers.collections | ||
|
||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.equals.Equality | ||
import io.kotest.equals.EqualityResult | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldStartWith | ||
|
||
class MatchCollectionsWithVerifierTest: StringSpec() { | ||
private val caseInsensitiveStringEquality: Equality<String> = object : Equality<String> { | ||
override fun name() = "Case Insensitive String Matcher" | ||
|
||
override fun verify(actual: String, expected: String): EqualityResult { | ||
return if (actual.uppercase() == expected.uppercase()) | ||
EqualityResult.equal(actual, expected, this) | ||
else | ||
EqualityResult.notEqual(actual, expected, this) | ||
} | ||
} | ||
|
||
init { | ||
"match" { | ||
matchCollectionsWithVerifier( | ||
listOf("Apple", "ORANGE", "apple"), | ||
listOf("Apple", "orange", "APPLE"), | ||
caseInsensitiveStringEquality | ||
) shouldBe null | ||
} | ||
"actual is too long" { | ||
matchCollectionsWithVerifier( | ||
listOf("Apple", "ORANGE", "apple"), | ||
listOf("Apple", "orange"), | ||
caseInsensitiveStringEquality | ||
) shouldBe CollectionMismatchWithCustomVerifier("Actual has an element at index 2, expected is shorter") | ||
} | ||
"expected is too long" { | ||
matchCollectionsWithVerifier( | ||
listOf("Apple", "ORANGE"), | ||
listOf("Apple", "orange", "apple"), | ||
caseInsensitiveStringEquality | ||
) shouldBe CollectionMismatchWithCustomVerifier("Expected has an element at index 2, actual is shorter") | ||
} | ||
"elements mismatch at index 2" { | ||
matchCollectionsWithVerifier( | ||
listOf("Apple", "ORANGE", "orange"), | ||
listOf("Apple", "orange", "apple"), | ||
caseInsensitiveStringEquality | ||
)!!.message shouldStartWith "Elements differ at index 2, expected: <\"apple\">, but was <\"orange\">, \"apple\" is not equal to \"orange\" by Case Insensitive String Matcher" | ||
} | ||
} | ||
} |