Skip to content

Commit

Permalink
Rename extracting to eachHaving
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Cooper committed Mar 20, 2024
1 parent bbc79c1 commit b3441bc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions assertk/src/commonMain/kotlin/assertk/assertions/array.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fun <T> Assert<Array<T>>.each(f: (Assert<T>) -> Unit) = given { actual ->
* .containsExactly("Sue", "Bob")
* ```
*/
fun <E, R> Assert<Array<E>>.extracting(f1: (E) -> R): Assert<List<R>> = transform { actual ->
fun <E, R> Assert<Array<E>>.eachHaving(f1: (E) -> R): Assert<List<R>> = transform { actual ->
actual.map(f1)
}

Expand All @@ -217,7 +217,7 @@ fun <E, R> Assert<Array<E>>.extracting(f1: (E) -> R): Assert<List<R>> = transfor
* .containsExactly("Sue" to 20, "Bob" to 22)
* ```
*/
fun <E, R1, R2> Assert<Array<E>>.extracting(f1: (E) -> R1, f2: (E) -> R2): Assert<List<Pair<R1, R2>>> =
fun <E, R1, R2> Assert<Array<E>>.eachHaving(f1: (E) -> R1, f2: (E) -> R2): Assert<List<Pair<R1, R2>>> =
transform { actual ->
actual.map { f1(it) to f2(it) }
}
Expand All @@ -231,7 +231,7 @@ fun <E, R1, R2> Assert<Array<E>>.extracting(f1: (E) -> R1, f2: (E) -> R2): Asser
* .contains(Triple("Sue", 20, "123 Street"), Triple("Bob", 22, "456 Street")
* ```
*/
fun <E, R1, R2, R3> Assert<Array<E>>.extracting(
fun <E, R1, R2, R3> Assert<Array<E>>.eachHaving(
f1: (E) -> R1,
f2: (E) -> R2,
f3: (E) -> R3
Expand Down
6 changes: 3 additions & 3 deletions assertk/src/commonMain/kotlin/assertk/assertions/iterable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fun <E> Assert<Iterable<E>>.each(f: (Assert<E>) -> Unit) = given { actual ->
* .containsOnly("Sue", "Bob")
* ```
*/
fun <E, R> Assert<Iterable<E>>.extracting(f1: (E) -> R): Assert<List<R>> = transform { actual ->
fun <E, R> Assert<Iterable<E>>.eachHaving(f1: (E) -> R): Assert<List<R>> = transform { actual ->
actual.map(f1)
}

Expand All @@ -170,7 +170,7 @@ fun <E, R> Assert<Iterable<E>>.extracting(f1: (E) -> R): Assert<List<R>> = trans
* .containsOnly("Sue" to 20, "Bob" to 22)
* ```
*/
fun <E, R1, R2> Assert<Iterable<E>>.extracting(f1: (E) -> R1, f2: (E) -> R2): Assert<List<Pair<R1, R2>>> =
fun <E, R1, R2> Assert<Iterable<E>>.eachHaving(f1: (E) -> R1, f2: (E) -> R2): Assert<List<Pair<R1, R2>>> =
transform { actual ->
actual.map { f1(it) to f2(it) }
}
Expand All @@ -184,7 +184,7 @@ fun <E, R1, R2> Assert<Iterable<E>>.extracting(f1: (E) -> R1, f2: (E) -> R2): As
* .contains(Triple("Sue", 20, "123 Street"), Triple("Bob", 22, "456 Street")
* ```
*/
fun <E, R1, R2, R3> Assert<Iterable<E>>.extracting(
fun <E, R1, R2, R3> Assert<Iterable<E>>.eachHaving(
f1: (E) -> R1,
f2: (E) -> R2,
f3: (E) -> R3
Expand Down
6 changes: 3 additions & 3 deletions assertk/src/commonMain/kotlin/assertk/assertions/sequence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fun <E> Assert<Sequence<E>>.each(f: (Assert<E>) -> Unit) = given { actual ->
* .containsExactly("Sue", "Bob")
* ```
*/
fun <E, R> Assert<Sequence<E>>.extracting(f1: (E) -> R): Assert<Sequence<R>> = transform { actual ->
fun <E, R> Assert<Sequence<E>>.eachHaving(f1: (E) -> R): Assert<Sequence<R>> = transform { actual ->
actual.map(f1)
}

Expand All @@ -191,7 +191,7 @@ fun <E, R> Assert<Sequence<E>>.extracting(f1: (E) -> R): Assert<Sequence<R>> = t
* .containsExactly("Sue" to 20, "Bob" to 22)
* ```
*/
fun <E, R1, R2> Assert<Sequence<E>>.extracting(f1: (E) -> R1, f2: (E) -> R2): Assert<Sequence<Pair<R1, R2>>> =
fun <E, R1, R2> Assert<Sequence<E>>.eachHaving(f1: (E) -> R1, f2: (E) -> R2): Assert<Sequence<Pair<R1, R2>>> =
transform { actual ->
actual.map { f1(it) to f2(it) }
}
Expand All @@ -205,7 +205,7 @@ fun <E, R1, R2> Assert<Sequence<E>>.extracting(f1: (E) -> R1, f2: (E) -> R2): As
* .contains(Triple("Sue", 20, "123 Street"), Triple("Bob", 22, "456 Street")
* ```
*/
fun <E, R1, R2, R3> Assert<Sequence<E>>.extracting(
fun <E, R1, R2, R3> Assert<Sequence<E>>.eachHaving(
f1: (E) -> R1,
f2: (E) -> R2,
f3: (E) -> R3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ class ArrayTest {
//region extracting
@Test
fun single_extracting_function_passes() {
assertThat(arrayOf("one", "two")).extracting { it.length }.containsExactly(3, 3)
assertThat(arrayOf("one", "two")).eachHaving { it.length }.containsExactly(3, 3)
}

@Test
fun single_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(arrayOf("one", "two")).extracting { it.length }.containsExactly(2, 2)
assertThat(arrayOf("one", "two")).eachHaving { it.length }.containsExactly(2, 2)
}
assertEquals(
"""expected to contain exactly:<[2, 2]> but was:<[3, 3]>
Expand All @@ -397,15 +397,15 @@ class ArrayTest {
@Test
fun pair_extracting_function_passes() {
assertThat(listOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two)
.eachHaving(Thing::one, Thing::two)
.containsExactly("one" to 1, "two" to 2)
}

@Test
fun pair_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(arrayOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two)
.eachHaving(Thing::one, Thing::two)
.containsExactly("one" to 2, "two" to 1)
}
assertEquals(
Expand All @@ -422,15 +422,15 @@ class ArrayTest {
@Test
fun triple_extracting_function_passes() {
assertThat(arrayOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two, Thing::three)
.eachHaving(Thing::one, Thing::two, Thing::three)
.containsExactly(Triple("one", 1, '1'), Triple("two", 2, '2'))
}

@Test
fun triple_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(arrayOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two, Thing::three)
.eachHaving(Thing::one, Thing::two, Thing::three)
.containsExactly(Triple("one", 1, '2'), Triple("two", 2, '3'))
}
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import assertk.assertions.containsOnly
import assertk.assertions.doesNotContain
import assertk.assertions.each
import assertk.assertions.exactly
import assertk.assertions.extracting
import assertk.assertions.eachHaving
import assertk.assertions.first
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
Expand Down Expand Up @@ -506,13 +506,13 @@ class IterableTest {
//region extracting
@Test
fun single_extracting_function_passes() {
assertThat(iterableOf("one", "two")).extracting { it.length }.containsExactly(3, 3)
assertThat(iterableOf("one", "two")).eachHaving { it.length }.containsExactly(3, 3)
}

@Test
fun single_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(iterableOf("one", "two")).extracting { it.length }.containsExactly(2, 2)
assertThat(iterableOf("one", "two")).eachHaving { it.length }.containsExactly(2, 2)
}
assertEquals(
"""expected to contain exactly:<[2, 2]> but was:<[3, 3]>
Expand All @@ -526,15 +526,15 @@ class IterableTest {
@Test
fun pair_extracting_function_passes() {
assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two)
.eachHaving(Thing::one, Thing::two)
.containsExactly("one" to 1, "two" to 2)
}

@Test
fun pair_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two)
.eachHaving(Thing::one, Thing::two)
.containsExactly("one" to 2, "two" to 1)
}
assertEquals(
Expand All @@ -550,15 +550,15 @@ class IterableTest {
@Test
fun triple_extracting_function_passes() {
assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two, Thing::three)
.eachHaving(Thing::one, Thing::two, Thing::three)
.containsExactly(Triple("one", 1, '1'), Triple("two", 2, '2'))
}

@Test
fun triple_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two, Thing::three)
.eachHaving(Thing::one, Thing::two, Thing::three)
.containsExactly(Triple("one", 1, '2'), Triple("two", 2, '3'))
}
assertEquals(
Expand Down Expand Up @@ -630,4 +630,4 @@ class IterableTest {
}

private fun <T> emptyIterable(): Iterable<T> = emptyList()
private fun <T> iterableOf(vararg elements: T): Iterable<T> = elements.toList()
private fun <T> iterableOf(vararg elements: T): Iterable<T> = elements.toList()
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import assertk.assertions.containsOnly
import assertk.assertions.doesNotContain
import assertk.assertions.each
import assertk.assertions.exactly
import assertk.assertions.extracting
import assertk.assertions.eachHaving
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isGreaterThan
Expand Down Expand Up @@ -588,14 +588,14 @@ class SequenceTest {
//region extracting
@Test
fun single_extracting_function_passes() {
assertThat(sequenceOf("one", "two")).extracting { it.length }
assertThat(sequenceOf("one", "two")).eachHaving { it.length }
.containsOnly(3, 3)
}

@Test
fun single_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(sequenceOf("one", "two")).extracting { it.length }.containsExactly(2, 2)
assertThat(sequenceOf("one", "two")).eachHaving { it.length }.containsExactly(2, 2)
}
assertEquals(
"""expected to contain exactly:<[2, 2]> but was:<[3, 3]>
Expand All @@ -609,15 +609,15 @@ class SequenceTest {
@Test
fun pair_extracting_function_passes() {
assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two)
.eachHaving(Thing::one, Thing::two)
.containsExactly("one" to 1, "two" to 2)
}

@Test
fun pair_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two)
.eachHaving(Thing::one, Thing::two)
.containsExactly("one" to 2, "two" to 1)
}
assertEquals(
Expand All @@ -633,15 +633,15 @@ class SequenceTest {
@Test
fun triple_extracting_function_passes() {
assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two, Thing::three)
.eachHaving(Thing::one, Thing::two, Thing::three)
.containsExactly(Triple("one", 1, '1'), Triple("two", 2, '2'))
}

@Test
fun triple_extracting_function_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2')))
.extracting(Thing::one, Thing::two, Thing::three)
.eachHaving(Thing::one, Thing::two, Thing::three)
.containsExactly(Triple("one", 1, '2'), Triple("two", 2, '3'))
}
assertEquals(
Expand All @@ -661,4 +661,4 @@ class SequenceTest {
private fun <T> oneshotSequenceOf(vararg elements: T): Sequence<T> {
var i = 0
return generateSequence { elements.getOrNull(i++) }
}
}

0 comments on commit b3441bc

Please sign in to comment.