mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
cleanup wrong changes in fluent and improvements in infix API
replace EncodingWithCreator with PathWithEncoding (and move to correct package)
This commit is contained in:
@@ -292,7 +292,7 @@ fun <T : Path> Expect<T>.extension(assertionCreator: Expect<String>.() -> Unit):
|
||||
|
||||
/**
|
||||
* Expects that the subject of the assertion (a [Path]) has the same textual content
|
||||
* as [targetPath].
|
||||
* as [targetPath] taking the given encodings into account (UTF-8 if none given).
|
||||
*
|
||||
* @param sourceCharset source file encoding - UTF-8 per default.
|
||||
* @param targetCharset target file encoding - UTF-8 per default.
|
||||
|
||||
@@ -5,7 +5,6 @@ import ch.tutteli.atrium.specs.fun0
|
||||
import ch.tutteli.atrium.specs.fun1
|
||||
import ch.tutteli.atrium.specs.fun3
|
||||
import ch.tutteli.atrium.specs.notImplemented
|
||||
import ch.tutteli.atrium.specs.testutils.WithAsciiReporter
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
@@ -25,7 +24,7 @@ class PathAssertionsSpec : ch.tutteli.atrium.specs.integration.PathAssertionsSpe
|
||||
fun1(Companion::hasSameTextualContentAsDefaultArgs)
|
||||
) {
|
||||
|
||||
companion object : WithAsciiReporter() {
|
||||
companion object {
|
||||
private fun hasSameTextualContentAsDefaultArgs(expect: Expect<Path>, targetPath: Path): Expect<Path> =
|
||||
expect.hasSameTextualContentAs(targetPath)
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package ch.tutteli.atrium.api.infix.en_GB.creating.encoding
|
||||
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* Parameter object which combines [path] (as [Path]), [sourceCharset] (as [Charset]), [targetCharset] (as [Charset])
|
||||
* with an [assertionCreator] which defines assertions for a resulting feature of type [E].
|
||||
*
|
||||
* Use the function `withEncoding(Path, Charset, Charset) { ... }` to create this representation.
|
||||
*
|
||||
* @since 0.13.0
|
||||
*/
|
||||
data class EncodingWithCreator<E> internal constructor(val path: Path, val sourceCharset: Charset, val targetCharset: Charset,
|
||||
val assertionCreator: Expect<E>)
|
||||
@@ -8,7 +8,7 @@ package ch.tutteli.atrium.api.infix.en_GB.creating.path
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
|
||||
/**
|
||||
* Parameter object which combines an [path] (as [String]) with an [assertionCreator] which defines assertions for
|
||||
* Parameter object which combines a [path] (as [String]) with an [assertionCreator] which defines assertions for
|
||||
* a resulting feature of type [E].
|
||||
*
|
||||
* Use the function `path(String) { ... }` to create this representation.
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package ch.tutteli.atrium.api.infix.en_GB.creating.path
|
||||
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* Parameter object which combines [path] (as [Path]) with a [sourceCharset] and [targetCharset].
|
||||
*
|
||||
* Use the function `withEncoding(Path, Charset, Charset)` to create this representation.
|
||||
*
|
||||
* @since 0.13.0
|
||||
*/
|
||||
data class PathWithEncoding internal constructor(
|
||||
val path: Path,
|
||||
val sourceCharset: Charset,
|
||||
val targetCharset: Charset
|
||||
)
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package ch.tutteli.atrium.api.infix.en_GB
|
||||
|
||||
import ch.tutteli.atrium.api.infix.en_GB.creating.encoding.EncodingWithCreator
|
||||
import ch.tutteli.atrium.api.infix.en_GB.creating.path.PathWithEncoding
|
||||
import ch.tutteli.atrium.api.infix.en_GB.creating.path.PathWithCreator
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import ch.tutteli.atrium.logic.*
|
||||
@@ -303,7 +303,7 @@ infix fun <T : Path> Expect<T>.extension(assertionCreator: Expect<String>.() ->
|
||||
|
||||
/**
|
||||
* Expects that the subject of the assertion (a [Path]) has the same textual content
|
||||
* as [targetPath].
|
||||
* as [targetPath] (using UTF-8 for encoding)
|
||||
*
|
||||
* @return An [Expect] for the current subject of the assertion.
|
||||
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
|
||||
@@ -312,25 +312,39 @@ infix fun <T : Path> Expect<T>.extension(assertionCreator: Expect<String>.() ->
|
||||
*/
|
||||
infix fun <T : Path> Expect<T>.hasSameTextualContentAs(
|
||||
targetPath: Path
|
||||
): Expect<T> = hasSameTextualContentAs(withEncoding(targetPath, this))
|
||||
): Expect<T> = hasSameTextualContentAs(withEncoding(targetPath))
|
||||
|
||||
/**
|
||||
* Helper function to create a [PathWithEncoding] based on the given [path] and the [sourceCharset] and [targetCharset]
|
||||
* where UTF-8 is used as default if one encoding is missing.
|
||||
*/
|
||||
fun withEncoding(
|
||||
path: Path,
|
||||
sourceCharset: Charset = Charsets.UTF_8,
|
||||
targetCharset: Charset = Charsets.UTF_8
|
||||
): PathWithEncoding =
|
||||
PathWithEncoding(
|
||||
path,
|
||||
sourceCharset,
|
||||
targetCharset
|
||||
)
|
||||
|
||||
/**
|
||||
* Expects that the subject of the assertion (a [Path]) has the same textual content
|
||||
* as path in [encodingWithCreator].
|
||||
* as [PathWithEncoding.path] in the given [pathWithEncoding] with the specified encodings.
|
||||
*
|
||||
* Use the function `withEncoding(Path, Charset, Charset) { ... }` to create an [EncodingWithCreator].
|
||||
* Use the function `withEncoding(Path, Charset, Charset)` to create a [PathWithEncoding].
|
||||
*
|
||||
* @return An [Expect] for the current subject of the assertion.
|
||||
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
|
||||
*
|
||||
* @since 0.13.0
|
||||
*/
|
||||
infix fun <T : Path> Expect<T>.hasSameTextualContentAs(encodingWithCreator: EncodingWithCreator<T>):
|
||||
Expect<T> = _logicAppend {
|
||||
hasSameTextualContentAs(
|
||||
encodingWithCreator.path, encodingWithCreator.sourceCharset, encodingWithCreator.targetCharset
|
||||
)
|
||||
infix fun <T : Path> Expect<T>.hasSameTextualContentAs(pathWithEncoding: PathWithEncoding): Expect<T> =
|
||||
_logicAppend {
|
||||
hasSameTextualContentAs(pathWithEncoding.path, pathWithEncoding.sourceCharset, pathWithEncoding.targetCharset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects that the subject of the assertion (a [Path]) has the same binary content
|
||||
* as [targetPath].
|
||||
@@ -340,15 +354,5 @@ infix fun <T : Path> Expect<T>.hasSameTextualContentAs(encodingWithCreator: Enco
|
||||
*
|
||||
* @since 0.13.0
|
||||
*/
|
||||
infix fun <T : Path> Expect<T>.hasSameBinaryContentAs(targetPath: Path):
|
||||
Expect<T> = _logicAppend {
|
||||
hasSameBinaryContentAs(targetPath)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to create an [EncodingWithCreator] based on the given [path] and [assertionCreator].
|
||||
*/
|
||||
fun <T : Path> withEncoding(path: Path, assertionCreator: Expect<T>,
|
||||
sourceCharset: Charset = Charsets.UTF_8, targetCharset: Charset = Charsets.UTF_8):
|
||||
EncodingWithCreator<T> = EncodingWithCreator(path, sourceCharset, targetCharset, assertionCreator)
|
||||
infix fun <T : Path> Expect<T>.hasSameBinaryContentAs(targetPath: Path): Expect<T> =
|
||||
_logicAppend { hasSameBinaryContentAs(targetPath) }
|
||||
|
||||
@@ -32,10 +32,18 @@ class PathAssertionsSpec : ch.tutteli.atrium.specs.integration.PathAssertionsSpe
|
||||
private fun isWritable(expect: Expect<Path>) = expect toBe writable
|
||||
private fun isRegularFile(expect: Expect<Path>) = expect toBe aRegularFile
|
||||
private fun isDirectory(expect: Expect<Path>) = expect toBe aDirectory
|
||||
private fun hasSameTextualContentAs(expect: Expect<Path>, targetPath: Path, sourceCharset: Charset, targetCharset: Charset): Expect<Path> =
|
||||
expect hasSameTextualContentAs withEncoding(targetPath, expect, sourceCharset = sourceCharset, targetCharset = targetCharset)
|
||||
private fun hasSameTextualContentAsDefaultArgs(expect: Expect<Path>, targetPath: Path): Expect<Path> =
|
||||
expect hasSameTextualContentAs targetPath
|
||||
|
||||
private fun hasSameTextualContentAs(
|
||||
expect: Expect<Path>,
|
||||
targetPath: Path,
|
||||
sourceCharset: Charset,
|
||||
targetCharset: Charset
|
||||
): Expect<Path> = expect hasSameTextualContentAs withEncoding(targetPath, sourceCharset, targetCharset)
|
||||
|
||||
private fun hasSameTextualContentAsDefaultArgs(
|
||||
expect: Expect<Path>,
|
||||
targetPath: Path
|
||||
): Expect<Path> = expect hasSameTextualContentAs targetPath
|
||||
}
|
||||
|
||||
@Suppress("unused", "UNUSED_VALUE")
|
||||
@@ -52,7 +60,7 @@ class PathAssertionsSpec : ch.tutteli.atrium.specs.integration.PathAssertionsSpe
|
||||
a1 toBe writable
|
||||
a1 toBe aRegularFile
|
||||
a1 toBe aDirectory
|
||||
a1 hasSameTextualContentAs withEncoding(Paths.get("a"), a1)
|
||||
a1 hasSameTextualContentAs withEncoding(Paths.get("a"))
|
||||
a1 hasSameTextualContentAs Paths.get("a")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import ch.tutteli.atrium.specs.fun0
|
||||
import ch.tutteli.atrium.specs.fun1
|
||||
import ch.tutteli.atrium.specs.fun3
|
||||
import ch.tutteli.atrium.specs.notImplemented
|
||||
import ch.tutteli.atrium.specs.testutils.WithAsciiReporter
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
@@ -28,7 +27,7 @@ class PathAssertionsSpec : ch.tutteli.atrium.specs.integration.PathAssertionsSpe
|
||||
fun1(Companion::hasSameTextualContentAsDefaultArgs)
|
||||
) {
|
||||
|
||||
companion object : WithAsciiReporter() {
|
||||
companion object {
|
||||
private fun hasSameTextualContentAsDefaultArgs(expect: Expect<Path>, targetPath: Path): Expect<Path> =
|
||||
expect.hasSameTextualContentAs(targetPath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user