All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.testing.ApprovalTransformer.kt Maven / Gradle / Ivy

There is a newer version: 5.35.1.0
Show newest version
package org.http4k.testing

import java.io.InputStream

/**
 * Convert the output into a Comparable form.
 */
fun interface ApprovalTransformer : (InputStream) -> T {
    companion object {
        /**
         * Use this for HTTP bodies which are strings with normalised line endings.
         */
        fun StringWithNormalisedLineEndings(): ApprovalTransformer {
            val matchAllLineEndings = "\\r\\n?".toRegex()
            fun String.normalizeLineEndings() = replace(matchAllLineEndings, "\n")

            return ApprovalTransformer {
                it.reader().use { it.readText().normalizeLineEndings().trimEnd() }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy