diff options
Diffstat (limited to 'test/files/run/ReplacementMatching.scala')
-rw-r--r-- | test/files/run/ReplacementMatching.scala | 21 |
1 files changed, 20 insertions, 1 deletions
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") + } + } + } |