From e7031299a70ded37e1cd10dd5399d3a335fc8ed7 Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Sun, 25 Apr 2021 00:46:15 +0200 Subject: [PATCH] replace isLessThan with toBeLessThan in README --- README.md | 136 +++++++++--------- .../readme/examples/MostExamplesSpec.kt | 27 ++++ 2 files changed, 99 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index cb2a9390d..4e0420935 100644 --- a/README.md +++ b/README.md @@ -303,13 +303,17 @@ you only need to write the `expect(...)` part once and can make several single a The expression which determines the subject of the assertion (`4 + 6` in the above example) is evaluated only once. In this sense we could have written it also as follows (which is only the same because `4 + 6` does not have side effects). + + + ```kotlin -expect(4 + 6).isLessThan(5) -expect(4 + 6).isGreaterThan(10) -``` +expect(4 + 6).toBeLessThan(5) +expect(4 + 6).toBeGreaterThan(10) +``` + Correspondingly, the first `expect` statement (which does not hold) throws an `AssertionError`. -In the above example, `isLessThan(5)` is already wrong and thus `isGreaterThan(10)` was not evaluated at all +In the above example, `toBeLessThan(5)` is already wrong and thus `toBeGreaterThan(10)` was not evaluated at all and correspondingly not reported. If you want that both assertions are evaluated together, then use the assertion group syntax as follows: @@ -323,7 +327,7 @@ expect(4 + 6) { toBeGreaterThan(10) } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L29)[Output](#ex-group) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L40)[Output](#ex-group) ```text expected that subject: 10 (kotlin.Int <1234789>) @@ -336,15 +340,19 @@ An assertion group throws an `AssertionError` at the end of its block; hence rep The reporting can be read as `I expected that the subject of the assertion, which is 10, is less than 5 and is greater than 10` You can use `and` as filling element between single assertions and assertion group blocks: -```kotlin -expect(4 + 6).isLessThan(5).and.isGreaterThan(10) -expect(4 + 6) { - // ... + + +```kotlin +expect(5).toBeGreaterThan(2).and.toBeLessThan(10) + +expect(5) { + // ... } and { // if the previous block fails, then this one is not evaluated // ... } ``` + ## Expect an Exception @@ -355,19 +363,19 @@ expect { throw IllegalArgumentException("name is empty") }.toThrow() ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L37)[Output](#ex-toThrow1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L64)[Output](#ex-toThrow1) ```text -expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$3$1 <1234789>) +expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$7$1 <1234789>) ◆ ▶ thrown exception when called: java.lang.IllegalArgumentException ◾ is instance of type: IllegalStateException (java.lang.IllegalStateException) ℹ Properties of the unexpected IllegalArgumentException » message: "name is empty" <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$3$1.invoke(MostExamplesSpec.kt:40) - ⚬ readme.examples.MostExamplesSpec$1$3$1.invoke(MostExamplesSpec.kt:22) - ⚬ readme.examples.MostExamplesSpec$1$3.invoke(MostExamplesSpec.kt:239) - ⚬ readme.examples.MostExamplesSpec$1$3.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$7$1.invoke(MostExamplesSpec.kt:67) + ⚬ readme.examples.MostExamplesSpec$1$7$1.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:266) + ⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:22) ``` @@ -391,10 +399,10 @@ expect { throw IllegalArgumentException() }.toThrow().message.toStartWith("firstName") ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L44)[Output](#ex-toThrow2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L71)[Output](#ex-toThrow2) ```text -expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$4$1 <1234789>) +expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$8$1 <1234789>) ◆ ▶ thrown exception when called: java.lang.IllegalArgumentException ◾ ▶ message: null ◾ is instance of type: String (kotlin.String) -- Class: java.lang.String @@ -412,10 +420,10 @@ expect { message { toStartWith("firstName") } } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L50)[Output](#ex-toThrow3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L77)[Output](#ex-toThrow3) ```text -expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$5$1 <1234789>) +expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$9$1 <1234789>) ◆ ▶ thrown exception when called: java.lang.IllegalArgumentException ◾ ▶ message: null ◾ is instance of type: String (kotlin.String) -- Class: java.lang.String @@ -436,22 +444,22 @@ expect { throw IllegalArgumentException("name is empty", RuntimeException("a cause")) }.notToThrow() ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L58)[Output](#ex-notToThrow) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L85)[Output](#ex-notToThrow) ```text -expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$6$1 <1234789>) +expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$10$1 <1234789>) ◆ ▶ invoke(): ❗❗ threw java.lang.IllegalArgumentException ℹ Properties of the unexpected IllegalArgumentException » message: "name is empty" <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$6$1.invoke(MostExamplesSpec.kt:61) - ⚬ readme.examples.MostExamplesSpec$1$6$1.invoke(MostExamplesSpec.kt:22) - ⚬ readme.examples.MostExamplesSpec$1$6.invoke(MostExamplesSpec.kt:62) - ⚬ readme.examples.MostExamplesSpec$1$6.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$10$1.invoke(MostExamplesSpec.kt:88) + ⚬ readme.examples.MostExamplesSpec$1$10$1.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$10.invoke(MostExamplesSpec.kt:89) + ⚬ readme.examples.MostExamplesSpec$1$10.invoke(MostExamplesSpec.kt:22) » cause: java.lang.RuntimeException » message: "a cause" <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$6$1.invoke(MostExamplesSpec.kt:61) + ⚬ readme.examples.MostExamplesSpec$1$10$1.invoke(MostExamplesSpec.kt:88) ``` @@ -843,7 +851,7 @@ expect(x).toBeAnInstanceOf() .feature { f(it::number) } .toEqual(2) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L65)[Output](#ex-type-assertions-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L92)[Output](#ex-type-assertions-1) ```text expected that subject: SubType2(word=hello, flag=true) (readme.examples.SubType2 <1234789>) @@ -865,7 +873,7 @@ expect(x).toBeAnInstanceOf { feature { f(it::flag) }.toEqual(false) } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L71)[Output](#ex-type-assertions-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L98)[Output](#ex-type-assertions-2) ```text expected that subject: SubType2(word=hello, flag=true) (readme.examples.SubType2 <1234789>) @@ -894,7 +902,7 @@ Let us look at the case where the subject of the assertion has a [nullable type] val slogan1: String? = "postulating assertions made easy" expect(slogan1).toEqual(null) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L79)[Output](#ex-nullable-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L106)[Output](#ex-nullable-1) ```text expected that subject: "postulating assertions made easy" <1234789> @@ -908,7 +916,7 @@ expected that subject: "postulating assertions made easy" <1234789> val slogan2: String? = null expect(slogan2).toEqual("postulating assertions made easy") ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L83)[Output](#ex-nullable-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L110)[Output](#ex-nullable-2) ```text expected that subject: null @@ -929,7 +937,7 @@ expect(slogan2) // subject has type String? .notToEqualNull() // subject is narrowed to String .toStartWith("atrium") ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L88)[Output](#ex-nullable-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L115)[Output](#ex-nullable-3) ```text expected that subject: null @@ -946,7 +954,7 @@ one without (example above) and one with `assertionCreator`-lambda (example belo ```kotlin expect(slogan2).notToEqualNull { toStartWith("atrium") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L93)[Output](#ex-nullable-4) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L120)[Output](#ex-nullable-4) ```text expected that subject: null @@ -985,7 +993,7 @@ The following sub sections show both use cases by examples. ```kotlin expect(listOf(1, 2, 2, 4)).contains(2, 3) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L97)[Output](#ex-collection-short-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L124)[Output](#ex-collection-short-1) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1024,7 +1032,7 @@ expect(listOf(1, 2, 2, 4)).contains( { toBeGreaterThan(2).toBeLessThan(4) } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L101)[Output](#ex-collection-short-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L128)[Output](#ex-collection-short-2) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1048,8 +1056,8 @@ the opposite of `inAnyOrder.atLeast(1)` and is named `containsExactly`. Again, Atrium provides two overloads for it, one for values, e.g. `containsExactly(1, 2)` which calls `contains.inOrder.only.values(1, 2)` and a second one which expects one or more `assertionCreator`-lambda, -e.g. `containsExactly({ isLessThan(0) }, { isGreaterThan(5) })` -which calls `contains.inOrder.only.elements({ isLessThan(2) }, { isGreaterThan(5) })`. +e.g. `containsExactly( { toBeGreaterThan(5) }, { toBeLessThan(10) })` +which calls `contains.inOrder.only.elements({ toBeGreaterThan(5) }, { toBeLessThan(10) })`. We will spare the examples here and show them in the following sections. Notice that you can pass `null` to `containsExactly` instead of an `assertionCreator`-lambda to match `null`. This makes of course only sense if your `Iterable` contains nullable elements. @@ -1064,7 +1072,7 @@ Following each in action: ```kotlin expect(listOf(1, 2, 3, 4)).any { toBeLessThan(0) } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L108)[Output](#ex-collection-any) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L135)[Output](#ex-collection-any) ```text expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1081,7 +1089,7 @@ expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 3, 4)).none { toBeGreaterThan(2) } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L111)[Output](#ex-collection-none) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L138)[Output](#ex-collection-none) ```text expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1100,7 +1108,7 @@ expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 3, 4)).all { toBeGreaterThan(2) } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L114)[Output](#ex-collection-all) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L141)[Output](#ex-collection-all) ```text expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1130,7 +1138,7 @@ Following on the last section we will start with an `inOrder` example: ```kotlin expect(listOf(1, 2, 2, 4)).contains.inOrder.only.entries({ toBeLessThan(3) }, { toBeLessThan(2) }) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L118)[Output](#ex-collection-builder-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L145)[Output](#ex-collection-builder-1) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1178,7 +1186,7 @@ and we happily answer your question there. ```kotlin expect(listOf(1, 2, 2, 4)).contains.inOrder.only.values(1, 2, 2, 3, 4) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L121)[Output](#ex-collection-builder-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L148)[Output](#ex-collection-builder-2) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1203,7 +1211,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.atLeast(1).butAtMost(2).entries({ toBeLessThan(3) }) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L124)[Output](#ex-collection-builder-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L151)[Output](#ex-collection-builder-3) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1220,7 +1228,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(1, 2, 3, 4) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L127)[Output](#ex-collection-builder-4) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L154)[Output](#ex-collection-builder-4) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1239,7 +1247,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(4, 3, 2, 2, 1) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L130)[Output](#ex-collection-builder-5) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L157)[Output](#ex-collection-builder-5) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1269,7 +1277,7 @@ and more [Sophisticated Assertion Builder](#sophisticated-assertion-builders-1) ```kotlin expect(mapOf("a" to 1, "b" to 2)).contains("c" to 2, "a" to 1, "b" to 1) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L134)[Output](#ex-map-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L161)[Output](#ex-map-1) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1293,7 +1301,7 @@ expect(mapOf("a" to 1, "b" to 2)).contains( KeyValue("b") { toBeLessThan(2) } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L137)[Output](#ex-map-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L164)[Output](#ex-map-2) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1315,7 +1323,7 @@ Again both overloads are provided, one for key-value `Pair`s: ```kotlin expect(mapOf("a" to 1, "b" to 2)).containsOnly("b" to 2) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L145)[Output](#ex-map-only-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L172)[Output](#ex-map-only-1) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1340,7 +1348,7 @@ expect(mapOf("a" to 1, "b" to 2)).containsOnly( KeyValue("b") { toBeLessThan(2) } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L148)[Output](#ex-map-only-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L175)[Output](#ex-map-only-2) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1368,7 +1376,7 @@ again provide two overloads, one expecting key-value `Pair`s: ```kotlin expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries("b" to 2, "a" to 1) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L156)[Output](#ex-map-builder-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L183)[Output](#ex-map-builder-1) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1395,7 +1403,7 @@ expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries( KeyValue("a") { toBeLessThan(2) }, KeyValue("b") { toBeLessThan(2) }) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L159)[Output](#ex-map-builder-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L186)[Output](#ex-map-builder-2) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1432,7 +1440,7 @@ expect(mapOf("bernstein" to bernstein)) feature { f(it::firstName) }.toEqual("Albert") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L169)[Output](#ex-map-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L196)[Output](#ex-map-3) ```text expected that subject: {bernstein=Person(firstName=Leonard, lastName=Bernstein, age=50)} (java.util.Collections.SingletonMap <1234789>) @@ -1452,7 +1460,7 @@ expect(mapOf("a" to 1, "b" to 2)) { values { none { toBeGreaterThan(1) } } } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L181)[Output](#ex-map-4) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L208)[Output](#ex-map-4) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1490,7 +1498,7 @@ expect(linkedMapOf("a" to 1, "b" to 2)).asEntries().contains.inOrder.only.entrie } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L187)[Output](#ex-map-5) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L214)[Output](#ex-map-5) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1586,7 +1594,7 @@ expect("filename?") notToContain("?") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L197)[Output](#ex-because-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L224)[Output](#ex-because-1) ```text expected that subject: "filename?" <1234789> @@ -1842,7 +1850,7 @@ But Atrium shows where it goes wrong and even gives a possible hint: ```text expected that subject: 9.99 (kotlin.Float <1234789>) -◆ to be (error ± 0.01): 10.0 (kotlin.Float <1234789>) +◆ to equal (error ± 0.01): 10.0 (kotlin.Float <1234789>) » failure might be due to using kotlin.Float, see exact check on the next line » exact check is |9.989999771118164 - 10.0| = 0.010000228881835938 ≤ 0.009999999776482582 ``` @@ -1863,10 +1871,10 @@ expect { } }.toThrow { messageContains("no no no") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L210)[Output](#ex-add-info-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L237)[Output](#ex-add-info-3) ```text -expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$35$1 <1234789>) +expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$39$1 <1234789>) ◆ ▶ thrown exception when called: java.lang.IllegalArgumentException ◾ is instance of type: IllegalStateException (java.lang.IllegalStateException) » ▶ message: @@ -1878,14 +1886,14 @@ expected that subject: () -> kotlin.Nothing (readme.examples.MostExamples ℹ Properties of the unexpected IllegalArgumentException » message: "no no no..." <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$35$1.invoke(MostExamplesSpec.kt:215) - ⚬ readme.examples.MostExamplesSpec$1$35$1.invoke(MostExamplesSpec.kt:22) - ⚬ readme.examples.MostExamplesSpec$1$35.invoke(MostExamplesSpec.kt:239) - ⚬ readme.examples.MostExamplesSpec$1$35.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:242) + ⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$39.invoke(MostExamplesSpec.kt:266) + ⚬ readme.examples.MostExamplesSpec$1$39.invoke(MostExamplesSpec.kt:22) » cause: java.lang.UnsupportedOperationException » message: "not supported" <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$35$1.invoke(MostExamplesSpec.kt:213) + ⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:240) ``` @@ -1906,7 +1914,7 @@ then Atrium reminds us of the possible pitfall. For instance: ```kotlin expect(BigDecimal.TEN).isEqualIncludingScale(BigDecimal("10.0")) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L220)[Output](#ex-pitfall-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L247)[Output](#ex-pitfall-1) ```text expected that subject: 10 (java.math.BigDecimal <1234789>) @@ -1924,7 +1932,7 @@ For instance: ```kotlin expect(listOf(1)).get(0) {} ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L223)[Output](#ex-pitfall-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L250)[Output](#ex-pitfall-2) ```text expected that subject: [1] (java.util.Collections.SingletonList <1234789>) diff --git a/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt b/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt index 2e991d9bc..c42cbc52b 100644 --- a/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt +++ b/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt @@ -26,6 +26,17 @@ class MostExamplesSpec : Spek({ expect(4 + 6).toBeLessThan(5).toBeGreaterThan(10) } + fun codeSingleNotExecutedHenceDoesNotFail() { + //snippet-code-single-start + expect(4 + 6).toBeLessThan(5) + expect(4 + 6).toBeGreaterThan(10) + //snippet-code-single-end + } + + test("code-single-explained"){ + //snippet-code-single-insert + } + test("ex-group") { // assertion group with two assertions, both evaluated expect(4 + 6) { @@ -34,6 +45,22 @@ class MostExamplesSpec : Spek({ } } + fun codeAndNotExecutedHenceDoesNotFail() { + //snippet-code-and-start + expect(5) { + // ... + } and { // if the previous block fails, then this one is not evaluated + // ... + } + //snippet-code-and-end + } + + test("code-and"){ + expect(5).toBeGreaterThan(2).and.toBeLessThan(10) + + //snippet-code-and-insert + } + test("ex-toThrow1") { expect { // this block does something but eventually...