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:
James Strachan
2011-12-22 08:59:43 +00:00
parent 060719e71b
commit 71b1aee908
4 changed files with 63 additions and 10 deletions
+6 -2
View File
@@ -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)
*/
}
}
+1 -1
View File
@@ -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);
}
}