From 52759489db5d74728bf63f0409a9d863daf3284b Mon Sep 17 00:00:00 2001 From: michelou Date: Wed, 13 Jun 2007 17:22:51 +0000 Subject: fixed split method on JVM --- src/dotnet-library/scala/runtime/RichString.scala | 2 + src/library/scala/runtime/RichString.scala | 18 +++- test/files/run/deeps.scala | 8 +- test/files/run/richs.check | 7 ++ test/files/run/richs.scala | 104 ++++++++++++---------- test/scalatest | 44 ++++----- 6 files changed, 101 insertions(+), 82 deletions(-) diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala index 1b087d7ff9..19085eee88 100644 --- a/src/dotnet-library/scala/runtime/RichString.scala +++ b/src/dotnet-library/scala/runtime/RichString.scala @@ -135,6 +135,8 @@ final class RichString(val self: String) extends Seq[Char] with Ordered[String] def split(separator: Char): Array[String] = self.Split(Array(separator)) + def split(separators: Array[Char]): Array[String] = self.Split(separators) + def toByte: Byte = System.Byte.Parse(self) def toShort: Short = System.Int16.Parse(self) def toInt: Int = System.Int32.Parse(self) diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala index 241d96f303..c8f5160351 100644 --- a/src/library/scala/runtime/RichString.scala +++ b/src/library/scala/runtime/RichString.scala @@ -112,10 +112,10 @@ final class RichString(val self: String) extends Seq[Char] with Ordered[String] * */ def stripMargin(marginChar: Char): String = { - val buf = new scala.compat.StringBuilder() + val buf = new StringBuilder() for (line <- linesWithSeparators) { val len = line.length - var index = 0; + var index = 0 while (index < len && line.charAt(index) <= ' ') index += 1 buf append (if (index < len && line.charAt(index) == marginChar) line.substring(index + 1) else line) @@ -133,7 +133,19 @@ final class RichString(val self: String) extends Seq[Char] with Ordered[String] */ def stripMargin: String = stripMargin('|') - def split(separator: Char): Array[String] = self.split(separator.toString()) + private def escape(ch: Char): String = ch match { + case '.' | '$' | '^' | '\\' => "\\" + ch + case _ => "" + ch + } + + @throws(classOf[java.util.regex.PatternSyntaxException]) + def split(separator: Char): Array[String] = self.split(escape(separator)) + + @throws(classOf[java.util.regex.PatternSyntaxException]) + def split(separators: Array[Char]): Array[String] = { + val re = separators.foldLeft("[")(_+_) + "]" + self.split(re) + } def toByte: Byte = java.lang.Byte.parseByte(self) def toShort: Short = java.lang.Short.parseShort(self) diff --git a/test/files/run/deeps.scala b/test/files/run/deeps.scala index 4bd018e783..af35ce6e45 100644 --- a/test/files/run/deeps.scala +++ b/test/files/run/deeps.scala @@ -42,9 +42,9 @@ object Test extends Application { } def testEquals4 { - println("boo:and:foo".split(":") == "boo:and:foo".split(":")) - println("boo:and:foo".split(":") equals "boo:and:foo".split(":")) - println("boo:and:foo".split(":") deepEquals "boo:and:foo".split(":")) + println("boo:and:foo".split(':') == "boo:and:foo".split(':')) + println("boo:and:foo".split(':') equals "boo:and:foo".split(':')) + println("boo:and:foo".split(':') deepEquals "boo:and:foo".split(':')) val xs = new java.util.ArrayList(); xs.add("a") val ys = new java.util.ArrayList(); ys.add("a") @@ -96,7 +96,7 @@ object Test extends Application { } def testToString3 { - println("boo:and:foo".split(":").deepToString) + println("boo:and:foo".split(':').deepToString) val xs = new java.util.ArrayList(); xs.add("a") println(xs.toArray.deepToString) diff --git a/test/files/run/richs.check b/test/files/run/richs.check index 80b2ef3ef2..2aa7e9467d 100644 --- a/test/files/run/richs.check +++ b/test/files/run/richs.check @@ -64,3 +64,10 @@ s4: abc |xyz s5: abc xyz +List(a, b, c, d) +List(a, b, c, d) +List(a, b, c, d) +List(a, b, c, d) +List(a, b, c, d) +List(a, b, c, d) +List(a, b, c, d) diff --git a/test/files/run/richs.scala b/test/files/run/richs.scala index 951b249e07..db8f228843 100644 --- a/test/files/run/richs.scala +++ b/test/files/run/richs.scala @@ -17,11 +17,11 @@ trait RichTest { } object RichCharTest1 extends RichTest { def run { - Console.println("\n" + getObjectName + ":") - Console.println('\40'.isWhitespace) - Console.println('\011'.isWhitespace) - Console.println('1'.asDigit == 1) - Console.println('A'.asDigit == 10) + println("\n" + getObjectName + ":") + println('\40'.isWhitespace) + println('\011'.isWhitespace) + println('1'.asDigit == 1) + println('A'.asDigit == 10) } } // object RichCharTest2 extends RichTest { @@ -30,84 +30,95 @@ object RichCharTest1 extends RichTest { // private var c: Char = _ // def ch(): Char = c // def nextch(): Unit = { c = if (it.hasNext) it.next else ';' } -// def err(msg: String) = Console.println(msg) +// def err(msg: String) = println(msg) // nextch() // } // def run { -// Console.println("\n" + getObjectName + ":") +// println("\n" + getObjectName + ":") // val c1 = C("x4A;") // val s1 = xml.Utility.parseCharRef(c1.ch, c1.nextch, c1.err) // val c2 = C("74;") // val s2 = xml.Utility.parseCharRef(c2.ch, c2.nextch, c2.err) -// Console.println(s1 == s2) +// println(s1 == s2) // } // } object RichIntTest extends RichTest { private val n = 10 private val m = -2 def run { - Console.println("\n" + getObjectName + ":") - Console.println(length(0 until n)) - Console.println(length(0 to n)) - Console.println(length(m until n)) - Console.println(length(m to n)) - Console.println(length(n until m)) - Console.println(length(n to m)) + println("\n" + getObjectName + ":") + println(length(0 until n)) + println(length(0 to n)) + println(length(m until n)) + println(length(m to n)) + println(length(n until m)) + println(length(n to m)) } } object RichStringTest1 extends RichTest { def run { - Console.println("\n" + getObjectName + ":") - Console.println("s1: " + s1) - Console.println("s2: " + s2) - Console.println("s3: " + s3) - Console.println("s4: " + s4) - Console.println("s5: " + s5) + println("\n" + getObjectName + ":") + println("s1: " + s1) + println("s2: " + s2) + println("s3: " + s3) + println("s4: " + s4) + println("s5: " + s5) } } object RichStringTest2 extends RichTest { def run { - Console.println("\n" + getObjectName + ":") - Console.print("s1: "); s1.lines foreach Console.println - Console.print("s2: "); s2.lines foreach Console.println - Console.print("s3: "); s3.lines foreach Console.println - Console.print("s4: "); s4.lines foreach Console.println - Console.print("s5: "); s5.lines foreach Console.println + println("\n" + getObjectName + ":") + Console.print("s1: "); s1.lines foreach println + Console.print("s2: "); s2.lines foreach println + Console.print("s3: "); s3.lines foreach println + Console.print("s4: "); s4.lines foreach println + Console.print("s5: "); s5.lines foreach println } } object RichStringTest3 extends RichTest { def run { - Console.println("\n" + getObjectName + ":") - Console.println("s1: " + s1.stripLineEnd) - Console.println("s2: " + s2.stripLineEnd) - Console.println("s3: " + s3.stripLineEnd) - Console.println("s4: " + s4.stripLineEnd) - Console.println("s5: " + s5.stripLineEnd) + println("\n" + getObjectName + ":") + println("s1: " + s1.stripLineEnd) + println("s2: " + s2.stripLineEnd) + println("s3: " + s3.stripLineEnd) + println("s4: " + s4.stripLineEnd) + println("s5: " + s5.stripLineEnd) } } object RichStringTest4 extends RichTest { def run { - Console.println("\n" + getObjectName + ":") - Console.println("s1: " + s1.stripMargin) - Console.println("s2: " + s2.stripMargin) - Console.println("s3: " + s3.stripMargin) - Console.println("s4: " + s4.stripMargin) - Console.println("s5: " + s5.stripMargin) + println("\n" + getObjectName + ":") + println("s1: " + s1.stripMargin) + println("s2: " + s2.stripMargin) + println("s3: " + s3.stripMargin) + println("s4: " + s4.stripMargin) + println("s5: " + s5.stripMargin) } } object RichStringTest5 extends RichTest { def run { - Console.println("\n" + getObjectName + ":") - Console.println("s1: " + s3.stripMargin('#')) - Console.println("s2: " + s3.stripMargin('#')) - Console.println("s3: " + s3.stripMargin('#')) - Console.println("s4: " + s4.stripMargin('#')) - Console.println("s5: " + s5.stripMargin('#')) + println("\n" + getObjectName + ":") + println("s1: " + s3.stripMargin('#')) + println("s2: " + s3.stripMargin('#')) + println("s3: " + s3.stripMargin('#')) + println("s4: " + s4.stripMargin('#')) + println("s5: " + s5.stripMargin('#')) + } +} +object RichStringTest6 extends RichTest { + def run { + println("a:b:c:d".split(':').toList) + println("a.b.c.d".split('.').toList) + println("a$b$c$d".split('$').toList) + println("a^b^c^d".split('^').toList) + println("a\\b\\c\\d".split('\\').toList) + println("a:b:c.d".split(Array(':', '.')).toList) + println("a:b.c$d".split(Array(':', '.', '$')).toList) } } /** xxx */ object Test { - def main(args: Array[String]): Unit = { + def main(args: Array[String]) { RichCharTest1.run //RichCharTest2.run RichIntTest.run @@ -116,5 +127,6 @@ object Test { RichStringTest3.run RichStringTest4.run RichStringTest5.run + RichStringTest6.run } } diff --git a/test/scalatest b/test/scalatest index 720a0beedd..6b9da347ff 100755 --- a/test/scalatest +++ b/test/scalatest @@ -275,9 +275,7 @@ test_run_jvm() { # Test the disassemblers. test_run_dis() { argsfile="$srcbase".args; - if [ ! -f "$argsfile" ]; then - argsfile=/dev/null; - fi; + [ ! -f "$argsfile" ] && argsfile=/dev/null; rm -rf "$dstbase".obj && mkdir -p "$dstbase".obj && $SCALAC -d "$os_dstbase".obj "$@" "$os_srcbase".scala && @@ -297,14 +295,15 @@ test_run_msil() { -sourcepath "$PREFIX/build/msil/src" "$os_srcbase".scala && case "$UNAME" in CYGWIN* ) - ilasm /qui /nol /out="$os_dstbase".$EXE "$os_dstbase".$MSIL \ + $ILASM /qui /nol /out="$os_dstbase".$EXE "$os_dstbase".$MSIL \ > /dev/null && # peverify /il "$os_dstbase".EXE > /dev/null && "$dstbase".$EXE_SUFFIX "msil";; * ) - ilasm /output:"$os_dstbase".$EXE "$os_dstbase".$MSIL \ + $ILASM /output:"$os_dstbase".$EXE "$os_dstbase".$MSIL \ > /dev/null && - env MONO_PATH="$PREFIX/build/msil:$PREFIX/lib" mono "$dstbase.$EXE" "msil";; + monopath=`get_os_pathlist $PREFIX/build/msil:$PREFIX/lib` && + env MONO_PATH="$monopath" $MONO "$dstbase.$EXE" "msil";; esac && rm -f "$dstbase".$EXE && rm -f "$dstbase".$MSIL; @@ -375,19 +374,12 @@ test_check_test() { # compute flags file flagsfile="$srcbase".flags; - if [ ! -f "$flagsfile" ]; then - flagsfile=/dev/null; - fi; + [ ! -f "$flagsfile" ] && flagsfile=/dev/null; # compute check file checkfile="$srcbase"-$kind.check; - if [ ! -f "$checkfile" ]; then - checkfile="$srcbase".check; - fi; - if [ ! -f "$checkfile" ]; then - checkfile=/dev/null; - fi; - + [ ! -f "$checkfile" ] && checkfile="$srcbase".check; + [ ! -f "$checkfile" ] && checkfile=/dev/null; # compute log file logfile="$dstbase".log; @@ -424,15 +416,9 @@ test_check_test() { else FAILURE_COUNT=`echo "$FAILURE_COUNT+1" | bc`; test_print_failure; - if [ ! -f "$logfile" ]; then - logfile=/dev/null; - fi; - if [ "$SHOWLOG" = "true" ]; then - cat "$logfile"; - fi; - if [ "$SHOWDIFF" = "true" ]; then - $DIFF "$logfile" "$checkfile"; - fi; + [ ! -f "$logfile" ] && logfile=/dev/null; + [ "$SHOWLOG" = "true" ] && cat "$logfile"; + [ "$SHOWDIFF" = "true" ] && $DIFF "$logfile" "$checkfile"; fi; } @@ -457,9 +443,7 @@ test_check_kind() { [ -z "$file" ] && continue; test_check_file "$file"; done - if [ -z "$header" ]; then - echo ""; - fi; + [ -z "$header" ] && echo ""; } # Checks everything. @@ -739,6 +723,8 @@ fi; SCALAC="$SCALAC_CMD $SCALAC_OPTS"; SCALAP="scalap"; ANT="ant"; +ILASM="ilasm"; +MONO="mono"; if [ -n "$OBJDIR" ]; then if [ -d "$OBJDIR" ] || mkdir -p "$OBJDIR"; then @@ -759,7 +745,7 @@ scala_version=`${SCALAC_CMD} -version 2>&1` printf_outline "Scala version is : $scala_version\\n"; [ -n "$SCALAC_OPTS" ] && printf_outline "Scalac options are : $SCALAC_OPTS\\n"; -javacmd=`which $JAVACMD`; +javacmd=`which $JAVACMD 2>/dev/null`; bin_dir=`test_get_location $javacmd`; printf_outline "Java binaries in : $bin_dir\\n"; if [ "$GIJ" = "true" ]; then -- cgit v1.2.3