Skip to content

Commit 0521af0

Browse files
author
Joseph Cooper
committed
Rename JVM File contents helper functions
1 parent 3046c24 commit 0521af0

File tree

2 files changed

+21
-7
lines changed
  • assertk/src

2 files changed

+21
-7
lines changed

assertk/src/jvmMain/kotlin/assertk/assertions/file.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,26 @@ fun Assert<File>.extension() = havingExtension()
5959
/**
6060
* Returns an assert on the file's contents as text.
6161
*/
62-
fun Assert<File>.text(charset: Charset = Charsets.UTF_8) = having("text") { it.readText(charset) }
62+
fun Assert<File>.havingText(charset: Charset = Charsets.UTF_8) = having("text") { it.readText(charset) }
63+
64+
@Deprecated(
65+
message = "Function text has been renamed to havingText",
66+
replaceWith = ReplaceWith("havingText()"),
67+
level = DeprecationLevel.WARNING
68+
)
69+
fun Assert<File>.text(charset: Charset = Charsets.UTF_8) = havingText()
6370

6471
/**
6572
* Returns an assert on the file's contents as bytes.
6673
*/
67-
fun Assert<File>.bytes() = having("bytes", File::readBytes)
74+
fun Assert<File>.havingBytes() = having("bytes", File::readBytes)
75+
76+
@Deprecated(
77+
message = "Function bytes has been renamed to havingBytes",
78+
replaceWith = ReplaceWith("havingBytes()"),
79+
level = DeprecationLevel.WARNING
80+
)
81+
fun Assert<File>.bytes() = havingBytes()
6882

6983
/**
7084
* Asserts the file exists.
@@ -144,7 +158,7 @@ fun Assert<File>.hasExtension(expected: String) {
144158
* @see [hasBytes]
145159
*/
146160
fun Assert<File>.hasText(expected: String, charset: Charset = Charsets.UTF_8) {
147-
text(charset).isEqualTo(expected)
161+
havingText(charset).isEqualTo(expected)
148162
}
149163

150164
/**

assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ class FileTest {
204204
//region contains
205205
@Test
206206
fun contains_correct_substring_passes() {
207-
assertThat(fileWithText).text().contains("Forty-two")
207+
assertThat(fileWithText).havingText().contains("Forty-two")
208208
}
209209

210210
@Test
211211
fun contains_wrong_substring_fails() {
212212
val error = assertFailsWith<AssertionError> {
213-
assertThat(fileWithText).text().contains("Forty-two!")
213+
assertThat(fileWithText).havingText().contains("Forty-two!")
214214
}
215215
assertTrue(error.message!!.startsWith("expected [text] to contain:<\"Forty-two!\"> but was:<\"$text\">"))
216216
assertTrue(error.message!!.contains("file_contains"))
@@ -228,14 +228,14 @@ class FileTest {
228228

229229
@Test
230230
fun matches_correct_regex_passes() {
231-
assertThat(matchingFile).text().matches(".a...e.".toRegex())
231+
assertThat(matchingFile).havingText().matches(".a...e.".toRegex())
232232
}
233233

234234
@Test
235235
fun matches_wrong_regex_fails() {
236236
val incorrectRegexp = ".*d".toRegex()
237237
val error = assertFailsWith<AssertionError> {
238-
assertThat(matchingFile).text().matches(incorrectRegexp)
238+
assertThat(matchingFile).havingText().matches(incorrectRegexp)
239239
}
240240
assertTrue(error.message!!.startsWith("expected [text] to match:</$incorrectRegexp/> but was:<\"$matchingText\">"))
241241
assertTrue(error.message!!.contains("file_contains"))

0 commit comments

Comments
 (0)