KT-968 String should provide an iterator() method

This commit is contained in:
Alex Tkachman
2012-01-25 09:36:55 +02:00
parent 309b6b3e0e
commit 3c13a2cd98
3 changed files with 61 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
package testString
import std.io.*
import stdhack.test.*
import junit.framework.*
class StringTest() : TestCase() {
fun testStringIterator() {
var sum = 0
for(c in "239")
sum += (c.int - '0'.int)
assertTrue(sum == 14)
}
fun testStringBuilderIterator() {
var sum = 0
val sb = StringBuilder()
for(c in "239")
sb.append(c)
println(sb)
for(c in sb)
sum += (c.int - '0'.int)
assertTrue(sum == 14)
}
}