rename appendAssertion/CreatedBy to append and appendAsGroup

This way we can use it also on ProofContainer and users won't notice
anything as long as they recompile
This commit is contained in:
Robert Stoll
2021-05-29 20:53:00 +02:00
parent ac0424c1bc
commit f67cd01e38
48 changed files with 125 additions and 128 deletions

View File

@@ -33,6 +33,7 @@ interface AssertionContainer<T> : @kotlin.Suppress("DEPRECATION") SubjectProvide
* Might be we completely remove it without prior notice.
*/
//TODO 0.18.0/0.19.0 maybe it would be better to have proofFactories as val like we have components?
//TODO 0.18.0 I guess it would make sense to get rid of getImpl and only use the ComponentFactoryContainer approach
@ExperimentalNewExpectTypes
fun <I : Any> getImpl(kClass: KClass<I>, defaultFactory: () -> I): I
@@ -55,8 +56,7 @@ interface AssertionContainer<T> : @kotlin.Suppress("DEPRECATION") SubjectProvide
*
* @throws AssertionError Might throw an [AssertionError] in case [Assertion]s are immediately evaluated.
*/
//TODO 0.17.0 rename to append - this way we can use it also on ProofContainer and users won't notice anything as long as they recompile
fun appendAssertion(assertion: Assertion): Expect<T>
fun append(assertion: Assertion): Expect<T>
/**
* Appends the [Assertion]s the given [assertionCreator] creates to this container and
@@ -72,12 +72,11 @@ interface AssertionContainer<T> : @kotlin.Suppress("DEPRECATION") SubjectProvide
*
* @throws AssertionError Might throw an [AssertionError] in case [Assertion]s are immediately evaluated.
*/
//TODO 0.17.0 rename to append - this way we can use it also on ProofContainer and users won't notice anything as long as they recompile
fun appendAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): Expect<T>
fun appendAsGroup(assertionCreator: Expect<T>.() -> Unit): Expect<T>
/**
* Creates a [DescriptiveAssertion] based on the given [description], [expected] and [test]
* and [appends][appendAssertion] it to the container.
* and [append]s it to the container.
*
* @param description The description of the assertion, e.g., `is less than`.
* @param expected The expected value, e.g., `5`
@@ -86,8 +85,7 @@ interface AssertionContainer<T> : @kotlin.Suppress("DEPRECATION") SubjectProvide
* @return an [Expect] for the subject of `this` expectation.
*/
//TODO remove SUPPRESS with 0.18.0
//TODO 0.17.0 rename to append - this way we can use it also on ProofContainer and users won't notice anything as long as they recompile
@Suppress("UNCHECKED_CAST", "DEPRECATION")
fun createAndAppendAssertion(description: String, expected: Any?, test: (T) -> Boolean): Expect<T> =
appendAssertion(assertionBuilder.createDescriptive(this as Expect<T>, Untranslatable(description),expected, test))
fun createAndAppend(description: String, expected: Any?, test: (T) -> Boolean): Expect<T> =
append(assertionBuilder.createDescriptive(this as Expect<T>, Untranslatable(description),expected, test))
}

View File

