KT-11208 Remove readLine's lineSeparator parameter

This commit is contained in:
meztihn
2018-02-04 13:30:13 +05:00
committed by Ilya Gorbunov
parent f6c1886394
commit 68cb66ff0e
2 changed files with 24 additions and 33 deletions
+7 -18
View File
@@ -21,7 +21,7 @@ import java.nio.charset.Charset
import kotlin.test.*
class ConsoleTest {
private val defaultLineSeparator: String = "\\n"
private val defaultLineSeparator: String = "\n"
@Test
fun shouldReadEmptyLine() {
@@ -45,14 +45,8 @@ class ConsoleTest {
@Test
fun shouldReadWindowsLineSeparator() {
val lineSeparator = "\\r\\n"
testReadLine("first${lineSeparator}second", "first", "second", lineSeparator = lineSeparator)
}
@Test
fun shouldReadOldMacLineSeparator() {
val lineSeparator = "\\r"
testReadLine("first${lineSeparator}second", "first", "second", lineSeparator = lineSeparator)
val lineSeparator = "\r\n"
testReadLine("first${lineSeparator}second", "first", "second")
}
@Test
@@ -60,20 +54,15 @@ class ConsoleTest {
testReadLine("first${defaultLineSeparator}second", "first", "second", charset = Charsets.UTF_32)
}
private fun testReadLine(
text: String,
vararg expected: String,
lineSeparator: String = defaultLineSeparator,
charset: Charset = Charsets.UTF_8
) {
val actual = readLines(text, lineSeparator, charset)
private fun testReadLine(text: String, vararg expected: String, charset: Charset = Charsets.UTF_8) {
val actual = readLines(text, charset)
assertEquals(expected.asList(), actual)
}
private fun readLines(text: String, lineSeparator: String, charset: Charset): List<String> {
private fun readLines(text: String, charset: Charset): List<String> {
text.byteInputStream(charset).use { stream ->
val decoder = charset.newDecoder()
return generateSequence { readLine(stream, lineSeparator, decoder) }.toList().also {
return generateSequence { readLine(stream, decoder) }.toList().also {
assertTrue("All bytes should be read") { stream.read() == -1 }
}
}