Skip to content

Commit

Permalink
Merge pull request #129 from IvanAtanasov89/master
Browse files Browse the repository at this point in the history
Added backtick functions for shouldContainSame
  • Loading branch information
MarkusAmshove authored Jan 10, 2019
2 parents 2ced344 + 5f4eb5d commit 0688ab3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
14 changes: 14 additions & 0 deletions jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,17 @@ infix fun <T> Any?.`should be in`(iterable: Iterable<T>) = this.shouldBeIn(itera
infix fun <T> Any?.`should not be in`(iterable: Iterable<T>) = this.shouldNotBeIn(iterable)

infix fun <T> Any?.`should be in`(array: Array<T>) = this.shouldBeIn(array)

infix fun <T> Array<T>.`should contain same`(expected: Array<T>) = this.shouldContainSame(expected)

infix fun <T> Iterable<T>.`should contain same`(expected: Iterable<T>) = 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)
Original file line number Diff line number Diff line change
@@ -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 }
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>().get(-1) }
val funcWithReturn = { ArrayList<String>()[-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") {
Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -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") {
Expand Down

0 comments on commit 0688ab3

Please sign in to comment.