more tests for for-

This commit is contained in:
Alex Tkachman
2011-09-03 13:39:28 +02:00
parent 44c4b2db3d
commit c20a39dbd8
2 changed files with 26 additions and 6 deletions
@@ -1,19 +1,26 @@
fun box() : String {
val c6 = MyCollection4()
for (el in c6) {
System.out?.println(el)
}
val c5 = MyCollection3()
for (el in c5) {}
for (el in c5) {
System.out?.println(el)
}
val c1: java.lang.Iterable<Int> = MyCollection1()
for (el in c1) {}
val c2 = MyCollection1()
for (el in c2) {}
/*
val c3: Iterable<Int> = MyCollection2()
for (el in c3) {}
val c4 = MyCollection2()
for (el in c4) {}
*/
return "OK"
}
@@ -39,7 +46,20 @@ class MyCollection3() {
fun iterator() = MyIterator()
class MyIterator() {
fun next() = 0
fun hasNext() = false
var k : Int = 5
fun next() : Int? = k--
fun hasNext() = k > 0
}
}
class MyCollection4() {
fun iterator() = MyIterator()
class MyIterator() {
var k : Int = 5
fun next() : Int = k--
fun hasNext() = k > 0
}
}