diff options
author | Som Snytt <som.snytt@gmail.com> | 2014-08-08 21:36:27 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2014-08-08 21:36:27 -0700 |
commit | cd2394ee43220e885bfa92f3ce34f41366bb4704 (patch) | |
tree | abc2f880a05d3d70c0558f74dcf3933386c5a614 /test | |
parent | 50167e3f1df664165a2ad485abace5dbce623996 (diff) | |
download | scala-cd2394ee43220e885bfa92f3ce34f41366bb4704.tar.gz scala-cd2394ee43220e885bfa92f3ce34f41366bb4704.tar.bz2 scala-cd2394ee43220e885bfa92f3ce34f41366bb4704.zip |
SI-8787 If you love nulls, so does Regex
Regex is robust when unapplying null. A null never matches.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/util/matching/RegexTest.scala | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/junit/scala/util/matching/RegexTest.scala b/test/junit/scala/util/matching/RegexTest.scala index d25842cc57..5b13397d6a 100644 --- a/test/junit/scala/util/matching/RegexTest.scala +++ b/test/junit/scala/util/matching/RegexTest.scala @@ -27,4 +27,21 @@ class RegexTest { assertEquals("1", x) assertEquals("1", y) } + + @Test def t8787nullMatch() = { + val r = """\d+""".r + val s: String = null + val x = s match { case r() => 1 ; case _ => 2 } + assertEquals(2, x) + } + + @Test def t8787nullMatcher() = { + val r = """(\d+):(\d+)""".r + val s = "1:2 3:4 5:6" + val z = ((r findAllMatchIn s).toList :+ null) flatMap { + case r(x, y) => Some((x.toInt, y.toInt)) + case _ => None + } + assertEquals(List((1,2),(3,4),(5,6)), z) + } } |