mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
Merge pull request #895 from robstoll/to-plus-infinitive
cleanup list assertions, they are already follow to + infinitive
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//TODO rename file to listExpectations.kt in 0.18.0
|
||||
package ch.tutteli.atrium.api.fluent.en_GB
|
||||
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
@@ -10,7 +11,7 @@ import ch.tutteli.atrium.logic.get
|
||||
*
|
||||
* @return The newly created [Expect] for the element at position [index].
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.ListAssertionSamples.getFeature
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.ListExpectationSamples.getFeature
|
||||
*/
|
||||
fun <E, T : List<E>> Expect<T>.get(index: Int): Expect<E> =
|
||||
_logic.get(index).transform()
|
||||
@@ -21,7 +22,7 @@ fun <E, T : List<E>> Expect<T>.get(index: Int): Expect<E> =
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.ListAssertionSamples.get
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.ListExpectationSamples.get
|
||||
*/
|
||||
fun <E, T : List<E>> Expect<T>.get(index: Int, assertionCreator: Expect<E>.() -> Unit): Expect<T> =
|
||||
_logic.get(index).collectAndAppend(assertionCreator)
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package ch.tutteli.atrium.api.fluent.en_GB.samples
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.*
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import kotlin.test.Test
|
||||
|
||||
class ListExpectationSamples {
|
||||
|
||||
@Test
|
||||
fun getFeature() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list)
|
||||
.get(0) // subject is now of type Int (actually 1)
|
||||
.toBeGreaterThan(0) // subject is still of type Int (still 1)
|
||||
.toBeLessThan(2)
|
||||
|
||||
fails {
|
||||
expect(list)
|
||||
.get(3) // fails because index 3 is out of bound
|
||||
.toBeLessThan(0) // not reported
|
||||
// use `get(index) { ... }` if you want that all expectations are evaluated
|
||||
}.message {
|
||||
toContain("index out of bounds")
|
||||
notToContain("is less than: 2")
|
||||
}
|
||||
|
||||
fails {
|
||||
expect(list)
|
||||
.get(0)
|
||||
.toBeGreaterThan(2) // fails
|
||||
.toBeLessThan(0) // not reported because `isGreaterThan(2)` already fails
|
||||
// use `get(index) { ... }` if you want that all expectations are evaluated
|
||||
}.message {
|
||||
toContain("is greater than: 2")
|
||||
notToContain("is less than: 0")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list)
|
||||
.get(0) { // subject inside this block is of type Int (actually 1)
|
||||
toBeGreaterThan(0)
|
||||
toBeLessThan(2)
|
||||
} // subject here is back to type List<Int>
|
||||
.get(1) { // subject inside this block is of type Int (actually 2)
|
||||
toBeGreaterThan(1)
|
||||
toBeLessThan(3)
|
||||
}
|
||||
|
||||
fails {
|
||||
// all expectations are evaluated inside an expectation group block; for more details:
|
||||
// https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups
|
||||
|
||||
expect(list)
|
||||
.get(0) {
|
||||
toBeGreaterThan(2) // fails
|
||||
toBeLessThan(0) // still evaluated even though `isGreaterThan(2)` already fails,
|
||||
// use the `.get(index).` if you want a fail fast behaviour
|
||||
}
|
||||
}.messageContains(
|
||||
"is greater than: 2",
|
||||
"is less than: 0"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
//TODO remove file with 1.0.0
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.*
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.samples.fails
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import kotlin.test.Test
|
||||
|
||||
class ListAssertionSamples {
|
||||
|
||||
@Test
|
||||
fun getFeature() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list)
|
||||
.get(0) // subject is now of type Int (actually 1)
|
||||
.isLessThan(2) // subject is still of type Int (still 1)
|
||||
.isGreaterThan(0)
|
||||
|
||||
fails {
|
||||
expect(list)
|
||||
.get(3) // fails because index 3 is out of bound
|
||||
.isLessThan(0) // not reported
|
||||
// use `get(index) { ... }` if you want that all assertions are evaluated
|
||||
}.message {
|
||||
contains("index out of bounds")
|
||||
containsNot("is less than: 2")
|
||||
}
|
||||
|
||||
fails {
|
||||
expect(list)
|
||||
.get(0)
|
||||
.isGreaterThan(2) // fails
|
||||
.isLessThan(0) // not reported because `isGreaterThan(2)` already fails
|
||||
// use `get(index) { ... }` if you want that all assertions are evaluated
|
||||
}.message {
|
||||
contains("is greater than: 2")
|
||||
containsNot("is less than: 0")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list)
|
||||
.get(0) { // subject inside this block is of type Int (actually 1)
|
||||
isLessThan(2)
|
||||
isGreaterThan(0)
|
||||
} // subject here is back to type List<Int>
|
||||
.get(1) { // subject inside this block is of type Int (actually 2)
|
||||
isLessThan(3)
|
||||
isGreaterThan(1)
|
||||
}
|
||||
|
||||
fails {
|
||||
// all assertions are evaluated inside an assertion group block; for more details:
|
||||
// https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups
|
||||
|
||||
expect(list)
|
||||
.get(0) {
|
||||
isGreaterThan(2) // fails
|
||||
isLessThan(0) // still evaluated even though `isGreaterThan(2)` already fails,
|
||||
// use the `.get(index).` if you want a fail fast behaviour
|
||||
}
|
||||
}.messageContains(
|
||||
"is greater than: 2",
|
||||
"is less than: 0"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
//TODO rename file to listExpectations.kt in 0.18.0
|
||||
package ch.tutteli.atrium.api.infix.en_GB
|
||||
|
||||
import ch.tutteli.atrium.api.infix.en_GB.creating.IndexWithCreator
|
||||
@@ -11,7 +12,7 @@ import ch.tutteli.atrium.logic.get
|
||||
*
|
||||
* @return The newly created [Expect] for the element at position [index].
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.deprecated.ListAssertionSamples.getFeature
|
||||
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ListExpectationSamples.getFeature
|
||||
*/
|
||||
infix fun <E, T : List<E>> Expect<T>.get(index: Int): Expect<E> =
|
||||
_logic.get(index).transform()
|
||||
@@ -25,7 +26,7 @@ infix fun <E, T : List<E>> Expect<T>.get(index: Int): Expect<E> =
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.deprecated.ListAssertionSamples.get
|
||||
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ListExpectationSamples.get
|
||||
*/
|
||||
infix fun <E, T : List<E>> Expect<T>.get(index: IndexWithCreator<E>): Expect<T> =
|
||||
_logic.get(index.index).collectAndAppend(index.assertionCreator)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package ch.tutteli.atrium.api.infix.en_GB.samples
|
||||
|
||||
import ch.tutteli.atrium.api.infix.en_GB.*
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.translations.DescriptionComparableAssertion
|
||||
import kotlin.test.Test
|
||||
|
||||
class ListExpectationSamples {
|
||||
private val toBeLessThanDescr = DescriptionComparableAssertion.IS_LESS_THAN.getDefault()
|
||||
private val toBeGreaterThanDescr = DescriptionComparableAssertion.IS_GREATER_THAN.getDefault()
|
||||
|
||||
@Test
|
||||
fun getFeature() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list) get 0 toBeGreaterThan 0 toBeLessThan 2
|
||||
// | | subject is still of type Int (still 1)
|
||||
// | subject is now of type Int (actually 1)
|
||||
|
||||
fails {
|
||||
expect(list) get 3 toBeLessThan 0
|
||||
// | | not reported
|
||||
// | fails because index 3 is out of bound
|
||||
// use `get index(elementIndex) { ... }` if you want that all expectations are evaluated
|
||||
} message {
|
||||
toContain("index out of bounds")
|
||||
notToContain("is less than: 0")
|
||||
}
|
||||
|
||||
fails {
|
||||
expect(list) get 0 toBeGreaterThan 2 toBeLessThan 0
|
||||
// | | | not reported because `toBeGreaterThan 2` already fails
|
||||
// | | fails
|
||||
// | subject is now of type Int (actually 1)
|
||||
expect(list) get 0 toBeLessThan 0
|
||||
// use `get index(elementIndex) { ... }` if you want that all expectations are evaluated
|
||||
|
||||
} message {
|
||||
toContain("${toBeGreaterThanDescr}: 2")
|
||||
notToContain("${toBeLessThanDescr}: 0")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list) get index(0) { // subject inside this block is of type Int (actually 1)
|
||||
it toBeLessThan 2
|
||||
it toBeGreaterThan 0
|
||||
}
|
||||
|
||||
expect(list) get index(1) { // subject inside this block is of type Int (actually 2)
|
||||
it toBeLessThan 3
|
||||
it toBeGreaterThan 1
|
||||
}
|
||||
|
||||
fails {
|
||||
// all expectations are evaluated inside an expectation group block; for more details:
|
||||
// https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups
|
||||
|
||||
expect(list) get index(0) {
|
||||
it toBeGreaterThan 2 // fails
|
||||
it toBeLessThan 0 // still evaluated even though `isGreaterThan(2)` already fails,
|
||||
// use `get index` if you want a fail fast behaviour
|
||||
}
|
||||
} messageContains values(
|
||||
"${toBeGreaterThanDescr}: 2",
|
||||
"${toBeLessThanDescr}: 0"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
//TODO remove file with 1.0.0
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package ch.tutteli.atrium.api.infix.en_GB.samples.deprecated
|
||||
|
||||
import ch.tutteli.atrium.api.infix.en_GB.*
|
||||
import ch.tutteli.atrium.api.infix.en_GB.samples.fails
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.translations.DescriptionComparableAssertion
|
||||
import kotlin.test.Test
|
||||
|
||||
class ListAssertionSamples {
|
||||
private val isLessThanDescr = DescriptionComparableAssertion.IS_LESS_THAN.getDefault()
|
||||
private val isGreaterThanDescr = DescriptionComparableAssertion.IS_GREATER_THAN.getDefault()
|
||||
|
||||
@Test
|
||||
fun getFeature() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list) get 0 isLessThan 2 isGreaterThan 0
|
||||
// | | subject is still of type Int (still 1)
|
||||
// | | subject is still of type Int (still 1)
|
||||
// | subject is now of type Int (actually 1)
|
||||
|
||||
fails {
|
||||
expect(list) get 3 isLessThan 0
|
||||
// | | not reported
|
||||
// | fails because index 3 is out of bound
|
||||
// use `get index(elementIndex) { ... }` if you want that all assertions are evaluated
|
||||
} message {
|
||||
toContain("index out of bounds")
|
||||
notToContain("is less than: 0")
|
||||
}
|
||||
|
||||
fails {
|
||||
expect(list) get 0 isGreaterThan 2 isLessThan 0
|
||||
// | | | not reported because `isGreaterThan 2` already fails
|
||||
// | | fails
|
||||
// | subject is now of type Int (actually 1)
|
||||
expect(list) get 0 isLessThan 0
|
||||
// use `get index(elementIndex) { ... }` if you want that all assertions are evaluated
|
||||
|
||||
} message {
|
||||
toContain("${isGreaterThanDescr}: 2")
|
||||
notToContain("${isLessThanDescr}: 0")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get() {
|
||||
val list = listOf(1, 2, 3)
|
||||
|
||||
expect(list) get index(0) { // subject inside this block is of type Int (actually 1)
|
||||
it isLessThan 2
|
||||
it isGreaterThan 0
|
||||
}
|
||||
|
||||
expect(list) get index(1) { // subject inside this block is of type Int (actually 2)
|
||||
it isLessThan 3
|
||||
it isGreaterThan 1
|
||||
}
|
||||
|
||||
fails {
|
||||
// all assertions are evaluated inside an assertion group block; for more details:
|
||||
// https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups
|
||||
|
||||
expect(list) get index(0) {
|
||||
it isGreaterThan 2 // fails
|
||||
it isLessThan 0 // still evaluated even though `isGreaterThan(2)` already fails,
|
||||
// use the ` get elementIndex ` if you want a fail fast behaviour
|
||||
}
|
||||
} messageContains values(
|
||||
"${isGreaterThanDescr}: 2",
|
||||
"${isLessThanDescr}: 0"
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user