doc / ch.tutteli.atrium.api.infix.en_GB / toHaveTheSameTextualContentAs

toHaveTheSameTextualContentAs

infix fun <T : Path> Expect<T>.toHaveTheSameTextualContentAs(targetPath: Path): Expect<T> (source)

Expects that the subject of this expectation (a Path) has the same textual content as targetPath (using UTF-8 for encoding)

val writtenTextInFile = "test_test"

val notEmptyFilePath = tempDir.newFile("test_file_1")
notEmptyFilePath.writeText(writtenTextInFile)

val expectedFilePath = tempDir.newFile("test_file_2")
expectedFilePath.writeText(writtenTextInFile)

val emptyFilePath = tempDir.newFile("test_file_3")

expect(notEmptyFilePath) toHaveTheSameTextualContentAs expectedFilePath

fails { // because nothing is written inside of `emptyFilePath`
    expect(emptyFilePath) toHaveTheSameTextualContentAs expectedFilePath
}

Return
an Expect for the subject of this expectation.

Since
0.17.0

infix fun <T : Path> Expect<T>.toHaveTheSameTextualContentAs(pathWithEncoding: PathWithEncoding): Expect<T> (source)

Expects that the subject of this expectation (a Path) has the same textual content as PathWithEncoding.path in the given pathWithEncoding with the specified encodings.

Use the function withEncoding(Path, Charset, Charset) to create a PathWithEncoding.

val writtenTextInFile = "test_test"

val notEmptyFilePath = tempDir.newFile("test_file_1")
notEmptyFilePath.writeText(writtenTextInFile)

val expectedFilePath = tempDir.newFile("test_file_2")
expectedFilePath.writeText(writtenTextInFile)

val emptyFilePath = tempDir.newFile("test_file_3")

expect(notEmptyFilePath) toHaveTheSameTextualContentAs withEncoding(
    expectedFilePath,
    Charsets.UTF_8,
    Charsets.UTF_8
)

fails { // because nothing is written inside of `emptyFilePath`
    expect(emptyFilePath) toHaveTheSameTextualContentAs withEncoding(
        expectedFilePath,
        Charsets.UTF_8,
        Charsets.UTF_8
    )
}

Return
an Expect for the subject of this expectation.