From 880ccb2f9e673abcab850794ea7ffa71bf885ff7 Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Mon, 21 Dec 2020 14:38:36 +0100 Subject: [PATCH] fix indentation for explanatory assertion group with info bullet-point --- .../api/fluent/en_GB/AnyAssertionsSpec.kt | 13 ++-- .../api/infix/en_GB/AnyAssertionsSpec.kt | 3 +- .../en_GB/samples/AnyAssertionSamples.kt | 2 +- .../AssertionFormatterParameterObject.kt | 23 +++++-- .../TextExplanatoryAssertionGroupFormatter.kt | 14 +++-- .../atrium/logic/impl/DefaultAnyAssertions.kt | 10 +-- .../specs/integration/AnyAssertionsSpec.kt | 24 ++++++-- .../reporting/AssertionFormatterSpecBase.kt | 1 + ...tExplanatoryAssertionGroupFormatterSpec.kt | 3 +- ...anatoryBasedAssertionGroupFormatterSpec.kt | 8 ++- ...tIndentBasedAssertionGroupFormatterSpec.kt | 61 +++++++++++-------- ...tInformationAssertionGroupFormatterSpec.kt | 3 +- 12 files changed, 110 insertions(+), 55 deletions(-) diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyAssertionsSpec.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyAssertionsSpec.kt index 47736fc97..dde613fed 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyAssertionsSpec.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyAssertionsSpec.kt @@ -36,7 +36,6 @@ class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec( fun1(Expect::isNotIn).withNullableSuffix(), fun2(Expect::because), fun2(Expect::because), - "ℹ ", "${Expect::toBe.name}(null)" to Companion::toBeNull, fun1(Expect::toBeNullIfNullGivenElse), @@ -52,7 +51,7 @@ class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec( getAndImmediatePair(), getAndLazyPair(), - "⚬ " + "◆ ", "⚬ ", "ℹ " ) { companion object { @@ -71,7 +70,10 @@ class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec( expect.isA() @Suppress("RemoveExplicitTypeArguments") - private fun isASuperType(expect: Expect, assertionCreator: Expect.() -> Unit): Expect = + private fun isASuperType( + expect: Expect, + assertionCreator: Expect.() -> Unit + ): Expect = expect.isA { assertionCreator() } @Suppress("RemoveExplicitTypeArguments") @@ -79,7 +81,10 @@ class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec( expect.isA() @Suppress("RemoveExplicitTypeArguments") - private fun isASubType(expect: Expect, assertionCreator: Expect.() -> Unit): Expect = + private fun isASubType( + expect: Expect, + assertionCreator: Expect.() -> Unit + ): Expect = expect.isA { assertionCreator() } private val andImmediate: KProperty1, Expect> = Expect::and diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/AnyAssertionsSpec.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/AnyAssertionsSpec.kt index 522eaba72..4d3862e93 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/AnyAssertionsSpec.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/AnyAssertionsSpec.kt @@ -36,7 +36,6 @@ class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec( fun1(Expect::isNotIn).withNullableSuffix(), fun2.() -> Unit>(Companion::because), fun2.() -> Unit>(Companion::becauseOfInt), - "(i) ", "${Expect::toBe.name}(null)" to Companion::toBeNull, fun1(Expect::toBeNullIfNullGivenElse), @@ -52,7 +51,7 @@ class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec( getAndImmediatePair(), getAndLazyPair(), - "- " + "* ", "- ","(i) " ) { companion object : WithAsciiReporter() { diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/AnyAssertionSamples.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/AnyAssertionSamples.kt index f1f00d144..a46fae066 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/AnyAssertionSamples.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/AnyAssertionSamples.kt @@ -1,6 +1,6 @@ package ch.tutteli.atrium.api.infix.en_GB.samples -import ch.tutteli.atrium.api.fluent.en_GB.toBe +import ch.tutteli.atrium.api.infix.en_GB.toBe import ch.tutteli.atrium.api.infix.en_GB.* import ch.tutteli.atrium.api.verbs.internal.expect import kotlin.test.Test diff --git a/core/api/atrium-core-api-common/src/main/kotlin/ch/tutteli/atrium/reporting/AssertionFormatterParameterObject.kt b/core/api/atrium-core-api-common/src/main/kotlin/ch/tutteli/atrium/reporting/AssertionFormatterParameterObject.kt index 27fb47989..c0f2de386 100644 --- a/core/api/atrium-core-api-common/src/main/kotlin/ch/tutteli/atrium/reporting/AssertionFormatterParameterObject.kt +++ b/core/api/atrium-core-api-common/src/main/kotlin/ch/tutteli/atrium/reporting/AssertionFormatterParameterObject.kt @@ -40,7 +40,8 @@ class AssertionFormatterParameterObject private constructor( * * @return The newly created [AssertionFormatterParameterObject]. */ - fun createChildWithNewPrefix(newPrefix: String) = createChildWithNewPrefixAndAdditionalIndent(newPrefix, 0) + fun createChildWithNewPrefix(newPrefix: String) = + createChildWithNewPrefixAndAdditionalIndent(newPrefix, additionalIndent = 0) /** @@ -75,7 +76,14 @@ class AssertionFormatterParameterObject private constructor( * @return The newly created [AssertionFormatterParameterObject]. */ fun createForDoNotFilterAssertionGroup(): AssertionFormatterParameterObject = - AssertionFormatterParameterObject(sb, prefix, indentLevel, assertionFilter, numberOfDoNotFilterGroups + 1, numberOfExplanatoryGroups) + AssertionFormatterParameterObject( + sb, + prefix, + indentLevel, + assertionFilter, + numberOfDoNotFilterGroups + 1, + numberOfExplanatoryGroups + ) /** @@ -85,8 +93,15 @@ class AssertionFormatterParameterObject private constructor( * * @return The newly created [AssertionFormatterParameterObject]. */ - fun createForExplanatoryFilterAssertionGroup(): AssertionFormatterParameterObject = - AssertionFormatterParameterObject(sb, prefix, indentLevel, assertionFilter, numberOfDoNotFilterGroups + 1, numberOfExplanatoryGroups + 1) + fun createForExplanatoryFilterAssertionGroup(newPrefix : String = prefix): AssertionFormatterParameterObject = + AssertionFormatterParameterObject( + sb, + newPrefix, + indentLevel, + assertionFilter, + numberOfDoNotFilterGroups + 1, + numberOfExplanatoryGroups + 1 + ) /** diff --git a/core/robstoll-lib/atrium-core-robstoll-lib-common/src/main/kotlin/ch/tutteli/atrium/core/robstoll/lib/reporting/TextExplanatoryAssertionGroupFormatter.kt b/core/robstoll-lib/atrium-core-robstoll-lib-common/src/main/kotlin/ch/tutteli/atrium/core/robstoll/lib/reporting/TextExplanatoryAssertionGroupFormatter.kt index e9ef6d7cb..2abc99039 100644 --- a/core/robstoll-lib/atrium-core-robstoll-lib-common/src/main/kotlin/ch/tutteli/atrium/core/robstoll/lib/reporting/TextExplanatoryAssertionGroupFormatter.kt +++ b/core/robstoll-lib/atrium-core-robstoll-lib-common/src/main/kotlin/ch/tutteli/atrium/core/robstoll/lib/reporting/TextExplanatoryAssertionGroupFormatter.kt @@ -45,11 +45,15 @@ class TextExplanatoryAssertionGroupFormatter( assertionGroup: AssertionGroup, parameterObject: AssertionFormatterParameterObject ): AssertionFormatterParameterObject { - val bulletPoint = when (assertionGroup.type) { - WarningAssertionGroupType -> warningBulletPoint - InformationAssertionGroupType -> informationBulletPoint - else -> explanatoryBulletPoint + // we don't indent in case of an InformationAssertionGroupType + return if (assertionGroup.type == InformationAssertionGroupType) { + parameterObject.createForExplanatoryFilterAssertionGroup(informationBulletPoint) + } else { + val bulletPoint = when (assertionGroup.type) { + WarningAssertionGroupType -> warningBulletPoint + else -> explanatoryBulletPoint + } + parameterObject.createForExplanatoryFilterAssertionGroup().createChildWithNewPrefix(bulletPoint) } - return parameterObject.createForExplanatoryFilterAssertionGroup().createChildWithNewPrefix(bulletPoint) } } diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/DefaultAnyAssertions.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/DefaultAnyAssertions.kt index 845e90c5a..c241cfefc 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/DefaultAnyAssertions.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/DefaultAnyAssertions.kt @@ -36,13 +36,13 @@ class DefaultAnyAssertions : AnyAssertions { reason: String, assertionCreator: Expect.() -> Unit ): Assertion { + val assertion = assertionCollector.collect(container.maybeSubject, assertionCreator) return assertionBuilder.invisibleGroup.withAssertions( - assertionCollector.collect(container.maybeSubject, assertionCreator), - ExplanatoryGroup - .GroupTypeOption - .create() + assertion, + assertionBuilder.explanatoryGroup .withInformationType - .withExplanatoryAssertion(TranslatableWithArgs(BECAUSE, reason)).build() + .withExplanatoryAssertion(TranslatableWithArgs(BECAUSE, reason)) + .build() ).build() } diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyAssertionsSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyAssertionsSpec.kt index bea440152..89382a9e6 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyAssertionsSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyAssertionsSpec.kt @@ -3,10 +3,12 @@ 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.assertions.DescriptiveAssertion +import ch.tutteli.atrium.core.polyfills.format import ch.tutteli.atrium.core.polyfills.fullName import ch.tutteli.atrium.creating.Expect import ch.tutteli.atrium.reporting.Text import ch.tutteli.atrium.specs.* +import ch.tutteli.atrium.specs.integration.MapLikeContainsSpecBase.Companion.separator import ch.tutteli.atrium.translations.DescriptionAnyAssertion.* import ch.tutteli.atrium.translations.DescriptionAnyAssertion.NOT_TO_BE import ch.tutteli.atrium.translations.DescriptionAnyAssertion.TO_BE @@ -42,7 +44,6 @@ abstract class AnyAssertionsSpec( isNotInNullableDataClass: Fun1>, because: Fun2.() -> Unit>, becauseInt: Fun2.() -> Unit>, - informationBulletPoint: String, toBeNull: Fun0, toBeNullIfNullGivenElse: Fun1.() -> Unit)?>, @@ -60,7 +61,10 @@ abstract class AnyAssertionsSpec( andPair: Fun0, andLazyPair: Fun1.() -> Unit>, + + rootBulletPoint: String, listBulletPoint: String, + informationBulletPoint: String, describePrefix: String = "[Atrium] " ) : Spek({ @@ -117,6 +121,8 @@ abstract class AnyAssertionsSpec( fun describeFun(vararg pairs: SpecPair<*>, body: Suite.() -> Unit) = describeFunTemplate(describePrefix, pairs.map { it.name }.toTypedArray(), body = body) + val indentBulletPoint = " ".repeat(rootBulletPoint.length) + fun Suite.checkInt( description: String, expectSubject: Expect, @@ -177,7 +183,10 @@ abstract class AnyAssertionsSpec( expectSubject.isNoneOfFun(1, arrayOf(2)) }.toThrow { message { - contains(IS_NONE_OF.getDefault(), "${listBulletPoint}1") + containsRegex( + "\\Q$rootBulletPoint${IS_NONE_OF.getDefault()}\\E:.*$separator" + + "$indentBulletPoint${listBulletPoint}1" + ) containsNot("$listBulletPoint 2") } } @@ -751,6 +760,9 @@ abstract class AnyAssertionsSpec( val becauseFun = because.lambda val becauseFunForInt = becauseInt.lambda + fun Expect.containsBecause(reason: String) = + contains.exactly(1).value("$separator${informationBulletPoint}${BECAUSE.getDefault().format(reason)}") + it("the test on the supplied subject is not throwing an assertion error") { expect("filename") .becauseFun("? is not allowed in file names on Windows") { @@ -766,7 +778,9 @@ abstract class AnyAssertionsSpec( startsWith("f") } }.toThrow { - messageContains("${informationBulletPoint}${String.format(BECAUSE.getDefault(), "? is not allowed in file names on Windows")}") + message { + containsBecause("? is not allowed in file names on Windows") + } } } @@ -779,7 +793,9 @@ abstract class AnyAssertionsSpec( isNoneOf(21) } }.toThrow { - messageContains("${informationBulletPoint}${String.format(BECAUSE.getDefault(), "we use the definition that teens are between 12 and 18 years old")}") + message { + containsBecause( "we use the definition that teens are between 12 and 18 years old") + } } } } diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/AssertionFormatterSpecBase.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/AssertionFormatterSpecBase.kt index c1824d899..ced5cdf48 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/AssertionFormatterSpecBase.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/AssertionFormatterSpecBase.kt @@ -43,6 +43,7 @@ abstract class AssertionFormatterSpecBase(spec: Root.() -> Unit) : Spek({ fun createFacade() = coreFactory.newAssertionFormatterFacade(coreFactory.newAssertionFormatterController()) + //TODO remove with 1.0.0 fun createFacade(testeeFactory: (Map, String>, AssertionFormatterController, ObjectFormatter, Translator) -> AssertionFormatter): AssertionFormatterFacade = createFacade(mapOf(), testeeFactory) diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryAssertionGroupFormatterSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryAssertionGroupFormatterSpec.kt index 8dd151dcf..45be4fc10 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryAssertionGroupFormatterSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryAssertionGroupFormatterSpec.kt @@ -15,4 +15,5 @@ abstract class TextExplanatoryAssertionGroupFormatterSpec( ExplanatoryAssertionGroupType::class, object : ExplanatoryAssertionGroupType {}, { assertionBuilder.explanatoryGroup.withDefaultType.withAssertions(it).build() }, - describePrefix) + describePrefix +) diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryBasedAssertionGroupFormatterSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryBasedAssertionGroupFormatterSpec.kt index ed0fb433e..681b4bdef 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryBasedAssertionGroupFormatterSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextExplanatoryBasedAssertionGroupFormatterSpec.kt @@ -14,15 +14,17 @@ abstract class TextExplanatoryBasedAssertionGroupFormatterSpec, anonymousAssertionGroupType: T, groupFactory: (List) -> AssertionGroup, - describePrefix: String = "[Atrium] " + describePrefix: String = "[Atrium] ", + withIndent: Boolean = true ) : Spek({ - @Suppress("DEPRECATION" /* TODO remove with 1.0.0 */) + @Suppress("DEPRECATION" /* TODO inline TextIndentBasedAssertionGroupFormatterSpec with 1.0.0 */) include(object : TextIndentBasedAssertionGroupFormatterSpec( testeeFactory, assertionGroupTypeClass, anonymousAssertionGroupType, groupFactory, - describePrefix + describePrefix, + withIndent ) {}) }) diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextIndentBasedAssertionGroupFormatterSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextIndentBasedAssertionGroupFormatterSpec.kt index fe780127d..ab4693c18 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextIndentBasedAssertionGroupFormatterSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/reporting/TextIndentBasedAssertionGroupFormatterSpec.kt @@ -1,5 +1,6 @@ package ch.tutteli.atrium.specs.reporting +import ch.tutteli.atrium.api.fluent.en_GB.feature import ch.tutteli.atrium.api.fluent.en_GB.toBe import ch.tutteli.atrium.api.verbs.internal.expect import ch.tutteli.atrium.assertions.* @@ -19,7 +20,8 @@ abstract class TextIndentBasedAssertionGroupFormatterSpec, anonymousAssertionGroupType: T, groupFactory: (List) -> AssertionGroup, - describePrefix: String = "[Atrium] " + describePrefix: String = "[Atrium] ", + withIndent: Boolean = true ) : AssertionFormatterSpecBase({ fun describeFun(vararg funName: String, body: Suite.() -> Unit) = @@ -28,21 +30,21 @@ abstract class TextIndentBasedAssertionGroupFormatterSpec - testeeFactory(bulletPoints, controller) - } + val facade = createFacade(assertionGroupTypeClass to "$indentBulletPoint ") { bulletPoints, controller, _, _ -> + testeeFactory(bulletPoints, controller) + } describeFun(AssertionFormatter::canFormat.name) { val testee = testeeFactory(bulletPoints, coreFactory.newAssertionFormatterController()) it("returns true for an ${AssertionGroup::class.simpleName} with type object: ${assertionGroupTypeClass.simpleName}") { - val result = testee.canFormat( - assertionBuilder.customType(anonymousAssertionGroupType) - .withDescriptionAndRepresentation(Untranslatable.EMPTY, 1) - .withAssertions(listOf()) - .build() - ) - expect(result).toBe(true) + expect(testee).feature { + f( + it::canFormat, assertionBuilder.customType(anonymousAssertionGroupType) + .withDescriptionAndRepresentation(Untranslatable.EMPTY, 1) + .withAssertions(listOf()) + .build() + ) + }.toBe(true) } } @@ -61,7 +63,7 @@ abstract class TextIndentBasedAssertionGroupFormatterSpec