@@ -22,8 +22,8 @@ interface CollectingExpect<T> : Expect<T> {
fun getAssertions(): List<Assertion>
@Deprecated(
"use appendAssertionsCreatedBy; will be removed with 0.18.0",
ReplaceWith("this.appendAssertionsCreatedBy(assertionCreator)")
"use appendAsGroup; will be removed with 0.18.0",
ReplaceWith("this.appendAsGroup(assertionCreator)")
)
override fun addAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): CollectingExpect<T>
@@ -41,7 +41,7 @@ interface CollectingExpect<T> : Expect<T> {
*
* @throws AssertionError Might throw an [AssertionError] in case [Assertion]s are immediately evaluated.
*/
fun appendAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): CollectingExpect<T>
fun appendAsGroup(assertionCreator: Expect<T>.() -> Unit): CollectingExpect<T>
companion object {
@Suppress(

View File

@@ -63,8 +63,8 @@ interface Expect<T> : @kotlin.Suppress("DEPRECATION") SubjectProvider<T> {
* @return an [Expect] for the subject of `this` expectation.
*/
@Deprecated(
"use _logic.appendAssertionsCreatedBy; will be removed with 0.18.0",
ReplaceWith("this._logic.appendAssertionsCreatedBy(assertionCreator)", "ch.tutteli.atrium.logic._logic")
"use _logic.appendAsGroup; will be removed with 0.18.0",
ReplaceWith("this._logic.appendAsGroup(assertionCreator)", "ch.tutteli.atrium.logic._logic")
)
fun addAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): Expect<T>
@@ -76,8 +76,8 @@ interface Expect<T> : @kotlin.Suppress("DEPRECATION") SubjectProvider<T> {
* @return an [Expect] for the subject of `this` expectation.
*/
@Deprecated(
"use _logic.appendAssertion; will be removed with 0.18.0",
ReplaceWith("this._logic.appendAssertion(assertion)", "ch.tutteli.atrium.logic._logic")
"use _logic.append; will be removed with 0.18.0",
ReplaceWith("this._logic.append(assertion)", "ch.tutteli.atrium.logic._logic")
)
override fun addAssertion(assertion: Assertion): Expect<T>
@@ -92,9 +92,9 @@ interface Expect<T> : @kotlin.Suppress("DEPRECATION") SubjectProvider<T> {
* @return an [Expect] for the subject of `this` expectation.
*/
@Deprecated(
"use _logic.createAndAppendAssertion; will be removed with 0.18.0",
"use _logic.createAndAppend; will be removed with 0.18.0",
ReplaceWith(
"this._logic.createAndAppendAssertion(description, expected, test)",
"this._logic.createAndAppend(description, expected, test)",
"ch.tutteli.atrium.logic._logic"
)
)
@@ -112,9 +112,9 @@ interface Expect<T> : @kotlin.Suppress("DEPRECATION") SubjectProvider<T> {
* @return an [Expect] for the subject of `this` expectation.
*/
@Deprecated(
"use _logic.createAndAppendAssertion; will be removed with 0.18.0",
"use _logic.createAndAppend; will be removed with 0.18.0",
ReplaceWith(
"this._logic.appendAssertion(this._logic.createDescriptiveAssertion(description, expected, test))",
"this._logic.append(this._logic.createDescriptiveAssertion(description, expected, test))",
"ch.tutteli.atrium.logic._logic",
"ch.tutteli.atrium.logic.createDescriptiveAssertion"
)

View File

@@ -43,21 +43,21 @@ abstract class BaseExpectImpl<T>(
//TODO remove with 0.18.0
override fun addAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): Expect<T> =
appendAssertionsCreatedBy(assertionCreator)
appendAsGroup(assertionCreator)
override fun appendAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): Expect<T> {
override fun appendAsGroup(assertionCreator: Expect<T>.() -> Unit): Expect<T> {
val assertions = CollectingExpect(maybeSubject, components)
.appendAssertionsCreatedBy(assertionCreator)
.appendAsGroup(assertionCreator)
.getAssertions()
return addAssertions(assertions)
return appendAsGroup(assertions)
}
protected fun addAssertions(assertions: List<Assertion>): Expect<T> {
protected fun appendAsGroup(assertions: List<Assertion>): Expect<T> {
return when (assertions.size) {
0 -> this
1 -> appendAssertion(assertions.first())
else -> appendAssertion(assertionBuilder.invisibleGroup.withAssertions(assertions).build())
1 -> append(assertions.first())
else -> append(assertionBuilder.invisibleGroup.withAssertions(assertions).build())
}
}

View File

@@ -16,15 +16,15 @@ internal class CollectingExpectImpl<T>(
override fun getAssertions(): List<Assertion> = assertions.toList()
override fun addAssertion(assertion: Assertion): Expect<T> = appendAssertion(assertion)
override fun addAssertion(assertion: Assertion): Expect<T> = append(assertion)
override fun appendAssertion(assertion: Assertion): Expect<T> =
override fun append(assertion: Assertion): Expect<T> =
apply { assertions.add(assertion) }
override fun addAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): CollectingExpect<T> =
appendAssertionsCreatedBy(assertionCreator)
appendAsGroup(assertionCreator)
override fun appendAssertionsCreatedBy(assertionCreator: Expect<T>.() -> Unit): CollectingExpect<T> {
override fun appendAsGroup(assertionCreator: Expect<T>.() -> Unit): CollectingExpect<T> {
// in case we run into performance problems, the code below is certainly not ideal
val allAssertions = mutableListOf<Assertion>()
allAssertions.addAll(getAssertions())
@@ -56,7 +56,7 @@ internal class CollectingExpectImpl<T>(
.build()
)
}
allAssertions.forEach { appendAssertion(it) }
allAssertions.forEach { append(it) }
return this
}

View File

@@ -14,8 +14,8 @@ internal class DelegatingExpectImpl<T>(private val container: AssertionContainer
get() = container.components
override fun addAssertion(assertion: Assertion): Expect<T> =
appendAssertion(assertion)
append(assertion)
override fun appendAssertion(assertion: Assertion): Expect<T> =
override fun append(assertion: Assertion): Expect<T> =
apply { container.addAssertion(assertion) }
}

View File

@@ -49,7 +49,7 @@ internal class FeatureExpectImpl<T, R>(
private val assertions: MutableList<Assertion> = mutableListOf()
init {
addAssertions(assertions)
appendAsGroup(assertions)
}
override val components: ComponentFactoryContainer
@@ -58,9 +58,9 @@ internal class FeatureExpectImpl<T, R>(
override fun addAssertion(assertion: Assertion): Expect<R> =
appendAssertion(assertion)
append(assertion)
override fun appendAssertion(assertion: Assertion): Expect<R> {
override fun append(assertion: Assertion): Expect<R> {
assertions.add(assertion)
//Would be nice if we don't have to add it immediately to the previousExpect but only:
//if (!assertion.holds()) {
@@ -76,7 +76,7 @@ internal class FeatureExpectImpl<T, R>(
//
//However, for this to work we would need to know when no more assertion is defined. This would be possible
//for CollectingExpectImpl
(previousExpect as AssertionContainer<*>).appendAssertion(
(previousExpect as AssertionContainer<*>).append(
assertionBuilder.feature
.withDescriptionAndRepresentation(description, representation)
.withAssertions(ArrayList(assertions))

View File

@@ -55,9 +55,9 @@ internal class RootExpectImpl<T>(
private val assertions: MutableList<Assertion> = mutableListOf()
override fun addAssertion(assertion: Assertion): Expect<T> =
appendAssertion(assertion)
append(assertion)
override fun appendAssertion(assertion: Assertion): Expect<T> {
override fun append(assertion: Assertion): Expect<T> {
assertions.add(assertion)
if (!assertion.holds()) {
val assertionGroup = assertionBuilder.root

View File

@@ -11,7 +11,7 @@ import org.spekframework.spek2.Spek
class DescriptiveWithBasedOnSubjectSpec : Spek({
fun addDescriptive(f: (Expect<Int>, Descriptive.HoldsOption) -> Assertion) = expectLambda<Int> {
_logic.appendAssertion(f(this, assertionBuilder.descriptive))
_logic.append(f(this, assertionBuilder.descriptive))
}
include(object : SubjectLessSpec<Int>("",

View File

@@ -33,8 +33,8 @@ class BulletPointProviderSpec : Spek({
expectWitNewBulletPoint(p, "a") toEqual "b"
}),
ListAssertionGroupType::class to ("- " to { p ->
expectWitNewBulletPoint(p, "a")._logic.appendAssertionsCreatedBy {
_logic.appendAssertion(
expectWitNewBulletPoint(p, "a")._logic.appendAsGroup {
_logic.append(
assertionBuilder.list
.withDescriptionAndEmptyRepresentation("hello")
.withAssertion(_logic.toBe("b")).build()
@@ -54,8 +54,8 @@ class BulletPointProviderSpec : Spek({
expectWitNewBulletPoint(p, listOf(1)) toContainExactly 2
}),
ExplanatoryAssertionGroupType::class to (">> " to { p ->
expectWitNewBulletPoint(p, "a")._logic.appendAssertionsCreatedBy {
_logic.appendAssertion(
expectWitNewBulletPoint(p, "a")._logic.appendAsGroup {
_logic.append(
assertionBuilder.explanatoryGroup
.withDefaultType
.withAssertion(_logic.toBe("b"))
@@ -65,8 +65,8 @@ class BulletPointProviderSpec : Spek({
}
}),
WarningAssertionGroupType::class to ("(!) " to { p ->
expectWitNewBulletPoint(p, "a")._logic.appendAssertionsCreatedBy {
_logic.appendAssertion(
expectWitNewBulletPoint(p, "a")._logic.appendAsGroup {
_logic.append(
assertionBuilder.explanatoryGroup
.withWarningType
.withAssertion(_logic.toBe("b"))
@@ -76,8 +76,8 @@ class BulletPointProviderSpec : Spek({
}
}),
InformationAssertionGroupType::class to ("(i) " to { p ->
expectWitNewBulletPoint(p, "a")._logic.appendAssertionsCreatedBy {
_logic.appendAssertion(
expectWitNewBulletPoint(p, "a")._logic.appendAsGroup {
_logic.append(
assertionBuilder.explanatoryGroup
.withInformationType(false)
.withAssertion(_logic.toBe("b"))