diff --git a/atrium-core/src/commonMain/kotlin/ch/tutteli/atrium/reporting/reportables/descriptions/DescriptionCharSequenceProof.kt b/atrium-core/src/commonMain/kotlin/ch/tutteli/atrium/reporting/reportables/descriptions/DescriptionCharSequenceProof.kt index ac5f7d725d..e47d99c272 100644 --- a/atrium-core/src/commonMain/kotlin/ch/tutteli/atrium/reporting/reportables/descriptions/DescriptionCharSequenceProof.kt +++ b/atrium-core/src/commonMain/kotlin/ch/tutteli/atrium/reporting/reportables/descriptions/DescriptionCharSequenceProof.kt @@ -21,6 +21,7 @@ enum class DescriptionCharSequenceProof(override val string: String) : Descripti /** @since 1.3.0 (but was since 0.18.0 in atrium-translations DescriptionCharSequenceExpectation) */ EXACTLY("is exactly"), + //TODO 1.3.0 think about if you want to support placeholders like that /** @since 1.3.0 (but was since 0.18.0 in atrium-translations DescriptionCharSequenceExpectation) */ IGNORING_CASE("%s, ignoring case"), diff --git a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt index f2e85060d4..434a30e81a 100644 --- a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt +++ b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt @@ -652,7 +652,7 @@ abstract class AnyExpectationsSpec( expect(null as Int?).notToEqualNullFun { toEqual(1) } }.toThrow { message { - toContainDescr(notToEqualNullButToBeInstanceOfDescr, "In2t (kotlin.Int)") + toContainDescr(notToEqualNullButToBeInstanceOfDescr, "Int (kotlin.Int)") if (hasExtraHint) toContainToEqualDescr(1) } diff --git a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/CharSequenceNotToContainExpectationsSpec.kt b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/CharSequenceNotToContainExpectationsSpec.kt index b305e6e970..685bcf6e26 100644 --- a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/CharSequenceNotToContainExpectationsSpec.kt +++ b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/CharSequenceNotToContainExpectationsSpec.kt @@ -2,12 +2,11 @@ package ch.tutteli.atrium.specs.integration import ch.tutteli.atrium.api.fluent.en_GB.message import ch.tutteli.atrium.api.fluent.en_GB.messageToContain +import ch.tutteli.atrium.api.fluent.en_GB.notToContain 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.reporting.Text -import ch.tutteli.atrium.reporting.reportables.Description import ch.tutteli.atrium.reporting.reportables.descriptions.DescriptionCharSequenceProof import ch.tutteli.atrium.specs.* import org.spekframework.spek2.style.specification.Suite @@ -18,21 +17,22 @@ abstract class CharSequenceNotToContainExpectationsSpec( describePrefix: String = "[Atrium] " ) : CharSequenceToContainSpecBase({ - val notToContain = notToContainPair.second - val notToContainIgnoringCase = notToContainIgnoringCasePair.second + val notToContainFunArr = notToContainPair.second + val notToContainIgnoringCaseFunArr = notToContainIgnoringCasePair.second include(object : SubjectLessSpec( describePrefix, - notToContain.forSubjectLess(2.3, arrayOf()), - notToContainIgnoringCase.forSubjectLess(2.3, arrayOf()) + notToContainFunArr.forSubjectLess(2.3, arrayOf()), + notToContainIgnoringCaseFunArr.forSubjectLess(2.3, arrayOf()) ) {}) fun describeFun(vararg funName: String, body: Suite.() -> Unit) = describeFunTemplate(describePrefix, funName, body = body) - fun Expect.notToContainFun(a: Any, vararg aX: Any) = notToContain(this, a, aX) + fun Expect.notToContainFun(a: Any, vararg aX: Any) = notToContainFunArr(this, a, aX) - fun Expect.notToContainIgnoringCaseFun(a: Any, vararg aX: Any) = notToContainIgnoringCase(this, a, aX) + fun Expect.notToContainIgnoringCaseFun(a: Any, vararg aX: Any) = + notToContainIgnoringCaseFunArr(this, a, aX) val notToContainDescr = DescriptionCharSequenceProof.NOT_TO_CONTAIN.string val notToContainIgnoringCaseDescr = @@ -47,7 +47,7 @@ abstract class CharSequenceNotToContainExpectationsSpec( toContainDescr(DescriptionCharSequenceProof.NUMBER_OF_MATCHES, representation) - describeFun(notToContain.name, notToContainIgnoringCase.name) { + describeFun(notToContainFunArr.name, notToContainIgnoringCaseFunArr.name) { context("throws an $illegalArgumentException") { @@ -74,7 +74,7 @@ abstract class CharSequenceNotToContainExpectationsSpec( } context("text '$helloWorld'") { - context("happy case with $notToContain once") { + context("happy case with $notToContainFunArr once") { it("${notToContainPair.first("'h'")} does not throw") { expect(helloWorld).notToContainFun('h') } @@ -90,33 +90,54 @@ abstract class CharSequenceNotToContainExpectationsSpec( } context("failing cases; search string at different positions") { - it("${notToContainPair.first("'l'")} throws AssertionError") { + it("${notToContainPair.first("'l', 'A'")} throws AssertionError") { expect { expect(helloWorld).notToContainFun('l') }.toThrow { message { - toContainSubject(helloWorld) - toContainDescr(DescriptionCharSequenceProof.NOT_TO_CONTAIN, Text.EMPTY) - toContainValue('l') + toContainSubject("\"$helloWorld\"") + toContainDescr(DescriptionCharSequenceProof.NOT_TO_CONTAIN, "") + toContainValue("'l'") toContainNumberOfMatches(3) toContainToEqualDescr(0) + notToContain("'A'") } } } it("${notToContainPair.first("'H', 'l'")} throws AssertionError") { expect { expect(helloWorld).notToContainFun('H', 'l') - }.toThrow { messageToContain("$valueWithIndent: 'l'") } + }.toThrow { + message { + toContainValue("'H'") + toContainValue("'l'") + } + } } it("${notToContainPair.first("'l', 'H'")} once throws AssertionError") { expect { expect(helloWorld).notToContainFun('l', 'H') - }.toThrow { messageToContain("$valueWithIndent: 'l'") } + }.toThrow { + message { + toContainValue("'H'") + toContainValue("'l'") + } + } } it("${notToContainIgnoringCasePair.first("'H', 'l'")} throws AssertionError") { expect { expect(helloWorld).notToContainIgnoringCaseFun('H', 'l') }.toThrow { + message { + toContainSubject("\"$helloWorld\"") + toContainDescr(DescriptionCharSequenceProof.NOT_TO_CONTAIN, "") + toContainValue("'l'") + toContainNumberOfMatches(3) + toContainToEqualDescr(0) + notToContain("'A'") + toContainValue("'H'") + toContainValue("'l'") + } messageToContain( "$rootBulletPoint$notToContainIgnoringCaseDescr: $separator" + "$valueWithIndent: 'H'", diff --git a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/stringTestExpectations.kt b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/stringTestExpectations.kt index 54e9cb699a..7fbab919ea 100644 --- a/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/stringTestExpectations.kt +++ b/misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/stringTestExpectations.kt @@ -30,3 +30,6 @@ fun Expect.toContainDescr(description: Description, representation: Any? fun Expect.toContainDescr(description: String, representation: Any?) = toContain.exactly(1).matchFor(Regex("\\Q$description\\E\\s+: \\Q$representation\\E")) +fun Expect.notToContainDescr(description: String, representation: Any?) = + toContain.exactly(1).matchFor(Regex("\\Q$description\\E\\s+: \\Q$representation\\E")) +