added a little test case showing how we can iterate through lines in a file; also started adding helper methods to the standard kotlin Iterator; though probably need to rename the to* methods iterators, maybe to collect* as Stepan suggested. Could maybe use some extension function syntax making it easy to add helper methods consistently to Array, Iterator, Iterable, java.util.Iterator, java.util.Iterable at the same time, we're very inconsistent currently :)
This commit is contained in:
@@ -10,6 +10,11 @@ import java.util.*
|
||||
class IoTest() : TestSupport() {
|
||||
val file = File("test/HelloWorld.txt")
|
||||
|
||||
fun testLineIterator() {
|
||||
val list = FileReader(file).buffered().lineIterator().toArrayList()
|
||||
assertEquals(arrayList("Hello", "World"), list)
|
||||
}
|
||||
|
||||
fun testUse() {
|
||||
val list = ArrayList<String>()
|
||||
|
||||
@@ -18,7 +23,7 @@ class IoTest() : TestSupport() {
|
||||
|
||||
/**
|
||||
TODO compiler error?
|
||||
reader.use<BufferedReader,Unit>{
|
||||
reader.use{
|
||||
val line = it.readLine()
|
||||
if (line != null) {
|
||||
list.add(line)
|
||||
@@ -28,5 +33,4 @@ class IoTest() : TestSupport() {
|
||||
assertEquals(arrayList("Hello", "World"), list)
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,6 @@ import junit.framework.TestSuite;
|
||||
*/
|
||||
public class TestAll {
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(CollectionTest.class, SetTest.class, ListTest.class, IoTest.class, MapTest.class);
|
||||
return new TestSuite(CollectionTest.class, IoTest.class, ListTest.class, MapTest.class, SetTest.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user