diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableAssertions.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableAssertions.kt index 787ab0f80..35e4f1218 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableAssertions.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableAssertions.kt @@ -372,8 +372,8 @@ fun > Expect.hasNotNext(): Expect = * @since 0.14.0 */ @Deprecated( - "Use notToContainDuplicates; will be removed with 1.0.0 at the latest", - ReplaceWith("this.notToContainDuplicates()") + "Use toHaveElementsAndNoDuplicates; will be removed with 1.0.0 at the latest", + ReplaceWith("this.toHaveElementsAndNoDuplicates()") ) fun > Expect.containsNoDuplicates(): Expect = _logicAppend { containsNoDuplicates(::identity) } diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableExpectations.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableExpectations.kt index 9b26fe734..e5ad6f57e 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableExpectations.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/iterableExpectations.kt @@ -234,6 +234,31 @@ inline fun > Expect.toContainElementsOf( fun > Expect.notToContain(expected: E, vararg otherExpected: E): Expect = notToContain.values(expected, *otherExpected) +/** + * Expects that the subject of `this` expectation (an [Iterable]) has a next element ([Iterator.hasNext] returns true). + * + * @return an [Expect] for the subject of `this` expectation. + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableExpectationSamples.toHaveElements + * + * @since 0.17.0 + */ +fun > Expect.toHaveElements(): Expect = + _logicAppend { hasNext(::identity) } + +/** + * Expects that the subject of `this` expectation (an [Iterable]) does not have a next element + * ([Iterator.hasNext] returns false). + * + * @return an [Expect] for the subject of `this` expectation. + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableExpectationSamples.notToHaveElements + * + * @since 0.17.0 + */ +fun > Expect.notToHaveElements(): Expect = + _logicAppend { hasNotNext(::identity) } + /** * Expects that the subject of `this` expectation (an [Iterable]) has next element(s) and * - that any of them holds the expectations the [assertionCreatorOrNull] creates or @@ -282,38 +307,14 @@ fun > Expect.toHaveElementsAndAll(assertionCreatorO /** - * Expects that the subject of `this` expectation (an [Iterable]) has a next element ([Iterator.hasNext] returns true). + * Expects that the subject of `this` expectation (an [Iterable]) has next element(s) and + * that it does not have duplicate elements. * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableExpectationSamples.toHaveElements + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableExpectationSamples.toHaveElementsAndNoDuplicates * * @since 0.17.0 */ -fun > Expect.toHaveElements(): Expect = - _logicAppend { hasNext(::identity) } - -/** - * Expects that the subject of `this` expectation (an [Iterable]) does not have a next element - * ([Iterator.hasNext] returns false). - * - * @return an [Expect] for the subject of `this` expectation. - * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableExpectationSamples.notToHaveElements - * - * @since 0.17.0 - */ -fun > Expect.notToHaveElements(): Expect = - _logicAppend { hasNotNext(::identity) } - -/** - * Expects that the subject of `this` expectation (an [Iterable]) does not have duplicate elements. - * - * @return an [Expect] for the subject of `this` expectation. - * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableExpectationSamples.notToContainDuplicates - * - * @since 0.17.0 - */ -fun > Expect.notToContainDuplicates(): Expect = +fun > Expect.toHaveElementsAndNoDuplicates(): Expect = _logicAppend { containsNoDuplicates(::identity) } diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableExpectationsSpec.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableExpectationsSpec.kt index 5b47aa8a1..bef11b4fd 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableExpectationsSpec.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableExpectationsSpec.kt @@ -10,7 +10,7 @@ object IterableExpectationsSpec : ch.tutteli.atrium.specs.integration.IterableEx fun1, Expect.() -> Unit>(Expect>::min), feature0, Int>(Expect>::max), fun1, Expect.() -> Unit>(Expect>::max), - fun0(Expect>::notToContainDuplicates) + fun0(Expect>::toHaveElementsAndNoDuplicates) ) { @Suppress("unused", "UNUSED_VALUE") @@ -21,15 +21,15 @@ object IterableExpectationsSpec : ch.tutteli.atrium.specs.integration.IterableEx a1 = a1.toHaveElements() a1 = a1.notToHaveElements() - a1 = a1.notToContainDuplicates() + a1 = a1.toHaveElementsAndNoDuplicates() a1b = a1b.toHaveElements() a1b = a1b.notToHaveElements() - a1b = a1b.notToContainDuplicates() + a1b = a1b.toHaveElementsAndNoDuplicates() star = star.toHaveElements() star = star.notToHaveElements() - star = star.notToContainDuplicates() + star = star.toHaveElementsAndNoDuplicates() //nullable not supported by min/max or rather T : Comparable does not exist for T? (one cannot implement an interface for the nullable type) //same for Iterable<*> diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableExpectationSamples.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableExpectationSamples.kt index 9101fb0d0..c2113e1b9 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableExpectationSamples.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableExpectationSamples.kt @@ -162,6 +162,25 @@ class IterableExpectationSamples { } } + @Test + fun toHaveElements() { + expect(listOf("A", 1, 3f)).toHaveElements() + + fails { + expect(emptyList()).toHaveElements() + } + } + + @Test + fun notToHaveElements() { + expect(setOf()).notToHaveElements() + + fails { + expect(listOf("A", "B")).notToHaveElements() + } + } + + @Test fun toHaveElementsAndAny() { expect(listOf(1, 2, 2, 4)).toHaveElementsAndAny { @@ -212,30 +231,13 @@ class IterableExpectationSamples { } } - @Test - fun toHaveElements() { - expect(listOf("A", 1, 3f)).toHaveElements() - - fails { - expect(emptyList()).toHaveElements() - } - } @Test - fun notToHaveElements() { - expect(setOf()).notToHaveElements() + fun toHaveElementsAndNoDuplicates() { + expect(listOf("A", "B")).toHaveElementsAndNoDuplicates() fails { - expect(listOf("A", "B")).notToHaveElements() - } - } - - @Test - fun notToContainDuplicates() { - expect(listOf("A", "B")).notToContainDuplicates() - - fails { - expect(listOf("A", "B", "C", "A")).notToContainDuplicates() + expect(listOf("A", "B", "C", "A")).toHaveElementsAndNoDuplicates() } } } diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableAssertions.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableAssertions.kt index 9fd92679d..4d6db8c97 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableAssertions.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableAssertions.kt @@ -419,8 +419,8 @@ infix fun > Expect.hasNot(@Suppress("UNUSED_PARAMETER") ne * @since 0.14.0 */ @Deprecated( - "Use notToContainDuplicates; will be removed with 1.0.0 at the latest", - ReplaceWith("this.notToContain(duplicates)", "ch.tutteli.atrium.api.infix.en_GB.duplicates") + "Use toHaveElementsAnd noDuplicates; will be removed with 1.0.0 at the latest", + ReplaceWith("this.toHaveElementsAnd(noDuplicates)") ) @Suppress("DEPRECATION") infix fun > Expect.contains(@Suppress("UNUSED_PARAMETER") noDuplicates: noDuplicates): Expect = diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableExpectations.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableExpectations.kt index f06da8966..85c17ecc9 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableExpectations.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableExpectations.kt @@ -259,6 +259,26 @@ infix fun > Expect.notToContain(expected: E): Expect = infix fun > Expect.notToContain(values: Values): Expect = it notToContain o the values +/** + * Expects that the subject of `this` expectation (an [Iterable]) has at least one element. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +infix fun > Expect.toHave(@Suppress("UNUSED_PARAMETER") elements: elements): Expect = + _logicAppend { hasNext(::identity) } + +/** + * Expects that the subject of `this` expectation (an [Iterable]) does not have next element. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +infix fun > Expect.notToHave(@Suppress("UNUSED_PARAMETER") elements: elements): Expect = + _logicAppend { hasNotNext(::identity) } + /** * Expects that the subject of `this` expectation (an [Iterable]) contains an entry holding @@ -302,26 +322,6 @@ infix fun > Expect.toHaveElementsAndAll(assertionCr _logicAppend { all(::identity, assertionCreatorOrNull) } -/** - * Expects that the subject of `this` expectation (an [Iterable]) has at least one element. - * - * @return an [Expect] for the subject of `this` expectation. - * - * @since 0.17.0 - */ -infix fun > Expect.toHave(@Suppress("UNUSED_PARAMETER") elements: elements): Expect = - _logicAppend { hasNext(::identity) } - -/** - * Expects that the subject of `this` expectation (an [Iterable]) does not have next element. - * - * @return an [Expect] for the subject of `this` expectation. - * - * @since 0.17.0 - */ -infix fun > Expect.notToHave(@Suppress("UNUSED_PARAMETER") elements: elements): Expect = - _logicAppend { hasNotNext(::identity) } - /** * Expects that the subject of `this` expectation (an [Iterable]) does not have duplicate elements. * @@ -329,6 +329,6 @@ infix fun > Expect.notToHave(@Suppress("UNUSED_PARAMETER") * * @since 0.17.0 */ -infix fun > Expect.notToContain(@Suppress("UNUSED_PARAMETER") duplicates: duplicates): Expect = +infix fun > Expect.toHaveElementsAnd(@Suppress("UNUSED_PARAMETER") noDuplicates: noDuplicates): Expect = _logicAppend { containsNoDuplicates(::identity) } diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt index 4529ff2d5..91357d442 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt @@ -168,17 +168,8 @@ object executable : Keyword * * @since 0.14.0 */ -@Deprecated("Will be removed with 1.0.0 at the latest without replacement") object noDuplicates : Keyword -/** - * A helper construct to allow expressing expectations about duplicates as in `expect(iterable) notToContain duplicates`. - * It can be used for a parameterless function so that it has one parameter and thus can be used as infix function. - * - * @since 0.17.0 - */ -object duplicates : Keyword - /** * A helper construct to allow expressing expectations about elements as in `expect(iterable) toHave elements`. * It can be used for a parameterless function so that it has one parameter and thus can be used as infix function. diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableExpectationsSpec.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableExpectationsSpec.kt index a41736af6..78da7a130 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableExpectationsSpec.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableExpectationsSpec.kt @@ -6,22 +6,22 @@ import kotlin.reflect.KFunction2 class IterableExpectationsSpec : ch.tutteli.atrium.specs.integration.IterableExpectationsSpec( getToHaveElementsPair(), - getNotToHaveElementstPair(), + getNotToHaveElementsPair(), minFeaturePair(), fun1, Expect.() -> Unit>(Expect>::min), maxFeaturePair(), fun1, Expect.() -> Unit>(Expect>::max), - getToContainNoDuplicatesPair() + getToHaveElementsAndNoDuplicatesPair() ) { companion object { private val toHave: KFunction2>, elements, Expect>> = Expect>::toHave - private fun getToHaveElementsPair() = "${toHave.name} ${next::class.simpleName}" to Companion::toHaveElements + private fun getToHaveElementsPair() = "${toHave.name} ${elements::class.simpleName}" to Companion::toHaveElements private fun toHaveElements(expect: Expect>) = expect toHave elements private val notToHave: KFunction2>, elements, Expect>> = Expect>::notToHave - private fun getNotToHaveElementstPair() = "${notToHave.name} ${next::class.simpleName}" to Companion::notToHaveElements + private fun getNotToHaveElementsPair() = "${notToHave.name} ${elements::class.simpleName}" to Companion::notToHaveElements private fun notToHaveElements(expect: Expect>) = expect notToHave elements private fun minFeaturePair() = feature1, o, Int>(Expect>::min).name to ::minFeature @@ -30,13 +30,13 @@ class IterableExpectationsSpec : ch.tutteli.atrium.specs.integration.IterableExp private fun maxFeaturePair() = feature1, o, Int>(Expect>::min).name to ::maxFeature private fun maxFeature(expect: Expect>) = expect max o - private val notToContainDuplicates: KFunction2>, duplicates, Expect>> = - Expect>::notToContain + private val toHaveElementsAnd: KFunction2>, noDuplicates, Expect>> = + Expect>::toHaveElementsAnd - private fun getToContainNoDuplicatesPair() = - "${notToContainDuplicates.name} ${duplicates::class.simpleName}" to Companion::toContainNoDuplicates + private fun getToHaveElementsAndNoDuplicatesPair() = + "${toHaveElementsAnd.name} ${noDuplicates::class.simpleName}" to Companion::toHaveElementsAndNoDuplicates - private fun toContainNoDuplicates(expect: Expect>) = expect notToContain duplicates + private fun toHaveElementsAndNoDuplicates(expect: Expect>) = expect toHaveElementsAnd noDuplicates } @@ -48,15 +48,15 @@ class IterableExpectationsSpec : ch.tutteli.atrium.specs.integration.IterableExp a1 = a1 toHave elements a1 = a1 notToHave elements - a1 = a1 notToContain duplicates + a1 = a1 toHaveElementsAnd noDuplicates a1b = a1b toHave elements a1b = a1b notToHave elements - a1b = a1b notToContain duplicates + a1b = a1b toHaveElementsAnd noDuplicates star = star toHave elements star = star notToHave elements - star = star notToContain duplicates + star = star toHaveElementsAnd noDuplicates //nullable not supported by min/max or rather T : Comparable does not exist for T? (one cannot implement an interface for the nullable type) //same for Iterable<*> diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/IterableExpectationsSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/IterableExpectationsSpec.kt index 01cc9e500..144164708 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/IterableExpectationsSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/IterableExpectationsSpec.kt @@ -11,23 +11,25 @@ import org.spekframework.spek2.Spek import org.spekframework.spek2.style.specification.Suite abstract class IterableExpectationsSpec( - toHaveANextElement: Fun0>, - notToHaveANextElement: Fun0>, + toHaveElements: Fun0>, + notToHaveElements: Fun0>, minFeature: Feature0, Int>, min: Fun1, Expect.() -> Unit>, maxFeature: Feature0, Int>, max: Fun1, Expect.() -> Unit>, - notToContainDuplicates: Fun0>, + toHaveElementsAndNoDuplicates: Fun0>, describePrefix: String = "[Atrium] " ) : Spek({ include(object : SubjectLessSpec>( describePrefix, - toHaveANextElement.forSubjectLess(), + toHaveElements.forSubjectLess(), + notToHaveElements.forSubjectLess(), minFeature.forSubjectLess(), min.forSubjectLess { toBeGreaterThan(-100) }, maxFeature.forSubjectLess(), - max.forSubjectLess { toEqual(1) } + max.forSubjectLess { toEqual(1) }, + toHaveElementsAndNoDuplicates.forSubjectLess() ) {}) include(object : AssertionCreatorSpec>( @@ -46,30 +48,30 @@ abstract class IterableExpectationsSpec( val hasANextElement = "$hasDescr: $nextElementDescr" - describeFun(toHaveANextElement) { - val toHaveANextElementFun = toHaveANextElement.lambda + describeFun(toHaveElements) { + val toHaveElementsFun = toHaveElements.lambda it("does not throw if an iterable has next") { - expect(listOf(1, 2) as Iterable).toHaveANextElementFun() + expect(listOf(1, 2) as Iterable).toHaveElementsFun() } it("throws an AssertionError if an iterable does not have next") { expect { - expect(listOf() as Iterable).toHaveANextElementFun() + expect(listOf() as Iterable).toHaveElementsFun() }.toThrow { messageToContain(hasANextElement) } } } - describeFun(notToHaveANextElement) { - val notToHaveANextElementFun = notToHaveANextElement.lambda + describeFun(notToHaveElements) { + val notToHaveElementsFun = notToHaveElements.lambda it("does not throw if an iterable has not next") { - expect(listOf() as Iterable).notToHaveANextElementFun() + expect(listOf() as Iterable).notToHaveElementsFun() } it("throws an AssertionError if an iterable has next element") { expect { - expect(listOf(1, 2) as Iterable).notToHaveANextElementFun() + expect(listOf(1, 2) as Iterable).notToHaveElementsFun() }.toThrow { messageToContain("$hasNotDescr: $nextElementDescr") } } } @@ -131,17 +133,17 @@ abstract class IterableExpectationsSpec( } } - describeFun(notToContainDuplicates) { - val notToContainDuplicatesFun = notToContainDuplicates.lambda + describeFun(toHaveElementsAndNoDuplicates) { + val toHaveElementsAndNoDuplicatesFun = toHaveElementsAndNoDuplicates.lambda describe("empty collection") { it("throws AssertionError as there needs to be at least one element") { expect { - expect(listOf() as Iterable).notToContainDuplicatesFun() + expect(listOf() as Iterable).toHaveElementsAndNoDuplicatesFun() }.toThrow { message { toContain( - "$hasANextElement", + hasANextElement, "$hasNotDescr: $duplicateElements" ) } @@ -151,7 +153,7 @@ abstract class IterableExpectationsSpec( describe("list without duplicates") { it("happy case") { - expect(listOf(1, 2) as Iterable).notToContainDuplicatesFun() + expect(listOf(1, 2) as Iterable).toHaveElementsAndNoDuplicatesFun() } } @@ -164,7 +166,7 @@ abstract class IterableExpectationsSpec( val input = listOf(1, 2, 1, 2, 3, 4, 4, 4).asIterable() expect { - expect(input).notToContainDuplicatesFun() + expect(input).toHaveElementsAndNoDuplicatesFun() }.toThrow { message { toContain("$hasNotDescr: $duplicateElements")