diff --git a/AUTHORS.md b/AUTHORS.md index fca96d21..abe84f80 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -27,3 +27,4 @@ 1. Vitus Ortner - [@vitusortner](https://github.com/vitusortner) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=vitusortner)) 1. Caleb Brinkman - [@floralvikings](https://github.com/floralvikings) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=floralvikings)) 1. Jonathan Cornaz - [@jcornaz](https://github.com/jcornaz) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=jcornaz)) +1. Ivan Atanasov - [@IvanAtanasov89](https://github.com/IvanAtanasov89) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=IvanAtanasov89)) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt index aa3dce2b..21885921 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt @@ -247,3 +247,17 @@ infix fun Any?.`should be in`(iterable: Iterable) = this.shouldBeIn(itera infix fun Any?.`should not be in`(iterable: Iterable) = this.shouldNotBeIn(iterable) infix fun Any?.`should be in`(array: Array) = this.shouldBeIn(array) + +infix fun Array.`should contain same`(expected: Array) = this.shouldContainSame(expected) + +infix fun Iterable.`should contain same`(expected: Iterable) = this.shouldContainSame(expected) + +infix fun ShortArray.`should contain same`(expected: ShortArray) = this.shouldContainSame(expected) + +infix fun FloatArray.`should contain same`(expected: FloatArray) = this.shouldContainSame(expected) + +infix fun DoubleArray.`should contain same`(expected: DoubleArray) = this.shouldContainSame(expected) + +infix fun LongArray.`should contain same`(expected: LongArray) = this.shouldContainSame(expected) + +infix fun CharArray.`should contain same`(expected: CharArray) = this.shouldContainSame(expected) diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldContainSameTests.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldContainSameTests.kt new file mode 100644 index 00000000..8f283857 --- /dev/null +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldContainSameTests.kt @@ -0,0 +1,34 @@ +package org.amshove.kluent.tests.backtickassertions + +import org.amshove.kluent.`should contain same` +import org.jetbrains.spek.api.Spek +import kotlin.test.assertFails + +class ShouldContainSameTests : Spek({ + given("the shouldContainSame method") { + on("testing a list which contains all the same elements") { + it("should pass") { + val cities = listOf("Israel", "Berlin", "Phoenix") + val actual = listOf("Israel", "Phoenix", "Berlin") + + actual `should contain same` cities + } + } + on("testing a short array which contains all the same elements") { + it("should pass") { + val numbers = shortArrayOf(1, 2, 3) + val actual = shortArrayOf(1, 3, 2) + + actual `should contain same` numbers + } + } + on("testing a list which contains only 2 of the 3 elements") { + it("should pass") { + val cities = listOf("Israel", "Berlin", "Phoenix") + val actual = listOf("Israel", "Berlin", "Liverpool") + + assertFails { actual `should contain same` cities } + } + } + } +}) diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldThrowTests.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldThrowTests.kt index b6d8e10b..a6d6b8b8 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldThrowTests.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/backtickassertions/ShouldThrowTests.kt @@ -17,13 +17,13 @@ class ShouldThrowTests : Spek({ on("expection another exception") { it("should fail") { val func = { throw IndexOutOfBoundsException() } - assertFails({ func `should throw` IllegalArgumentException::class }) + assertFails { func `should throw` IllegalArgumentException::class } } } on("trying to get an out of indexed item in an empty list") { - val funcWithReturn = { ArrayList().get(-1) } + val funcWithReturn = { ArrayList()[-1] } it("should pass a failing test") { - funcWithReturn `should throw` ArrayIndexOutOfBoundsException::class + funcWithReturn `should throw` java.lang.IndexOutOfBoundsException::class } } on("throwing subtype of an exception") { @@ -41,7 +41,7 @@ class ShouldThrowTests : Spek({ on("throwing an exception with a wrong message") { it("should fail") { val func = { throw Exception("Hello World!") } - assertFails({ func `should throw` Exception::class `with message` "Hello" }) + assertFails { func `should throw` Exception::class `with message` "Hello" } } } on("throwing an exception with a cause") { @@ -53,13 +53,13 @@ class ShouldThrowTests : Spek({ on("throwing an exception with a wrong cause") { it("should fail") { val func = { throw Exception(RuntimeException()) } - assertFails({ func `should throw` Exception::class `with cause` IOException::class }) + assertFails { func `should throw` Exception::class `with cause` IOException::class } } } on("throwing another exception") { it("should fail") { val func = { throw IllegalArgumentException() } - assertFails({ func `should throw` IndexOutOfBoundsException::class }) + assertFails { func `should throw` IndexOutOfBoundsException::class } } } on("expecting any exception when any exception is thrown") { @@ -71,7 +71,7 @@ class ShouldThrowTests : Spek({ on("expecting any exception when no exception is thrown") { it("should fail") { val func = { Unit } - assertFails({ func `should throw` AnyException }) + assertFails { func `should throw` AnyException } } } on("being fluent asserting both a cause and a message") {