Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Merge branch 'master' into range-assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
javatarz committed Jan 15, 2020
2 parents 4494fbd + 9223ce7 commit 0c66fbc
Show file tree
Hide file tree
Showing 41 changed files with 1,063 additions and 189 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
1. Jógvan Olsen - [@jeggy](https://github.com/jeggy) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=jeggy))
1. Yang C - [@ychescale9](https://github.com/ychescale9) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=ychescale9))
1. Christian Ivicevic - [@ChristianIvicevic](https://github.com/ChristianIvicevic) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=ChristianIvicevic))
1. Ivan Mikhnovich - [@Murtaught](https://github.com/Murtaught) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=Murtaught))
1. Jc Miñarro - [@JcMinarro](https://github.com/JcMinarro) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=JcMinarro))
1. Kshitij Patil [@Kshitij09](https://github.com/Kshitij09) ([Contributions](https://github.com/MarkusAmshove/Kluent/commits?author=Kshitij09))
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 1.59
* Rename some assertions to keep consistent naming strategy | [Issue](https://github.com/MarkusAmshove/Kluent/issues/96) | [PR](https://github.com/MarkusAmshove/Kluent/pull/172/) | thanks to [@JcMinarro](https://github.com/JcMinarro)
* Support assertion for sorted collections | [Issue](https://github.com/MarkusAmshove/Kluent/issues/167) | [PR](https://github.com/MarkusAmshove/Kluent/pull/173/) | thanks to [@JcMinarro](https://github.com/JcMinarro)
# 1.58
* Fix implementation of `Map.shouldContainSame` to compare all pairs |[Issue](https://github.com/MarkusAmshove/Kluent/issues/170) | [PR](https://github.com/MarkusAmshove/Kluent/pull/171) | thanks to [@Murtaught](https://github.com/Murtaught)

# 1.57
* Add assertions for sequences | [PR](https://github.com/MarkusAmshove/Kluent/pull/159) | thanks to [@jcornaz](https://github.com/jcornaz)
* Add `shouldHaveSingleItem` assertions for various arrays | [PR](https://github.com/MarkusAmshove/Kluent/pull/165) | thanks to [@ChristianIvicevic](https://github.com/ChristianIvicevic)
* Add `shouldContainAny` with lambda predicates | [PR](https://github.com/MarkusAmshove/Kluent/pull/153) | thanks to [@javatarz](https://github.com/javatarz)
* Various gradle fixes | [PR](https://github.com/MarkusAmshove/Kluent/pull/161) | thanks to [@javatarz](https://github.com/javatarz)

# 1.56
* Support for validating custom exception values | [PR](https://github.com/MarkusAmshove/Kluent/pull/158) | thanks to [@jeggy](https://github.com/jeggy)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ More examples can be seen on the [Site](https://markusamshove.github.io/Kluent/)
### assertEquals ##

```kotlin
"hello" shouldEqual "hello"
"hello" shouldBeEqualTo "hello"
```

### assertNotEquals ##

```kotlin
"hello" shouldNotEqual "world"
"hello" shouldNotBeEqualTo "world"
```

### Assert that an Array/Iterable contains something ##
Expand Down Expand Up @@ -109,12 +109,12 @@ Some examples:
### assertEquals ##

```kotlin
"hello" `should equal` "hello"
"hello" `should be equal to` "hello"
```

### assertNotEquals ##
```kotlin
"hello" `should not equal` "world"
"hello" `should not be equal to` "world"
```

# Building Kluent
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ext {

allprojects {
group 'org.amshove.kluent'
version '1.56'
version '1.59'

apply plugin: 'com.adarshr.test-logger'

Expand Down
10 changes: 8 additions & 2 deletions common/src/main/kotlin/org/amshove/kluent/Basic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.fail

infix fun <T> T.shouldEqual(expected: T?): T = this.apply { assertEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun <T> T.shouldEqual(expected: T?): T = this.shouldBeEqualTo(expected)

infix fun <T> T.shouldNotEqual(expected: T?) = this.apply { assertNotEquals(expected, this) }
infix fun <T> T.shouldBeEqualTo(expected: T?): T = this.apply { assertEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun <T> T.shouldNotEqual(expected: T?) = this.shouldNotBeEqualTo(expected)

infix fun <T> T.shouldNotBeEqualTo(expected: T?) = this.apply { assertNotEquals(expected, this) }

infix fun <T> T.shouldBe(expected: T?): T = this.apply { assertSame(expected, this) }

Expand Down
261 changes: 235 additions & 26 deletions common/src/main/kotlin/org/amshove/kluent/Collections.kt

Large diffs are not rendered by default.

70 changes: 56 additions & 14 deletions common/src/main/kotlin/org/amshove/kluent/Numerical.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,75 @@ import org.amshove.kluent.internal.assertTrue
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

infix fun Boolean.shouldEqualTo(expected: Boolean) = this.apply { assertEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Boolean.shouldEqualTo(expected: Boolean) = this.shouldBeEqualTo(expected)

infix fun Byte.shouldEqualTo(expected: Byte) = this.apply { assertEquals(expected, this) }
infix fun Boolean.shouldBeEqualTo(expected: Boolean) = this.apply { assertEquals(expected, this) }

infix fun Short.shouldEqualTo(expected: Short) = this.apply { assertEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Byte.shouldEqualTo(expected: Byte) = this.shouldBeEqualTo(expected)

infix fun Int.shouldEqualTo(expected: Int) = this.apply { assertEquals(expected, this) }
infix fun Byte.shouldBeEqualTo(expected: Byte) = this.apply { assertEquals(expected, this) }

infix fun Long.shouldEqualTo(expected: Long) = this.apply { assertEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Short.shouldEqualTo(expected: Short) = this.shouldBeEqualTo(expected)

infix fun Float.shouldEqualTo(expected: Float) = this.apply { assertEquals(expected, this) }
infix fun Short.shouldBeEqualTo(expected: Short) = this.apply { assertEquals(expected, this) }

infix fun Double.shouldEqualTo(expected: Double) = this.apply { assertEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Int.shouldEqualTo(expected: Int) = this.shouldBeEqualTo(expected)

infix fun Boolean.shouldNotEqualTo(expected: Boolean) = this.apply { assertNotEquals(expected, this) }
infix fun Int.shouldBeEqualTo(expected: Int) = this.apply { assertEquals(expected, this) }

infix fun Byte.shouldNotEqualTo(expected: Byte) = this.apply { assertNotEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Long.shouldEqualTo(expected: Long) = this.shouldBeEqualTo(expected)

infix fun Short.shouldNotEqualTo(expected: Short) = this.apply { assertNotEquals(expected, this) }
infix fun Long.shouldBeEqualTo(expected: Long) = this.apply { assertEquals(expected, this) }

infix fun Int.shouldNotEqualTo(expected: Int) = this.apply { assertNotEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Float.shouldEqualTo(expected: Float) = this.shouldBeEqualTo(expected)

infix fun Long.shouldNotEqualTo(expected: Long) = this.apply { assertNotEquals(expected, this) }
infix fun Float.shouldBeEqualTo(expected: Float) = this.apply { assertEquals(expected, this) }

infix fun Float.shouldNotEqualTo(expected: Float) = this.apply { assertNotEquals(expected, this) }
@Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)"))
infix fun Double.shouldEqualTo(expected: Double) = this.shouldBeEqualTo(expected)

infix fun Double.shouldNotEqualTo(expected: Double) = this.apply { assertNotEquals(expected, this) }
infix fun Double.shouldBeEqualTo(expected: Double) = this.apply { assertEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Boolean.shouldNotEqualTo(expected: Boolean) = this.shouldNotBeEqualTo(expected)

infix fun Boolean.shouldNotBeEqualTo(expected: Boolean) = this.apply { assertNotEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Byte.shouldNotEqualTo(expected: Byte) = this.shouldNotBeEqualTo(expected)

infix fun Byte.shouldNotBeEqualTo(expected: Byte) = this.apply { assertNotEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Short.shouldNotEqualTo(expected: Short) = this.shouldNotBeEqualTo(expected)

infix fun Short.shouldNotBeEqualTo(expected: Short) = this.apply { assertNotEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Int.shouldNotEqualTo(expected: Int) = this.shouldNotBeEqualTo(expected)

infix fun Int.shouldNotBeEqualTo(expected: Int) = this.apply { assertNotEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Long.shouldNotEqualTo(expected: Long) = this.shouldNotBeEqualTo(expected)

infix fun Long.shouldNotBeEqualTo(expected: Long) = this.apply { assertNotEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Float.shouldNotEqualTo(expected: Float) = this.shouldNotBeEqualTo(expected)

infix fun Float.shouldNotBeEqualTo(expected: Float) = this.apply { assertNotEquals(expected, this) }

@Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)"))
infix fun Double.shouldNotEqualTo(expected: Double) = this.shouldNotBeEqualTo(expected)

infix fun Double.shouldNotBeEqualTo(expected: Double) = this.apply { assertNotEquals(expected, this) }

infix fun Byte.shouldBeGreaterThan(expected: Byte) = this.apply { assertTrue("Expected $this to be greater than $expected", this > expected) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.amshove.kluent.internal

import kotlin.test.assertTrue
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import kotlin.test.fail

internal fun assertTrue(message: String, boolean: Boolean) = assertTrue(boolean, message)
internal inline fun assertTrue(boolean: Boolean, lazyMessage: () -> String) {
if (!boolean) fail(lazyMessage())
}

internal fun assertFalse(message: String, boolean: Boolean) = assertFalse(boolean, message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fun assertMessage(message: String, func: () -> Unit) {
try {
func()
} catch (e: Throwable) {
e.message.shouldEqual(message)
e.message.shouldBeEqualTo(message)
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
package org.amshove.kluent.basic

import org.amshove.kluent.Person
import org.amshove.kluent.shouldEqual
import org.amshove.kluent.shouldBeEqualTo
import kotlin.test.Test
import kotlin.test.assertFails

class ShouldEqualShould {
@Test
fun passWhenComparingEqualStrings() {
"hello world" shouldEqual "hello world"
"hello world" shouldBeEqualTo "hello world"
}

@Test
fun returnTheTestedInstance() {
val hello = "hello world"
val returnedInstance = hello shouldEqual "hello world"
hello shouldEqual returnedInstance
val returnedInstance = hello shouldBeEqualTo "hello world"
hello shouldBeEqualTo returnedInstance
}

@Test
fun failWhenComparingUnequalStrings() {
assertFails { "hello world!" shouldEqual "hello" }
assertFails { "hello world!" shouldBeEqualTo "hello" }
}

@Test
fun failWhenComparingDifferentTypes() {
assertFails { "hello world" shouldEqual 5 }
assertFails { "hello world" shouldBeEqualTo 5 }
}

@Test
fun passWhenCheckingTwoDataObjectsWithSameValues() {
val firstObject = Person("Jon", "Doe")
val secondObject = Person("Jon", "Doe")
firstObject shouldEqual secondObject
firstObject shouldBeEqualTo secondObject
}

@Test
fun failWhenCheckingTwoDataObjectsWithDifferentValues() {
val jane = Person("Jane", "Doe")
val jon = Person("Jon", "Doe")
assertFails { jane shouldEqual jon }
assertFails { jane shouldBeEqualTo jon }
}

}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
package org.amshove.kluent.basic

import org.amshove.kluent.Person
import org.amshove.kluent.shouldEqual
import org.amshove.kluent.shouldNotEqual
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBeEqualTo
import kotlin.test.Test
import kotlin.test.assertFails

class ShouldNotEqualShould {
@Test
fun passWhenCheckingEqualityOfDifferentStrings() {
"hello world!" shouldNotEqual "hello"
"hello world!" shouldNotBeEqualTo "hello"
}

@Test
fun failWhenCheckingEqualityOfEqualStrings() {
assertFails { "hello world!" shouldNotEqual "hello world!" }
assertFails { "hello world!" shouldNotBeEqualTo "hello world!" }
}

@Test
fun passWhenCheckingDifferentTypes() {
"hello world" shouldNotEqual 5
"hello world" shouldNotBeEqualTo 5
}

@Test
fun passWhenCheckingUnequalDataObjects() {
val jane = Person("Jane", "Doe")
val jon = Person("Jon", "Doe")
jane shouldNotEqual jon
jane shouldNotBeEqualTo jon
}

@Test
fun failWhenCheckingEqualDataObjects() {
val jane1 = Person("Jane", "Doe")
val jane2 = Person("Jane", "Doe")
assertFails { jane1 shouldNotEqual jane2 }
assertFails { jane1 shouldNotBeEqualTo jane2 }
}

@Test
fun returnTheTestedInstance() {
val jane = Person("Jane", "Doe")
val jon = Person("Jon", "Doe")
val instance = jane shouldNotEqual jon
instance shouldEqual jane
val instance = jane shouldNotBeEqualTo jon
instance shouldBeEqualTo jane
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class ShouldBeEmptyShould {
iterable.shouldBeEmpty()
}

@Test
fun passWhenTestingAnEmptySequence() {
val sequence = emptySequence<String>()
sequence.shouldBeEmpty()
}

@Test
fun passWhenTestingAnEmptyMap() {
val map = mapOf<Int, String>()
Expand All @@ -33,6 +39,11 @@ class ShouldBeEmptyShould {
assertFails { listOf("Hi").shouldBeEmpty() }
}

@Test
fun failWhenTestingANonEmptySequence() {
assertFails { sequenceOf("Hi").shouldBeEmpty() }
}

@Test
fun failWhenTestingANonEmptyMap() {
assertFails { mapOf(1 to "Hi").shouldBeEmpty() }
Expand Down
Loading

0 comments on commit 0c66fbc

Please sign in to comment.