diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/bug0325.check | 15 | ||||
-rw-r--r-- | test/files/run/bug0325.scala | 45 |
2 files changed, 60 insertions, 0 deletions
diff --git a/test/files/run/bug0325.check b/test/files/run/bug0325.check new file mode 100644 index 0000000000..71d1f3feb5 --- /dev/null +++ b/test/files/run/bug0325.check @@ -0,0 +1,15 @@ + + +RichString split("x]") returned List(a]b) when expecting List(a, b) +RichString split("&&") returned List(a&b) when expecting List(a, b) +RichString split("\x") returned List(a\b) when expecting List(a, b) +RichString split("[x") returned List(a[b) when expecting List(a, b) +RichString split("^x") returned List(a^b) when expecting List(a, b) +RichString split("x-z") returned List(a-b) when expecting List(a, b) + +RS split("x]") returned List(a]b) when expecting List(a, b) +RS split("&&") returned List(a&b) when expecting List(a, b) +RS split("\x") returned List(a\b) when expecting List(a, b) +RS split("[x") returned List(a[b) when expecting List(a, b) +RS split("^x") returned List(a^b) when expecting List(a, b) +RS split("x-z") returned List(a-b) when expecting List(a, b) diff --git a/test/files/run/bug0325.scala b/test/files/run/bug0325.scala new file mode 100644 index 0000000000..18193ff960 --- /dev/null +++ b/test/files/run/bug0325.scala @@ -0,0 +1,45 @@ +case class RS(self: String) { + def split(separator: Char): Array[String] = self.split("\\Q"+separator+"\\E") + + def split(separators: Array[Char]): Array[String] = { + val re = separators.foldLeft("[\\Q")(_+_) + "\\E]" + self.split(re) + } +} + +object Test { + def expect = List("a","b") + def test(f: => Array[String], which: String) { + try { + val ret = f.toList + if (ret != expect) { + println(which + " returned " + ret + " when expecting " + expect) + } + } catch { + case e@_ => println(which + " failed with " + e.getClass) + } + } + + def main(args: Array[String]) { + val badChars = "?*{+([\\^.$" + + for (c <- badChars) + test(("a"+c+"b").split(c),"RichString split('"+ c + "')") + println + + for (c <- badChars) + test(RS("a"+c+"b").split(c),"RS split('"+ c + "')") + println + + val badCases = List( + ']' -> "x]", '&' -> "&&",'\\' -> "\\x", '[' -> "[x", + '^' -> "^x", '-' -> "x-z" + ) + for ((c,str) <- badCases) + test(("a"+c+"b").split(str.toArray),"RichString split(\""+ str + "\")") + println + + for ((c,str) <- badCases) + test(RS("a"+c+"b").split(str.toArray),"RS split(\""+ str + "\")") + } +} |