Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: samples of iterableSubjectChangers in api-infix and api-fluent #1155

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ch.tutteli.atrium.logic.changeSubject
*
* @return The newly created [Expect] for the transformed subject.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableSubjectChangerSamples.asListFeature
*
* @since 0.14.0
*/
fun <E, T : Iterable<E>> Expect<T>.asList(): Expect<List<E>> = _logic.changeSubject.unreported { it.toList() }
Expand All @@ -25,6 +27,8 @@ fun <E, T : Iterable<E>> Expect<T>.asList(): Expect<List<E>> = _logic.changeSubj
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableSubjectChangerSamples.asList
*
* @since 0.14.0
*/
fun <E, T : Iterable<E>> Expect<T>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<T> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ch.tutteli.atrium.api.fluent.en_GB.samples

import ch.tutteli.atrium.api.fluent.en_GB.asList
import ch.tutteli.atrium.api.fluent.en_GB.toContain
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.internal.expect
import kotlin.test.Test

class IterableSubjectChangerSamples {
@Test
fun asListFeature() {
expect(0..2)
.asList() // subject is now of type List<Int>
.toEqual(listOf(0, 1, 2))

fails {
expect(0..2)
.asList() // subject is now of type List<Int>
.toContain(3) // fails
.toContain(4) // not evaluated/reported because above `toContain` already fails
// use `.asList { ... }` if you want that all expectations are evaluated
robstoll marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Test
fun asList() {
expect(0..2) // subject within this expectation-group is of type List<Int>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move comment one line below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this.

.asList {
toEqual(listOf(0, 1, 2))
} // subject here is back to type IntRange

fails {
// all expectations inside an expectation-group are evaluated together; for more details see:
// https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group

expect(0..2)
.asList {
toContain(3) // fails
toContain(4) // still evaluated even though above `toContain` already fails
// use `.asList().` if you want a fail fast behaviour
robstoll marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import kotlin.jvm.JvmName
*
* @return The newly created [Expect] for the transformed subject.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableSubjectChangerSamples.asListFeature
*
* @since 0.14.0
*/
infix fun <E, T : Iterable<E>> Expect<T>.asList(
Expand All @@ -28,6 +30,8 @@ infix fun <E, T : Iterable<E>> Expect<T>.asList(
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableSubjectChangerSamples.asList
*
* @since 0.14.0
*/
infix fun <E, T : Iterable<E>> Expect<T>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<T> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ch.tutteli.atrium.api.infix.en_GB.samples

import ch.tutteli.atrium.api.infix.en_GB.asList
import ch.tutteli.atrium.api.infix.en_GB.it
import ch.tutteli.atrium.api.infix.en_GB.o
import ch.tutteli.atrium.api.infix.en_GB.toContain
import ch.tutteli.atrium.api.infix.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.internal.expect
import kotlin.test.Test

class IterableSubjectChangerSamples {
@Test
fun asListFeature() {
expect(0..2) asList o toEqual listOf(0, 1, 2)
// | subject is now of type List<Int>
robstoll marked this conversation as resolved.
Show resolved Hide resolved

fails {
expect(0..2) asList o toContain 3 toContain 4
}
}

@Test
fun asList() {
expect(0..2)
.asList { // subject within this expectation-group is of type List<Int>
it toEqual listOf(0, 1, 2)
} // subject here is back to type IntRange

fails {
// all expectations inside an expectation-group are evaluated together; for more details see:
// https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group
expect(0..2)
.asList {
it toContain 3 // fails
it toContain 4 // still evaluated even though above `toContain` already fails
// use `asList o` if you want a fail fast behaviour
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem are the parameter names in intellij. You could hide them but I am going to fix the alignment, that's fine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you fixed it already 🙂👍

}
}
}
}