Add containsAll(Any?) check to CollectionBehaviors

This commit is contained in:
Abduqodiri Qurbonzoda
2019-02-20 02:46:45 +03:00
committed by Ilya Gorbunov
parent 1b6b44c805
commit 60e83383ad
2 changed files with 8 additions and 1 deletions
@@ -19,7 +19,7 @@ public fun <T> CompareContext<List<T>>.listBehavior() {
for (index in expected.indices)
propertyEquals { this[index] }
propertyFails { this[size] }
propertyFailsWith<IndexOutOfBoundsException> { this[size] }
propertyEquals { indexOf(elementAtOrNull(0)) }
propertyEquals { lastIndexOf(elementAtOrNull(0)) }
@@ -103,6 +103,8 @@ public fun <T> CompareContext<Collection<T>>.collectionBehavior(objectName: Stri
(object {}).let { propertyEquals { contains(it as Any?) } }
propertyEquals { contains(firstOrNull()) }
propertyEquals { containsAll(this) }
(object {}).let { propertyEquals { containsAll(listOf<Any?>(it)) } }
propertyEquals { containsAll(listOf<Any?>(null)) }
}
@@ -31,6 +31,11 @@ public class CompareContext<out T>(public val expected: T, public val actual: T)
assertFailEquals({ expected.getter() }, { actual.getter() })
}
public inline fun <reified E : Throwable> propertyFailsWith(crossinline getter: T.() -> Unit) {
assertFailsWith<E> { expected.getter() }
assertFailsWith<E> { actual.getter() }
}
public fun <P> compareProperty(getter: T.() -> P, block: CompareContext<P>.() -> Unit) {
compare(expected.getter(), actual.getter(), block)
}