X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FOneByOneMatcher.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FOneByOneMatcher.kt;h=f0ccecaa79d621cc9720187d2a9cbbc151db92bc;hp=0000000000000000000000000000000000000000;hb=eb32457356fac09e16ec98394c1b5d48f9dfba84;hpb=ec655d61682a70063c1cf540fe3e41613aaf71a5
diff --git a/src/test/kotlin/net/pterodactylus/sone/test/OneByOneMatcher.kt b/src/test/kotlin/net/pterodactylus/sone/test/OneByOneMatcher.kt
new file mode 100644
index 0000000..f0cceca
--- /dev/null
+++ b/src/test/kotlin/net/pterodactylus/sone/test/OneByOneMatcher.kt
@@ -0,0 +1,33 @@
+package net.pterodactylus.sone.test
+
+import org.hamcrest.Description
+import org.hamcrest.TypeSafeDiagnosingMatcher
+
+class OneByOneMatcher : TypeSafeDiagnosingMatcher() {
+ private data class Matcher(val expected: V, val actual: (A) -> V, val description: String)
+
+ private val matchers = mutableListOf>()
+
+ fun expect(description: String, expected: V, actual: (A) -> V) {
+ matchers += Matcher(expected, actual, description)
+ }
+
+ override fun describeTo(description: Description) {
+ matchers.forEachIndexed { index, matcher ->
+ if (index > 0) {
+ description.appendText(", ")
+ }
+ description.appendText("${matcher.description} is ").appendValue(matcher.expected)
+ }
+ }
+
+ override fun matchesSafely(item: A, mismatchDescription: Description) =
+ matchers.all {
+ if (it.expected != it.actual(item)) {
+ mismatchDescription.appendText("${it.description} is ").appendValue(it.actual(item))
+ false
+ } else {
+ true
+ }
+ }
+}