diff --git a/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableNotToContainEntriesExpectationsTest.kt b/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableNotToContainEntriesExpectationsTest.kt new file mode 100644 index 0000000000..229ca44507 --- /dev/null +++ b/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableNotToContainEntriesExpectationsTest.kt @@ -0,0 +1,61 @@ +package ch.tutteli.atrium.api.fluent.en_GB + +import ch.tutteli.atrium.api.verbs.internal.expect +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.specs.integration.AbstractIterableNotToContainEntriesExpectationsTest +import ch.tutteli.atrium.specs.withNullableSuffix +import kotlin.test.Test + +class IterableNotToContainEntriesExpectationsTest : + AbstractIterableNotToContainEntriesExpectationsTest( + functionDescription to Companion::notToContainFun, + (functionDescription to Companion::notToContainNullableFun).withNullableSuffix(), + Expect>::notToHaveElementsOrNone.name, + ) { + companion object : IterableToContainSpecBase() { + private val functionDescription = "$notToContain.$entry/$entries" + + private fun notToContainFun( + expect: Expect>, + a: Expect.() -> Unit, + aX: Array.() -> Unit> + ): Expect> = + if (aX.isEmpty()) expect.notToContain.entry(a) + else expect.notToContain.entries(a, *aX) + + private fun notToContainNullableFun( + expect: Expect>, + a: (Expect.() -> Unit)?, + aX: Array.() -> Unit)?> + ): Expect> = + if (aX.isEmpty()) expect.notToContain.entry(a) + else expect.notToContain.entries(a, *aX) + } + + + @Test + @Suppress("AssignedValueIsNeverRead") + fun ambiguityTest() { + var list: Expect> = expect(listOf(1, 2, 3)) + var nList: Expect> = expect(setOf(1, 2)) + var subList: Expect> = expect(arrayListOf(1, 2, 3)) + var star: Expect> = expect(listOf(1, 2)) + + + list = list.notToContain.value(4) + nList = nList.notToContain.value(4) + subList = subList.notToContain.value(4) + star = star.notToContain.value(4) + + nList = nList.notToContain.value(null) + star = star.notToContain.value(null) + + list = list.notToContain.values(5, 7) + nList = nList.notToContain.values(3, 4) + subList = subList.notToContain.values(5, 6) + star = star.notToContain.values(7, 8) + + nList = nList.notToContain.values(null, 8) + star = star.notToContain.values(null, {}) + } +} diff --git a/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableToContainNotEntriesExpectationsSpec.kt b/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableToContainNotEntriesExpectationsSpec.kt deleted file mode 100644 index 767df9d240..0000000000 --- a/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableToContainNotEntriesExpectationsSpec.kt +++ /dev/null @@ -1,58 +0,0 @@ -package ch.tutteli.atrium.api.fluent.en_GB - -import ch.tutteli.atrium.creating.Expect -import ch.tutteli.atrium.specs.notImplemented -import ch.tutteli.atrium.specs.withNullableSuffix - -class IterableNotToContainEntriesExpectationsSpec : - ch.tutteli.atrium.specs.integration.IterableNotToContainEntriesExpectationsSpec( - functionDescription to Companion::notToContainFun, - (functionDescription to Companion::notToContainNullableFun).withNullableSuffix(), - Expect>::notToHaveElementsOrNone.name, - "[Atrium][Builder] " - ) { - companion object : IterableToContainSpecBase() { - private val functionDescription = "$notToContain.$entry/$entries" - - private fun notToContainFun( - expect: Expect>, - a: Expect.() -> Unit, - aX: Array.() -> Unit> - ): Expect> = - if (aX.isEmpty()) expect.notToContain.entry(a) - else expect.notToContain.entries(a, *aX) - - private fun notToContainNullableFun( - expect: Expect>, - a: (Expect.() -> Unit)?, - aX: Array.() -> Unit)?> - ): Expect> = - if (aX.isEmpty()) expect.notToContain.entry(a) - else expect.notToContain.entries(a, *aX) - } - - @Suppress("unused", "UNUSED_VALUE") - private fun ambiguityTest() { - var list: Expect> = notImplemented() - var nList: Expect> = notImplemented() - var subList: Expect> = notImplemented() - var star: Expect> = notImplemented() - - - list = list.notToContain.entry {} - nList = nList.notToContain.entry {} - subList = subList.notToContain.entry {} - star = star.notToContain.entry {} - - nList = nList.notToContain.entry(null) - star = star.notToContain.entry(null) - - list = list.notToContain.entries({}, {}) - nList = nList.notToContain.entries({}, {}) - subList = subList.notToContain.entries({}, {}) - star = star.notToContain.entries({}, {}) - - nList = nList.notToContain.entries(null, {}, null) - star = star.notToContain.entries(null, {}, null) - } -} diff --git a/apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToContainEntriesExpectationsSpec.kt b/apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToContainEntriesExpectationsTest.kt similarity index 85% rename from apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToContainEntriesExpectationsSpec.kt rename to apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToContainEntriesExpectationsTest.kt index 5e8129bd63..a2953cf5e1 100644 --- a/apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToContainEntriesExpectationsSpec.kt +++ b/apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToContainEntriesExpectationsTest.kt @@ -1,14 +1,14 @@ package ch.tutteli.atrium.api.infix.en_GB import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.specs.integration.AbstractIterableNotToContainEntriesExpectationsTest import ch.tutteli.atrium.specs.withNullableSuffix -class IterableNotToContainEntriesExpectationsSpec : - ch.tutteli.atrium.specs.integration.IterableNotToContainEntriesExpectationsSpec( +class IterableNotToContainEntriesExpectationsTest : + AbstractIterableNotToContainEntriesExpectationsTest( getNotToContainPair(), getNotToContainNullablePair().withNullableSuffix(), Expect>::notToHaveElementsOrNone.name, - "[Atrium][Builder] " ) { companion object : IterableToContainSpecBase() { diff --git a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AbstractIterableNotToContainEntriesExpectationsTest.kt b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AbstractIterableNotToContainEntriesExpectationsTest.kt new file mode 100644 index 0000000000..4f639be70d --- /dev/null +++ b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AbstractIterableNotToContainEntriesExpectationsTest.kt @@ -0,0 +1,258 @@ +package ch.tutteli.atrium.specs.integration + +import ch.tutteli.atrium.api.fluent.en_GB.message +import ch.tutteli.atrium.api.fluent.en_GB.notToContain +import ch.tutteli.atrium.api.fluent.en_GB.regex +import ch.tutteli.atrium.api.fluent.en_GB.toBeGreaterThan +import ch.tutteli.atrium.api.fluent.en_GB.toBeLessThan +import ch.tutteli.atrium.api.fluent.en_GB.toContainRegex +import ch.tutteli.atrium.api.fluent.en_GB.toEqual +import ch.tutteli.atrium.api.fluent.en_GB.toThrow +import ch.tutteli.atrium.api.verbs.internal.expect +import ch.tutteli.atrium.core.polyfills.format +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.logic.utils.expectLambda +import ch.tutteli.atrium.specs.Fun2 +import ch.tutteli.atrium.specs.explanatoryBulletPoint +import ch.tutteli.atrium.specs.forExpectationCreatorTest +import ch.tutteli.atrium.specs.forSubjectLessTest +import ch.tutteli.atrium.specs.hintBulletPoint +import ch.tutteli.atrium.specs.indentListBulletPoint +import ch.tutteli.atrium.specs.indentRootBulletPoint +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.afterExplanatory +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.afterExplanatoryIndent +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.afterMismatchedWarning +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.anElementWhichNeedsDescr +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.hasANextElement +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.index +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.mismatchedIndex +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.toBeGreaterThanFun +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.toBeLessThanFun +import ch.tutteli.atrium.specs.integration.IterableToContainEntriesSpecBase.Companion.toEqualFun +import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.mismatches +import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.oneToSeven +import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.oneToSevenNullable +import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.separator +import ch.tutteli.atrium.specs.integration.utils.ExpectationCreatorTestData +import ch.tutteli.atrium.specs.integration.utils.ExpectationCreatorTriple +import ch.tutteli.atrium.specs.integration.utils.SubjectLessTestData +import ch.tutteli.atrium.specs.invoke +import ch.tutteli.atrium.specs.listBulletPoint +import ch.tutteli.atrium.specs.rootBulletPoint +import ch.tutteli.atrium.specs.toEqualDescr +import ch.tutteli.atrium.specs.warningBulletPoint +import ch.tutteli.atrium.testfactories.TestFactory +import ch.tutteli.atrium.translations.DescriptionComparableExpectation +import ch.tutteli.atrium.translations.DescriptionIterableLikeExpectation +import ch.tutteli.kbox.toVararg + + +@Suppress("FunctionName") +abstract class AbstractIterableNotToContainEntriesExpectationsTest( + private val notToContainEntriesSpec: Fun2, Expect.() -> Unit, Array.() -> Unit>>, + private val notToContainNullableEntriesSpec: Fun2, (Expect.() -> Unit)?, Array.() -> Unit)?>>, + private val notToHaveElementsOrNoneFunName: String, +) : ExpectationFunctionBaseTest() { + + @TestFactory + fun subjectLessTest() = subjectLessTestFactory( + SubjectLessTestData( + notToContainEntriesSpec.forSubjectLessTest({ toEqual(2.3) }, arrayOf()) + ), + SubjectLessTestData( + notToContainNullableEntriesSpec.forSubjectLessTest({ toEqual(2.3) }, arrayOf()) + ) + ) + + private val notToContainDescr = DescriptionIterableLikeExpectation.NOT_TO_CONTAIN.getDefault() + private val toBeLessThanDescr = DescriptionComparableExpectation.TO_BE_LESS_THAN.getDefault() + private val toBeGreaterThanDescr = DescriptionComparableExpectation.TO_BE_GREATER_THAN.getDefault() + + @TestFactory + fun expectationCreatorTest() = expectationCreatorTestFactory( + + notToContainEntriesSpec.forExpectationCreatorTest( + "$toBeGreaterThanDescr: 8.0", + "$toBeGreaterThanDescr: 10.0", + { toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) }) + ).toVararg().let { (first, rest) -> + ExpectationCreatorTestData( + oneToSeven().toList().asIterable(), + first as ExpectationCreatorTriple>, + *(rest as Array>>) + ) + }, + + notToContainNullableEntriesSpec.forExpectationCreatorTest( + "$toBeGreaterThanDescr: 8.0", + "$toBeGreaterThanDescr: 10.0", + { toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) }) + ).toVararg().let { (first, rest) -> + ExpectationCreatorTestData( + oneToSeven().toList().asIterable(), + first as ExpectationCreatorTriple>, + *(rest as Array>>), + groupPrefix = "[nullable Element] " + ) + }, + ) + + + + private fun Expect>.notToContainNullableFun( + a: (Expect.() -> Unit)?, + vararg aX: (Expect.() -> Unit)?, + ) = notToContainNullableEntriesSpec(this, a, aX) + + @TestFactory + fun empty_iterable__throws_AssertionError() = + nonNullableCases(notToContainEntriesSpec, notToContainNullableEntriesSpec) { notToContainFunArr -> + fun Expect>.notToContainFun( + a: Expect.() -> Unit, + vararg aX: Expect.() -> Unit, + ) = notToContainFunArr(a, aX) + + expect { + expect(setOf().asIterable()).notToContainFun({ toEqual(4.0) }) + }.toThrow { + message { + toContainRegex( + "$hasANextElement$separator" + + "$indentRootBulletPoint\\Q$explanatoryBulletPoint\\E$notToContainDescr: $separator" + + "$indentRootBulletPoint$indentListBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + + "$indentListBulletPoint$afterExplanatory$toEqualDescr: 4.0.*", + "$hintBulletPoint${ + DescriptionIterableLikeExpectation.USE_NOT_TO_HAVE_ELEMENTS_OR_NONE.getDefault() + .format(notToHaveElementsOrNoneFunName) + }" + ) + } + } + } + + @TestFactory + fun iterable__happy_case() = + nonNullableCases(notToContainEntriesSpec, notToContainNullableEntriesSpec) { notToContainFunArr -> + fun Expect>.notToContainFun( + a: Expect.() -> Unit, + vararg aX: Expect.() -> Unit, + ) = notToContainFunArr(a, aX) + testFactory(notToContainEntriesSpec) { + it("$toBeGreaterThanFun(1.0) and $toBeLessThanFun(2.0) does not throw") { + expect(oneToSeven()).notToContainFun({ toBeGreaterThan(1.0); toBeLessThan(2.0) }) + } + it("$toEqualFun(1.1), $toEqualFun(2.2), $toEqualFun(3.3) does not throw") { + expect(oneToSeven()).notToContainFun({ toEqual(1.1) }, { toEqual(2.2) }, { toEqual(3.3) }) + } + it("$toEqualFun(3.3), $toEqualFun(1.1), $toEqualFun(2.2) does not throw") { + expect(oneToSeven()).notToContainFun({ toEqual(3.3) }, { toEqual(1.1) }, { toEqual(2.2) }) + } + } + expect(oneToSeven()).notToContainFun({ toBeGreaterThan(1.0); toBeLessThan(2.0) }) + } + + @TestFactory + fun iterable__failing_cases_search_string_at_different_positions() { + nonNullableCases(notToContainEntriesSpec, notToContainNullableEntriesSpec) { notToContainFunArr -> + fun Expect>.notToContainFun( + a: Expect.() -> Unit, + vararg aX: Expect.() -> Unit, + ) = notToContainFunArr(a, aX) + + testFactory(notToContainEntriesSpec) { + it("$toBeLessThanFun(4.0) throws AssertionError") { + expect { + expect(oneToSeven()).notToContainFun({ toBeLessThan(4.0) }) + }.toThrow { + message { + toContainRegex( + "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + + "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + + "$afterExplanatory$toBeLessThanDescr: 4.0.*$separator" + + "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + + "$afterMismatchedWarning${mismatchedIndex(0, "1.0")}.*$separator" + + "$afterMismatchedWarning${mismatchedIndex(1, "2.0")}.*$separator" + + "$afterMismatchedWarning${mismatchedIndex(5, "3.0")}.*" + ) + } + } + } + it("$toEqualFun(1.0), $toEqualFun(4.0) throws AssertionError") { + expect { + expect(oneToSeven()).notToContainFun({ toEqual(1.0) }, { toEqual(4.0) }) + }.toThrow { + message { + toContainRegex( + "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + + "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + + "$afterExplanatory$toEqualDescr: 1.0.*$separator" + + "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + + "$afterMismatchedWarning${mismatchedIndex(0, "1.0")}.*$separator" + + "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + + "$afterExplanatory$toEqualDescr: 4.0.*$separator" + + "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + + "$afterMismatchedWarning${mismatchedIndex(2, "4.0")}.*$separator" + + "$afterMismatchedWarning${mismatchedIndex(3, "4.0")}.*$separator" + + "$afterMismatchedWarning${mismatchedIndex(8, "4.0")}.*" + ) + } + } + } + it("$toEqualFun(4.0), $toEqualFun(1.1) throws AssertionError mentioning only 4.0") { + expect { + expect(oneToSeven()).notToContainFun({ toEqual(4.0) }, { toEqual(1.0) }) + }.toThrow { + message { + toContainRegex("$anElementWhichNeedsDescr: $separator.*$toEqualDescr: 4.0") + notToContain.regex("$anElementWhichNeedsDescr: $separator.*$toEqualDescr: 1.1") + } + } + } + } + } + } + + @TestFactory + fun iterable__null_does_not_throw() { + expect(oneToSeven() as Iterable).notToContainNullableFun(null) + } + + @TestFactory + fun iterable__null() { + testFactory(notToContainNullableEntriesSpec) { + it("null throws AssertionError") { + expect { + expect(oneToSevenNullable()).notToContainNullableFun(null) + }.toThrow { + message { + toContainRegex( + "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + + "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + + "$afterExplanatory$toEqualDescr: null$separator" + + "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + + "$afterMismatchedWarning${mismatchedIndex(1, "null")}.*$separator" + + "$afterMismatchedWarning${mismatchedIndex(5, "null")}.*" + ) + } + } + } + it("1.1, null throws AssertionError mentioning only null") { + expect { + expect(oneToSevenNullable()).notToContainNullableFun({ toEqual(1.1) }, null) + }.toThrow { + message { + toContainRegex( + "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + + "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + + "$afterExplanatory$toEqualDescr: null$separator" + + "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + + "$afterMismatchedWarning${index(1)}: null.*$separator" + + "$afterMismatchedWarning${index(5)}: null.*" + ) + this.notToContain("$notToContainDescr: 1.1") + } + } + } + } + } +} diff --git a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/IterableNotToContainEntriesExpectationsSpec.kt b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/IterableNotToContainEntriesExpectationsSpec.kt deleted file mode 100644 index e12fb42ea1..0000000000 --- a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/IterableNotToContainEntriesExpectationsSpec.kt +++ /dev/null @@ -1,194 +0,0 @@ -package ch.tutteli.atrium.specs.integration - -import ch.tutteli.atrium.api.fluent.en_GB.* -import ch.tutteli.atrium.api.verbs.internal.expect -import ch.tutteli.atrium.core.polyfills.format -import ch.tutteli.atrium.creating.Expect -import ch.tutteli.atrium.logic.utils.expectLambda -import ch.tutteli.atrium.specs.* -import ch.tutteli.atrium.translations.DescriptionIterableLikeExpectation - -abstract class IterableNotToContainEntriesExpectationsSpec( - notToContainEntries: Fun2, Expect.() -> Unit, Array.() -> Unit>>, - notToContainNullableEntries: Fun2, (Expect.() -> Unit)?, Array.() -> Unit)?>>, - notToHaveElementsOrNoneFunName: String, - describePrefix: String = "[Atrium] " -) : IterableToContainEntriesSpecBase({ - - include(object : SubjectLessSpec>( - describePrefix, - notToContainEntries.forSubjectLessTest({ toEqual(2.3) }, arrayOf()) - ) {}) - include(object : SubjectLessSpec>( - describePrefix, - notToContainNullableEntries.forSubjectLessTest({ toEqual(2.3) }, arrayOf()) - ) {}) - - include(object : AssertionCreatorSpec>( - describePrefix, oneToSeven().toList().asIterable(), - *notToContainEntries.forExpectationCreatorTest( - "$toBeGreaterThanDescr: 8.0", - "$toBeGreaterThanDescr: 10.0", - { toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) }) - ) - ) {}) - include(object : AssertionCreatorSpec>( - "$describePrefix[nullable Element] ", oneToSeven().toList().asIterable(), - *notToContainNullableEntries.forExpectationCreatorTest( - "$toBeGreaterThanDescr: 8.0", - "$toBeGreaterThanDescr: 10.0", - { toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) }) - ) - ) {}) - - fun Expect>.notToContainNullableFun( - a: (Expect.() -> Unit)?, - vararg aX: (Expect.() -> Unit)? - ) = notToContainNullableEntries(this, a, aX) - - val notToContainDescr = DescriptionIterableLikeExpectation.NOT_TO_CONTAIN.getDefault() - - nonNullableCases( - describePrefix, - notToContainEntries, - notToContainNullableEntries - ) { notToContainFunArr -> - - fun Expect>.notToContainFun( - a: Expect.() -> Unit, - vararg aX: Expect.() -> Unit - ) = notToContainFunArr(a, aX) - - context("empty iterable") { - - it("$toEqualFun(4.0) throws AssertionError") { - expect { - expect(setOf().asIterable()).notToContainFun({ toEqual(4.0) }) - }.toThrow { - message { - toContainRegex( - "$hasANextElement$separator" + - "$indentRootBulletPoint\\Q$explanatoryBulletPoint\\E$notToContainDescr: $separator" + - "$indentRootBulletPoint$indentListBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + - "$indentListBulletPoint$afterExplanatory$toEqualDescr: 4.0.*", - "$hintBulletPoint${DescriptionIterableLikeExpectation.USE_NOT_TO_HAVE_ELEMENTS_OR_NONE.getDefault().format(notToHaveElementsOrNoneFunName)}" - ) - } - } - } - } - - context("iterable ${oneToSeven().toList()}") { - - context("happy case") { - it("$toBeGreaterThanFun(1.0) and $toBeLessThanFun(2.0) does not throw") { - expect(oneToSeven()).notToContainFun({ toBeGreaterThan(1.0); toBeLessThan(2.0) }) - } - it("$toEqualFun(1.1), $toEqualFun(2.2), $toEqualFun(3.3) does not throw") { - expect(oneToSeven()).notToContainFun({ toEqual(1.1) }, { toEqual(2.2) }, { toEqual(3.3) }) - } - it("$toEqualFun(3.3), $toEqualFun(1.1), $toEqualFun(2.2) does not throw") { - expect(oneToSeven()).notToContainFun({ toEqual(3.3) }, { toEqual(1.1) }, { toEqual(2.2) }) - } - } - - context("failing cases; search string at different positions") { - it("$toBeLessThanFun(4.0) throws AssertionError") { - expect { - expect(oneToSeven()).notToContainFun({ toBeLessThan(4.0) }) - }.toThrow { - message { - toContainRegex( - "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + - "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + - "$afterExplanatory$toBeLessThanDescr: 4.0.*$separator" + - "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + - "$afterMismatchedWarning${mismatchedIndex(0, "1.0")}.*$separator" + - "$afterMismatchedWarning${mismatchedIndex(1, "2.0")}.*$separator" + - "$afterMismatchedWarning${mismatchedIndex(5, "3.0")}.*" - ) - } - } - } - it("$toEqualFun(1.0), $toEqualFun(4.0) throws AssertionError") { - expect { - expect(oneToSeven()).notToContainFun({ toEqual(1.0) }, { toEqual(4.0) }) - }.toThrow { - message { - toContainRegex( - "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + - "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + - "$afterExplanatory$toEqualDescr: 1.0.*$separator" + - "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + - "$afterMismatchedWarning${mismatchedIndex(0, "1.0")}.*$separator" + - "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + - "$afterExplanatory$toEqualDescr: 4.0.*$separator" + - "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + - "$afterMismatchedWarning${mismatchedIndex(2, "4.0")}.*$separator" + - "$afterMismatchedWarning${mismatchedIndex(3, "4.0")}.*$separator" + - "$afterMismatchedWarning${mismatchedIndex(8, "4.0")}.*" - ) - } - } - } - it("$toEqualFun(4.0), $toEqualFun(1.1) throws AssertionError mentioning only 4.0") { - expect { - expect(oneToSeven()).notToContainFun({ toEqual(4.0) }, { toEqual(1.0) }) - }.toThrow { - message { - toContainRegex("$anElementWhichNeedsDescr: $separator.*$toEqualDescr: 4.0") - notToContain.regex("$anElementWhichNeedsDescr: $separator.*$toEqualDescr: 1.1") - } - } - } - } - - } - } - - nullableCases(describePrefix) { - describeFun(notToContainNullableEntries) { - context("iterable ${oneToSeven().toList()}") { - it("null does not throw") { - expect(oneToSeven() as Iterable).notToContainNullableFun(null) - } - } - context("iterable ${oneToSevenNullable().toList()}") { - it("null throws AssertionError") { - expect { - expect(oneToSevenNullable()).notToContainNullableFun(null) - }.toThrow { - message { - toContainRegex( - "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + - "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + - "$afterExplanatory$toEqualDescr: null$separator" + - "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + - "$afterMismatchedWarning${mismatchedIndex(1, "null")}.*$separator" + - "$afterMismatchedWarning${mismatchedIndex(5, "null")}.*" - ) - } - } - } - - it("1.1, null throws AssertionError mentioning only null") { - expect { - expect(oneToSevenNullable()).notToContainNullableFun({ toEqual(1.1) }, null) - }.toThrow { - message { - toContainRegex( - "\\Q$rootBulletPoint\\E$notToContainDescr: $separator" + - "$indentRootBulletPoint\\Q$listBulletPoint\\E$anElementWhichNeedsDescr: $separator" + - "$afterExplanatory$toEqualDescr: null$separator" + - "$afterExplanatoryIndent\\Q$warningBulletPoint$mismatches:\\E $separator" + - "$afterMismatchedWarning${index(1)}: null.*$separator" + - "$afterMismatchedWarning${index(5)}: null.*" - ) - this.notToContain("$notToContainDescr: 1.1") - } - } - } - } - } - } -})