From 89bacb9c25a58454ff1878e67f7ea07ffc8c269f Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 12 May 2015 18:30:53 +0200 Subject: Run tests as they were in scala. --- tests/pending/run/t0325.scala | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/pending/run/t0325.scala (limited to 'tests/pending/run/t0325.scala') diff --git a/tests/pending/run/t0325.scala b/tests/pending/run/t0325.scala new file mode 100644 index 000000000..a126a3a20 --- /dev/null +++ b/tests/pending/run/t0325.scala @@ -0,0 +1,53 @@ +case class RS(self: String) { + + // NB. "\\Q" + '\\' + "\\E" works on Java 1.5 and newer, but not on Java 1.4 + private def escape(ch: Char): String = ch match { + case '\\' => "\\\\" + case _ => "\\Q"+ch+"\\E" + } + + def split(separator: Char): Array[String] = self.split(escape(separator)) + + def split(separators: Array[Char]): Array[String] = { + val re = separators.foldLeft("[")(_+escape(_)) + "]" + 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) + else + println(ret) + } catch { + case e: Throwable => 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 + "\")") + } +} -- cgit v1.2.3