added a little helper method for processing a closeable object which then makes sure the resource is closed (like the try-with-resource extension in Java 7)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Hello
|
||||
World
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace test.collections
|
||||
|
||||
import std.test.*
|
||||
|
||||
import std.io.*
|
||||
import std.util.*
|
||||
import java.io.*
|
||||
|
||||
class IoTest() : TestSupport() {
|
||||
val file = File("test/HelloWorld.txt")
|
||||
|
||||
fun testUse() {
|
||||
val list = arrayList<String>()
|
||||
|
||||
val reader = FileReader(file).buffered()
|
||||
reader.close()
|
||||
|
||||
/**
|
||||
TODO compiler error?
|
||||
reader.use<BufferedReader,Unit>{
|
||||
val line = it.readLine()
|
||||
if (line != null) {
|
||||
list.add(line)
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(arrayList("Hello", "World"), list)
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user