From c3d125891f7707cd8b47786bfd063760508b009a Mon Sep 17 00:00:00 2001 From: Aleksandar Pokopec Date: Mon, 25 Jan 2010 19:22:06 +0000 Subject: Fixes #2766. Review by phaller. --- test/files/run/ReplacementMatching.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test/files/run') diff --git a/test/files/run/ReplacementMatching.scala b/test/files/run/ReplacementMatching.scala index ab14202871..64a912392b 100644 --- a/test/files/run/ReplacementMatching.scala +++ b/test/files/run/ReplacementMatching.scala @@ -1,7 +1,7 @@ - +import util.matching._ @@ -9,6 +9,11 @@ object Test { def main(args: Array[String]) { + replacementMatching + groupsMatching + } + + def replacementMatching { val regex = """\$\{(.+?)\}""".r val replaced = regex.replaceAllMatchDataIn("Replacing: ${main}. And another method: ${foo}.", (m: util.matching.Regex.Match) => { @@ -24,4 +29,18 @@ object Test { assert(replaced2 == "Replacing: main. And then one more: bar.") } + def groupsMatching { + val Date = """(\d+)/(\d+)/(\d+)""".r + for (Regex.Groups(a, b, c) <- Date findFirstMatchIn "1/1/2001 marks the start of the millenium. 31/12/2000 doesn't.") { + assert(a == "1") + assert(b == "1") + assert(c == "2001") + } + for (Regex.Groups(a, b, c) <- (Date findAllIn "1/1/2001 marks the start of the millenium. 31/12/2000 doesn't.").matchData) { + assert(a == "1" || a == "31") + assert(b == "1" || b == "12") + assert(c == "2001" || c == "2000") + } + } + } -- cgit v1.2.3