diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-20 22:16:35 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-20 22:16:35 +0000 |
commit | 5326d9a204764172aebabacbfaefea3da6f13b46 (patch) | |
tree | a69d3c3d2424823455023f3646641c05a1a96d0e /test/files/run | |
parent | 4c3d87a50122dba7f8bc2e8b601c10a216d03a38 (diff) | |
download | scala-5326d9a204764172aebabacbfaefea3da6f13b46.tar.gz scala-5326d9a204764172aebabacbfaefea3da6f13b46.tar.bz2 scala-5326d9a204764172aebabacbfaefea3da6f13b46.zip |
KMP implementation for StringBuilder and test c...
KMP implementation for StringBuilder and test case. Repaired
long-standing infinite loop in lastIndexOf.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/stringbuilder.scala | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/files/run/stringbuilder.scala b/test/files/run/stringbuilder.scala new file mode 100644 index 0000000000..eb0fccd067 --- /dev/null +++ b/test/files/run/stringbuilder.scala @@ -0,0 +1,32 @@ +object Test extends Application { + val str = "ABCDEFGHIJKLMABCDEFGHIJKLM" + type SB = { + def indexOf(str: String): Int + def indexOf(str: String, fromIndex: Int): Int + def lastIndexOf(str: String): Int + def lastIndexOf(str: String, fromIndex: Int): Int + } + + import scala.collection.mutable.{ StringBuilder => ScalaStringBuilder } + import java.lang.{ StringBuilder => JavaStringBuilder } + + val sbScala = new ScalaStringBuilder() append str + val sbJava = new JavaStringBuilder() append str + val sbs: List[SB] = List[SB](sbScala, sbJava) + + def sameAnswers(f: (SB) => Int) = assert(f(sbScala) == f(sbJava)) + + sameAnswers(_.indexOf("")) + sameAnswers(_.indexOf("G")) + sameAnswers(_.indexOf("ABC")) + sameAnswers(_.indexOf("KLM")) + sameAnswers(_.indexOf("QZV")) + sameAnswers(_.indexOf("LMABC")) + sameAnswers(_.lastIndexOf("")) + sameAnswers(_.lastIndexOf("M")) + sameAnswers(_.lastIndexOf("ABCDEFG")) + sameAnswers(_.lastIndexOf("KLM")) + sameAnswers(_.lastIndexOf("QZV")) + sameAnswers(_.lastIndexOf("GHI", 22)) + sameAnswers(_.lastIndexOf("KLM", 22)) +}
\ No newline at end of file |