diff options
Diffstat (limited to 'test/files')
-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 |