From cd2394ee43220e885bfa92f3ce34f41366bb4704 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Fri, 8 Aug 2014 21:36:27 -0700 Subject: SI-8787 If you love nulls, so does Regex Regex is robust when unapplying null. A null never matches. --- test/junit/scala/util/matching/RegexTest.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/junit') 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) + } } -- cgit v1.2.3