Files
kotlin-fork/libraries/stdlib/jvm/test/io/IOStreams.kt
T
Ilya Gorbunov ecf0d7ec0d Reformat stdlib tests and samples
#KT-5558
2018-04-27 05:28:57 +03:00

47 lines
1.1 KiB
Kotlin

/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package test.io
import kotlin.test.*
import java.io.Writer
import java.io.BufferedReader
class IOStreamsTest {
@Test fun testGetStreamOfFile() {
val tmpFile = createTempFile()
var writer: Writer? = null
try {
writer = tmpFile.outputStream().writer()
writer.write("Hello, World!")
} finally {
writer?.close()
}
val act: String?
var reader: BufferedReader? = null
try {
reader = tmpFile.inputStream().reader().buffered()
act = reader.readLine()
} finally {
reader?.close()
}
assertEquals("Hello, World!", act)
}
@Test fun testInputStreamIterator() {
val x = ByteArray(10) { it.toByte() }
val result = mutableListOf<Byte>()
x.inputStream().buffered().use { stream ->
for (b in stream) {
result += b
}
}
assertEquals(x.asList(), result)
}
}