Skip to content

Commit

Permalink
Rename JVM Path helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Cooper committed May 20, 2024
1 parent 0523b81 commit 2bdd618
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions assertk/src/jvmMain/kotlin/assertk/assertions/path.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ import java.nio.file.Path
*
* @param charset charset to use when reading file
*/
fun Assert<Path>.lines(charset: Charset = Charsets.UTF_8): Assert<List<String>> =
fun Assert<Path>.havingLines(charset: Charset = Charsets.UTF_8): Assert<List<String>> =
transform { actual -> Files.readAllLines(actual, charset) }

@Deprecated(
message = "Function lines has been renamed to havingLines",
replaceWith = ReplaceWith("havingLines()"),
level = DeprecationLevel.WARNING
)
fun Assert<Path>.lines(charset: Charset = Charsets.UTF_8): Assert<List<String>> = havingLines()

/** Assert on file bytes */
fun Assert<Path>.bytes(): Assert<ByteArray> =
fun Assert<Path>.havingBytes(): Assert<ByteArray> =
transform { actual -> Files.readAllBytes(actual) }

@Deprecated(
message = "Function bytes has been renamed to havingBytes",
replaceWith = ReplaceWith("havingBytes()"),
level = DeprecationLevel.WARNING
)
fun Assert<Path>.bytes(): Assert<ByteArray> = havingBytes()

/** Assert that the path is a regular file.
*
* @param options indicating how symbolic links are handled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ class PathTest {
//region lines
@Test
fun lines_correct_string_passes() {
assertThat(regularFileWithText!!).lines().containsExactly("a", "b")
assertThat(regularFileWithText!!).havingLines().containsExactly("a", "b")
}
//endregion

//region bytes
@Test
fun bytes_value_correct_byte_array_passes() {
assertThat(regularFile!!).bytes().containsExactly(*ByteArray(10))
assertThat(regularFile!!).havingBytes().containsExactly(*ByteArray(10))
}
//endregion
}
Expand Down

0 comments on commit 2bdd618

Please sign in to comment.