From ee3b487016336070d5dfa14ad0254c507843b21e Mon Sep 17 00:00:00 2001 From: Matthias Geisler Date: Sun, 27 Feb 2022 14:54:06 +0100 Subject: [PATCH] Wire Contraints into ArgumentMatchers --- kmock/build.gradle.kts | 7 + .../tech/antibytes/kmock/KMockContract.kt | 2 +- .../kmock/verification/ArgumentMatcher.kt | 76 +++- .../kmock/verification/contraints/any.kt | 6 +- .../kmock/verification/contraints/eq.kt | 23 +- .../kmock/verification/contraints/isNot.kt | 3 +- .../verification/contraints/isNotSame.kt | 2 +- .../kmock/verification/contraints/isSame.kt | 2 +- .../kmock/verification/ArgumentMatcherSpec.kt | 167 ++++++--- .../VerificationHandleFactorySpec.kt | 8 +- .../kmock/verification/contraints/AnySpec.kt | 4 +- .../verification/contraints/EqualSpec.kt | 349 +++++++++++++++++- 12 files changed, 574 insertions(+), 75 deletions(-) diff --git a/kmock/build.gradle.kts b/kmock/build.gradle.kts index 242a34e2..4deb4c35 100644 --- a/kmock/build.gradle.kts +++ b/kmock/build.gradle.kts @@ -53,6 +53,13 @@ kotlin { ).contains(sourceSet.name) } + all { + languageSettings.apply { + optIn("kotlin.ExperimentalUnsignedTypes") + optIn("kotlin.RequiresOptIn") + } + } + val commonMain by getting { dependencies { implementation(Dependency.multiplatform.kotlin.common) diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt index ba62ebdb..d5b248bf 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt @@ -317,7 +317,7 @@ interface KMockContract { } fun interface MatcherConstraint { - fun matches(value: Any?): Boolean + fun matches(actual: Any?): Boolean } data class Reference( diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ArgumentMatcher.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ArgumentMatcher.kt index 624b3f35..70032a09 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ArgumentMatcher.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ArgumentMatcher.kt @@ -6,27 +6,92 @@ package tech.antibytes.kmock.verification +import tech.antibytes.kmock.KMockContract import tech.antibytes.kmock.KMockContract.GetOrSet +import tech.antibytes.kmock.verification.contraints.eq internal fun Array?.hasBeenCalledWithVoid(): Boolean = this == null +private fun wrapValue(value: Any?): KMockContract.MatcherConstraint { + return if (value is KMockContract.MatcherConstraint) { + value + } else { + eq(value) + } +} + internal fun Array?.hasBeenCalledWith(vararg values: Any?): Boolean { return when { this == null -> values.isEmpty() values.isEmpty() -> true - else -> values.all { value -> this.contains(value) } + else -> { + var lastMatch = 0 + + for (value in values) { + var matched = false + val expected = wrapValue(value) + + for (idx in lastMatch until this.size) { + val actual = this[idx] + + if (expected.matches(actual)) { + matched = true + lastMatch = idx + break + } + } + + if (!matched) { + return false + } + } + + return true + } } } internal fun Array?.hasBeenStrictlyCalledWith(vararg values: Any?): Boolean { - return this?.contentDeepEquals(values) ?: values.isEmpty() + return when { + this == null && values.isEmpty() -> true + this == null -> false + values.size != this.size -> false + else -> { + + for (idx in values.indices) { + val expected = wrapValue(values[idx]) + + if (!expected.matches(this[idx])) { + return false + } + } + + return true + } + } } internal fun Array?.hasBeenCalledWithout(vararg values: Any?): Boolean { return if (this == null) { values.isNotEmpty() } else { - values.none { value -> this.contains(value) } + for (value in values) { + var matched = false + val expected = wrapValue(value) + + for (actual in this) { + if (expected.matches(actual)) { + matched = true + break + } + } + + if (matched) { + return false + } + } + + return true } } @@ -37,6 +102,9 @@ internal fun GetOrSet.wasSet(): Boolean = this is GetOrSet.Set internal fun GetOrSet.wasSetTo(value: Any?): Boolean { return when (this) { !is GetOrSet.Set -> false - else -> this.value == value + else -> { + val expected = wrapValue(value) + return expected.matches(this.value) + } } } diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/any.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/any.kt index e0810262..32b07c58 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/any.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/any.kt @@ -14,11 +14,11 @@ import kotlin.reflect.KClass class any( private val expected: KClass<*>? = null ) : KMockContract.MatcherConstraint { - override fun matches(value: Any?): Boolean { + override fun matches(actual: Any?): Boolean { return when { expected == null -> true - value == null -> false - else -> value::class == expected + actual == null -> false + else -> actual::class == expected } } } diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/eq.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/eq.kt index c6245a87..ccc2f524 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/eq.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/eq.kt @@ -9,10 +9,29 @@ package tech.antibytes.kmock.verification.contraints import tech.antibytes.kmock.KMockContract -import kotlin.reflect.KClass +@OptIn(ExperimentalUnsignedTypes::class) class eq( private val expected: Any? ) : KMockContract.MatcherConstraint { - override fun matches(value: Any?): Boolean = expected == value + override fun matches(actual: Any?): Boolean { + return when { + expected is Array<*> && actual is Array<*> -> expected.contentDeepEquals(actual) + expected is ByteArray && actual is ByteArray -> expected.contentEquals(actual) + expected is ShortArray && actual is ShortArray -> expected.contentEquals(actual) + expected is IntArray && actual is IntArray -> expected.contentEquals(actual) + expected is LongArray && actual is LongArray -> expected.contentEquals(actual) + expected is FloatArray && actual is FloatArray -> expected.contentEquals(actual) + expected is DoubleArray && actual is DoubleArray -> expected.contentEquals(actual) + expected is CharArray && actual is CharArray -> expected.contentEquals(actual) + expected is BooleanArray && actual is BooleanArray -> expected.contentEquals(actual) + + expected is UByteArray && actual is UByteArray -> expected.contentEquals(actual) + expected is UShortArray && actual is UShortArray -> expected.contentEquals(actual) + expected is UIntArray && actual is UIntArray -> expected.contentEquals(actual) + expected is ULongArray && actual is ULongArray -> expected.contentEquals(actual) + + else -> expected == actual + } + } } diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNot.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNot.kt index 181e93e8..8886672c 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNot.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNot.kt @@ -9,10 +9,9 @@ package tech.antibytes.kmock.verification.contraints import tech.antibytes.kmock.KMockContract -import kotlin.reflect.KClass class isNot( private val illegal: Any? = null ) : KMockContract.MatcherConstraint { - override fun matches(value: Any?): Boolean = illegal != value + override fun matches(actual: Any?): Boolean = illegal != actual } diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNotSame.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNotSame.kt index 3eca053a..9a5a4310 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNotSame.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isNotSame.kt @@ -13,5 +13,5 @@ import tech.antibytes.kmock.KMockContract class isNotSame( private val illegal: Any? ) : KMockContract.MatcherConstraint { - override fun matches(value: Any?): Boolean = illegal !== value + override fun matches(actual: Any?): Boolean = illegal !== actual } diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isSame.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isSame.kt index 97e5bde8..dce25b72 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isSame.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/contraints/isSame.kt @@ -13,5 +13,5 @@ import tech.antibytes.kmock.KMockContract class isSame( private val expected: Any? ) : KMockContract.MatcherConstraint { - override fun matches(value: Any?): Boolean = expected === value + override fun matches(actual: Any?): Boolean = expected === actual } diff --git a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ArgumentMatcherSpec.kt b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ArgumentMatcherSpec.kt index 3d5394ee..c70b9ff0 100644 --- a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ArgumentMatcherSpec.kt +++ b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ArgumentMatcherSpec.kt @@ -7,6 +7,10 @@ package tech.antibytes.kmock.verification import tech.antibytes.kmock.KMockContract +import tech.antibytes.kmock.verification.contraints.eq +import tech.antibytes.kmock.verification.contraints.isNot +import tech.antibytes.kmock.verification.contraints.isNotSame +import tech.antibytes.kmock.verification.contraints.isSame import tech.antibytes.util.test.fixture.fixture import tech.antibytes.util.test.fixture.kotlinFixture import tech.antibytes.util.test.fixture.listFixture @@ -43,6 +47,19 @@ class ArgumentMatcherSpec { actual mustBe false } + @Test + @JsName("fn2") + fun `Given hasBeenCalledWith is called with an Argument it returns true if the Array is null and the Arguments are empty`() { + // Given + val array = null + + // When + val actual = array.hasBeenCalledWith() + + // Then + actual mustBe true + } + @Test @JsName("fn3") fun `Given hasBeenCalledWith is called with an Argument it returns false if the Array contains not the given Argument`() { @@ -60,10 +77,10 @@ class ArgumentMatcherSpec { @JsName("fn4") fun `Given hasBeenCalledWith is called with an Argument it returns true if the Array contains the given Argument`() { // Given - val array = fixture.listFixture().toTypedArray() + val array = fixture.listFixture(size = 5).toTypedArray() // When - val actual = array.hasBeenCalledWith(array.first()) + val actual = array.hasBeenCalledWith(array.first(), array[2]) // Then actual mustBe true @@ -71,6 +88,19 @@ class ArgumentMatcherSpec { @Test @JsName("fn5") + fun `Given hasBeenCalledWith is called with an Argument it returns true if the Array contains the given Argument while respecting the order`() { + // Given + val array = fixture.listFixture(size = 5).toTypedArray() + + // When + val actual = array.hasBeenCalledWith(array[2], array.first()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn6") fun `Given hasBeenCalledWith is called without Arguments void it returns true if the Array contains Arguments`() { // Given val array = fixture.listFixture().toTypedArray() @@ -83,7 +113,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn6") + @JsName("fn7") fun `Given hasBeenCalledWith is called without Arguments void it returns true if the Array is null`() { // Given val array = null @@ -96,7 +126,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn7") + @JsName("fn8") fun `Given hasBeenCalledWith is called with Arguments it returns false if the Array is null`() { // Given val array = null @@ -109,7 +139,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn8") + @JsName("fn9") fun `Given hasBeenCalledWith is called with Arguments it returns false if the Array contains not all of given Arguments`() { // Given val array = fixture.listFixture(size = 8).toTypedArray() @@ -122,39 +152,28 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn9") + @JsName("fn10") fun `Given hasBeenCalledWith is called with Arguments it returns true if the Array contains all of given Arguments`() { // Given val array = fixture.listFixture(size = 8).toTypedArray() // When - val actual = array.hasBeenCalledWith(array[0], array[1], array[2], array[3]) + val actual = array.hasBeenCalledWith(*array) // Then actual mustBe true } - @Test - @JsName("fn10") - fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns false if the Array matches not the given Argument`() { - // Given - val array = fixture.listFixture().toTypedArray() - - // When - val actual = array.hasBeenStrictlyCalledWith(fixture.fixture()) - - // Then - actual mustBe false - } - @Test @JsName("fn11") - fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns true if the Array matches the given Argument`() { + fun `Given hasBeenCalledWith is called with Arguments it returns true while using Constraints`() { // Given - val array = fixture.listFixture(size = 1).toTypedArray() + val array = fixture.listFixture(size = 8).toTypedArray() // When - val actual = array.hasBeenStrictlyCalledWith(array.first()) + val actual = array.hasBeenCalledWith( + *(array.map { value -> isSame(value) }.toTypedArray()) + ) // Then actual mustBe true @@ -162,25 +181,25 @@ class ArgumentMatcherSpec { @Test @JsName("fn12") - fun `Given hasBeenStrictlyCalledWith is called without Arguments void it returns false if the Array has Arguments`() { + fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns true if the Array is null and no values were given`() { // Given - val array = fixture.listFixture(size = 1).toTypedArray() + val array = null // When val actual = array.hasBeenStrictlyCalledWith() // Then - actual mustBe false + actual mustBe true } @Test @JsName("fn13") - fun `Given hasBeenStrictlyCalledWith is called witg Arguments void it returns false if the Array is null`() { + fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns false if the Array is null and values were given`() { // Given val array = null // When - val actual = array.hasBeenStrictlyCalledWith(fixture.fixture()) + val actual = array.hasBeenStrictlyCalledWith(fixture.fixture()) // Then actual mustBe false @@ -188,25 +207,25 @@ class ArgumentMatcherSpec { @Test @JsName("fn14") - fun `Given hasBeenStrictlyCalledWith is called without Arguments void it returns false if the Array is null`() { + fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns false if the Array and Value size does not match`() { // Given - val array = null + val array = fixture.listFixture(size = 5).toTypedArray() // When - val actual = array.hasBeenStrictlyCalledWith() + val actual = array.hasBeenStrictlyCalledWith(fixture.fixture()) // Then - actual mustBe true + actual mustBe false } @Test @JsName("fn15") - fun `Given hasBeenStrictlyCalledWith is called with Arguments it returns false if the Array matches not exactly the given Arguments`() { + fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns false if the Array and Value do not match`() { // Given - val array = fixture.listFixture(size = 8).toTypedArray() + val array = fixture.listFixture(size = 5).toTypedArray() // When - val actual = array.hasBeenStrictlyCalledWith(array[0], array[1], array[2], array[3]) + val actual = array.hasBeenStrictlyCalledWith(fixture.listFixture(size = 5).toTypedArray()) // Then actual mustBe false @@ -214,19 +233,34 @@ class ArgumentMatcherSpec { @Test @JsName("fn16") - fun `Given hasBeenStrictlyCalledWith is called with Arguments it returns true if the Array matches exactly the given Arguments`() { + fun `Given hasBeenStrictlyCalledWith is called with an Argument it returns true if the Array and Value do match`() { // Given - val array = fixture.listFixture(size = 8).toTypedArray() + val array = fixture.listFixture(size = 5) // When - val actual = array.hasBeenStrictlyCalledWith(*array) + val actual = array.toTypedArray().hasBeenStrictlyCalledWith(array.toTypedArray()) // Then - actual mustBe true + actual mustBe false } @Test @JsName("fn17") + fun `Given hasBeenStrictlyCalledWith is called with Arguments it returns true while using Constraints`() { + // Given + val array = fixture.listFixture(size = 5).toTypedArray() + + // When + val actual = array.hasBeenStrictlyCalledWith( + *(array.map { value -> isNotSame(value) }.toTypedArray()) + ) + + // Then + actual mustBe false + } + + @Test + @JsName("fn18") fun `Given hasBeenCalledWithout is called with an Argument it returns false if the Array contains no Argument`() { // Given val array = null @@ -239,7 +273,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn18") + @JsName("fn19") fun `Given hasBeenCalledWithout is called with an Argument it returns true if the Array contains Arguments`() { // Given val array = null @@ -252,7 +286,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn19") + @JsName("fn20") fun `Given hasBeenCalledWithout is called with an Argument it returns true if the Array contains not the given Argument`() { // Given val array = fixture.listFixture().toTypedArray() @@ -265,7 +299,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn20") + @JsName("fn21") fun `Given hasBeenCalledWithout is called with an Argument it returns false if the Array contains the given Argument`() { // Given val array = fixture.listFixture().toTypedArray() @@ -278,7 +312,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn21") + @JsName("fn22") fun `Given hasBeenCalledWithout is called without Argument it returns true if the Array contains Argument`() { // Given val array = fixture.listFixture().toTypedArray() @@ -291,7 +325,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn22") + @JsName("fn23") fun `Given hasBeenCalledWithout is called with Arguments it returns false if the Array is null`() { // Given val array = fixture.listFixture().toTypedArray() @@ -304,7 +338,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn23") + @JsName("fn24") fun `Given hasBeenCalledWithout is called with Arguments it returns true if the Array none of given Arguments matches`() { // Given val array = fixture.listFixture(size = 8).toTypedArray() @@ -318,7 +352,7 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn24") + @JsName("fn25") fun `Given hasBeenCalledWithout is called with Arguments it returns false if the Array matches at least one of given Arguments`() { // Given val array = fixture.listFixture(size = 8).toTypedArray() @@ -336,45 +370,70 @@ class ArgumentMatcherSpec { } @Test - @JsName("fn25") + @JsName("fn26") + fun `Given hasBeenCalledWithout is called with Arguments it returns false while using Constraints`() { + // Given + val array = fixture.listFixture(size = 8).toTypedArray() + + // When + val actual = array.hasBeenCalledWithout( + isNot(fixture.fixture()), + isNot(fixture.fixture()), + isNot(fixture.fixture()), + eq(array[0]), + ) + + // Then + actual mustBe false + } + + @Test + @JsName("fn27") fun `Given wasGotten is called it returns false if it is attacht to Set`() { KMockContract.GetOrSet.Set(null).wasGotten() mustBe false } @Test - @JsName("fn26") + @JsName("fn28") fun `Given wasGotten is called it returns true if it is attacht to Get`() { KMockContract.GetOrSet.Get.wasGotten() mustBe true } @Test - @JsName("fn27") + @JsName("fn29") fun `Given wasSet is called it returns false if it is attacht to Get`() { KMockContract.GetOrSet.Get.wasSet() mustBe false } @Test - @JsName("fn28") + @JsName("fn30") fun `Given wasGotten is called it returns true if it is attacht to Set`() { KMockContract.GetOrSet.Set(null).wasSet() mustBe true } @Test - @JsName("fn29") + @JsName("fn31") fun `Given wasSetTo is called it returns false if it is attacht to Get`() { KMockContract.GetOrSet.Get.wasSetTo(null) mustBe false } @Test - @JsName("fn30") + @JsName("fn32") fun `Given wasSetTo is called it returns false if the values do not match`() { KMockContract.GetOrSet.Set(fixture.fixture()).wasSetTo(fixture.fixture()) mustBe false } @Test - @JsName("fn31") - fun `Given wasSetTo is called it returns true if the values do math`() { + @JsName("fn33") + fun `Given wasSetTo is called it returns true if the values do match`() { val value: Any = fixture.fixture() KMockContract.GetOrSet.Set(value).wasSetTo(value) mustBe true } + + @Test + @JsName("fn34") + fun `Given wasSetTo is called it returns false if the values do match while using Constraints`() { + val value: Any = fixture.fixture() + KMockContract.GetOrSet.Set(value).wasSetTo(isNotSame(value)) mustBe false + } } diff --git a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/VerificationHandleFactorySpec.kt b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/VerificationHandleFactorySpec.kt index 1b6ef19c..78e115ce 100644 --- a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/VerificationHandleFactorySpec.kt +++ b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/VerificationHandleFactorySpec.kt @@ -99,7 +99,7 @@ class VerificationHandleFactorySpec { // Given val name: String = fixture.fixture() val mock = FunMockeryStub(name, 1) - val values = fixture.listFixture().toTypedArray() + val values = fixture.listFixture().toTypedArray().sortedArray() var capturedIndex: Int? = null mock.getArgumentsForCall = { givenIndex -> @@ -109,7 +109,7 @@ class VerificationHandleFactorySpec { } // When - val actual = mock.hasBeenCalledWith(*(values.sorted()).toTypedArray()) + val actual = mock.hasBeenCalledWith(*values) // Then actual mustBe VerificationHandle(name, listOf(0)) @@ -122,7 +122,7 @@ class VerificationHandleFactorySpec { // Given val name: String = fixture.fixture() val captured: MutableList = mutableListOf() - val values = fixture.listFixture().toTypedArray() + val values = fixture.listFixture().toTypedArray().sortedArray() val builder = VerificationChainBuilderStub(captured) val mock = FunMockeryStub(name, 1, verificationBuilderReference = builder) @@ -135,7 +135,7 @@ class VerificationHandleFactorySpec { } // When - mock.hasBeenCalledWith(*(values.sorted()).toTypedArray()) + mock.hasBeenCalledWith(*values) val actual = captured.first() // Then diff --git a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/AnySpec.kt b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/AnySpec.kt index 89caf3b9..cd46a1bb 100644 --- a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/AnySpec.kt +++ b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/AnySpec.kt @@ -47,7 +47,7 @@ class AnySpec { } @Test - @JsName("fn2") + @JsName("fn3") fun `Given any is called it returns false if the given KClass and the call was null`() { // When val actual = any(Any::class).matches(null) @@ -57,7 +57,7 @@ class AnySpec { } @Test - @JsName("fn3") + @JsName("fn4") fun `Given any is called it returns true if the given KClass and the call KClass are matching`() { // Given val value = true diff --git a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/EqualSpec.kt b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/EqualSpec.kt index 7bd24b28..817cd741 100644 --- a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/EqualSpec.kt +++ b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/contraints/EqualSpec.kt @@ -9,6 +9,7 @@ package tech.antibytes.kmock.verification.contraints import tech.antibytes.kmock.KMockContract import tech.antibytes.util.test.fixture.fixture import tech.antibytes.util.test.fixture.kotlinFixture +import tech.antibytes.util.test.fixture.listFixture import tech.antibytes.util.test.fulfils import tech.antibytes.util.test.mustBe import kotlin.js.JsName @@ -38,7 +39,7 @@ class EqualSpec { @Test @JsName("fn2") - fun `Given eq is called it returns true if the given Value and the call Value are the same`() { + fun `Given eq is called it returns true if the given Value and the call Value are matching`() { // Given val value: Int = fixture.fixture() @@ -48,4 +49,350 @@ class EqualSpec { // Then actual mustBe true } + + @Test + @JsName("fn3") + fun `Given eq is called it returns false if the given Value is an Array and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn4") + fun `Given eq is called it returns true if the given Value is an Array and the call Value are matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray()).matches(value.toTypedArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn5") + fun `Given eq is called it returns false if the given Value is an ByteArray and the call Value are not matching`() { + // Given + val value = fixture.fixture().encodeToByteArray() + + // When + val actual = eq(value).matches(fixture.fixture().encodeToByteArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn6") + fun `Given eq is called it returns true if the given Value is an ByteArray and the call Value are not matching`() { + // Given + val value = fixture.fixture() + + // When + val actual = eq(value.encodeToByteArray()).matches(value.encodeToByteArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn7") + fun `Given eq is called it returns false if the given Value is an ShortArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toShortArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toShortArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn8") + fun `Given eq is called it returns true if the given Value is an ShortArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toShortArray()).matches(value.toTypedArray().toShortArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn9") + fun `Given eq is called it returns false if the given Value is an IntArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toIntArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toIntArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn10") + fun `Given eq is called it returns true if the given Value is an IntArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toIntArray()).matches(value.toTypedArray().toIntArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn11") + fun `Given eq is called it returns false if the given Value is an LongArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toLongArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toLongArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn12") + fun `Given eq is called it returns true if the given Value is an LongArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toLongArray()).matches(value.toTypedArray().toLongArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn13") + fun `Given eq is called it returns false if the given Value is an FloatArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toFloatArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toFloatArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn14") + fun `Given eq is called it returns true if the given Value is an FloatArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toFloatArray()).matches(value.toTypedArray().toFloatArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn15") + fun `Given eq is called it returns false if the given Value is an DoubleArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toDoubleArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toDoubleArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn16") + fun `Given eq is called it returns true if the given Value is an DoubleArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toDoubleArray()).matches(value.toTypedArray().toDoubleArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn17") + fun `Given eq is called it returns false if the given Value is an CharArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toCharArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toCharArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn18") + fun `Given eq is called it returns true if the given Value is an CharArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toCharArray()).matches(value.toTypedArray().toCharArray()) + + // Then + actual mustBe true + } + + @Test + @JsName("fn19") + fun `Given eq is called it returns false if the given Value is an BooleanArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toBooleanArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toBooleanArray()) + + // Then + actual mustBe false + } + + @Test + @JsName("fn20") + fun `Given eq is called it returns true if the given Value is an BooleanArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toBooleanArray()).matches(value.toTypedArray().toBooleanArray()) + + // Then + actual mustBe true + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn21") + fun `Given eq is called it returns false if the given Value is an UByteArray and the call Value are not matching`() { + // Given + val value = fixture.fixture() + + // When + val actual = eq(value).matches(fixture.fixture()) + + // Then + actual mustBe false + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn22") + fun `Given eq is called it returns true if the given Value is an UByteArray and the call Value are not matching`() { + // Given + val value = fixture.fixture() + + // When + val actual = eq(value).matches(value) + + // Then + actual mustBe true + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn23") + fun `Given eq is called it returns false if the given Value is an UShortArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toUShortArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toUShortArray()) + + // Then + actual mustBe false + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn24") + fun `Given eq is called it returns true if the given Value is an UShortArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toUShortArray()).matches(value.toTypedArray().toUShortArray()) + + // Then + actual mustBe true + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn25") + fun `Given eq is called it returns false if the given Value is an UIntArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toUIntArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toUIntArray()) + + // Then + actual mustBe false + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn26") + fun `Given eq is called it returns true if the given Value is an UIntArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toUIntArray()).matches(value.toTypedArray().toUIntArray()) + + // Then + actual mustBe true + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn27") + fun `Given eq is called it returns false if the given Value is an ULongArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture().toTypedArray().toULongArray() + + // When + val actual = eq(value).matches(fixture.listFixture().toTypedArray().toULongArray()) + + // Then + actual mustBe false + } + + @OptIn(ExperimentalUnsignedTypes::class) + @Test + @JsName("fn28") + fun `Given eq is called it returns true if the given Value is an ULongArray and the call Value are not matching`() { + // Given + val value = fixture.listFixture() + + // When + val actual = eq(value.toTypedArray().toULongArray()).matches(value.toTypedArray().toULongArray()) + + // Then + actual mustBe true + } }