mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
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:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>("",
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user