diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-01-25 19:22:06 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-01-25 19:22:06 +0000 |
commit | c3d125891f7707cd8b47786bfd063760508b009a (patch) | |
tree | f33001846d0de1a2be45f4184d160794c29f3b91 /test/files/run | |
parent | 6c88e2e2982709f981c26a3e8e935bc44c2fa751 (diff) | |
download | scala-c3d125891f7707cd8b47786bfd063760508b009a.tar.gz scala-c3d125891f7707cd8b47786bfd063760508b009a.tar.bz2 scala-c3d125891f7707cd8b47786bfd063760508b009a.zip |
Fixes #2766. Review by phaller.
Diffstat (limited to 'test/files/run')
-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") + } + } + } |