Skip to content

Commit ff4551b

Browse files
authored
Add samples for SequenceExpectation (#1000)
1 parent b1b8b6e commit ff4551b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/sequenceAssertions.kt

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import ch.tutteli.atrium.logic.changeSubject
1212
* Use `feature(Sequence::asIterable)` if you want to show the transformation in reporting.
1313
*
1414
* @return The newly created [Expect] for the transformed subject.
15+
*
16+
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SequenceExpectationSamples.asIterableFeature
1517
*/
1618
fun <E, T : Sequence<E>> Expect<T>.asIterable(): Expect<Iterable<E>> =
1719
_logic.changeSubject.unreported { it.asIterable() }
@@ -24,6 +26,8 @@ fun <E, T : Sequence<E>> Expect<T>.asIterable(): Expect<Iterable<E>> =
2426
* Use `feature(Sequence::asIterable, assertionCreator)` if you want to show the transformation in reporting.
2527
*
2628
* @return an [Expect] for the subject of `this` expectation.
29+
*
30+
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SequenceExpectationSamples.asIterable
2731
*/
2832
fun <E, T : Sequence<E>> Expect<T>.asIterable(assertionCreator: Expect<Iterable<E>>.() -> Unit): Expect<T> =
2933
apply { asIterable()._logic.appendAsGroup(assertionCreator) }
@@ -37,6 +41,8 @@ fun <E, T : Sequence<E>> Expect<T>.asIterable(assertionCreator: Expect<Iterable<
3741
* @return The newly created [Expect] for the transformed subject.
3842
*
3943
* @since 0.14.0
44+
*
45+
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SequenceExpectationSamples.asListFeature
4046
*/
4147
fun <E, T : Sequence<E>> Expect<T>.asList(): Expect<List<E>> = _logic.changeSubject.unreported { it.toList() }
4248

@@ -50,6 +56,8 @@ fun <E, T : Sequence<E>> Expect<T>.asList(): Expect<List<E>> = _logic.changeSubj
5056
* @return an [Expect] for the subject of `this` expectation.
5157
*
5258
* @since 0.14.0
59+
*
60+
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SequenceExpectationSamples.asList
5361
*/
5462
fun <E, T : Sequence<E>> Expect<T>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<T> =
5563
apply { asList()._logic.appendAsGroup(assertionCreator) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package ch.tutteli.atrium.api.fluent.en_GB.samples
2+
3+
import ch.tutteli.atrium.api.fluent.en_GB.*
4+
import ch.tutteli.atrium.api.verbs.internal.expect
5+
import kotlin.test.Test
6+
7+
class SequenceExpectationSamples {
8+
9+
@Test
10+
fun asIterableFeature() {
11+
expect(sequenceOf(1, 2, 3))
12+
.asIterable() // subject is now of type Iterable<Int>
13+
.toContain
14+
.inOrder // order specifier
15+
.only
16+
.values(1, 2, 3)
17+
18+
fails {
19+
expect(sequenceOf(1, 2, 3))
20+
.asIterable() // subject is now of type Iterable<Int>
21+
.toContain(4)
22+
}
23+
24+
}
25+
26+
@Test
27+
fun asIterable() {
28+
expect(sequenceOf(1, 2, 3))
29+
.asIterable { // subject within this block is of type Iterable<Int>
30+
toContain(1)
31+
toContain(2)
32+
toContain(3)
33+
} // subject here is back to type Sequence<Int>
34+
35+
fails {
36+
expect(sequenceOf(1, 2, 3))
37+
.asIterable { // subject within this block is of type Iterable<Int>
38+
toContain(4)
39+
} // subject here is back to type Sequence<Int>
40+
}
41+
}
42+
43+
@Test
44+
fun asListFeature() {
45+
expect(sequenceOf(1, 2, 3))
46+
.asList() // subject is now of type List<Int>
47+
.toEqual(listOf(1, 2, 3))
48+
}
49+
50+
@Test
51+
fun asList() {
52+
expect(sequenceOf(1, 2, 3))
53+
.asList { // subject within this block is of type List<Int>
54+
toEqual(listOf(1, 2, 3))
55+
} // subject here is back to type Sequence<Int>
56+
}
57+
}

0 commit comments

Comments
 (0)