diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-08-14 13:29:10 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-08-14 13:29:10 -0700 |
commit | 5bdb828a2ef3fa874c2c19e8415d3d670c022ae1 (patch) | |
tree | 13618fa2427a03feb4237baed184dd5f17a6a9df /test | |
parent | 275194a62989115e065ff69c41942f113db8b8f7 (diff) | |
parent | 93e9623f5babee93c50eb1ce82e443d6771b693d (diff) | |
download | scala-5bdb828a2ef3fa874c2c19e8415d3d670c022ae1.tar.gz scala-5bdb828a2ef3fa874c2c19e8415d3d670c022ae1.tar.bz2 scala-5bdb828a2ef3fa874c2c19e8415d3d670c022ae1.zip |
Merge pull request #2819 from som-snytt/issue/regextract-char
SI-7737 Regex matches Char
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/util/matching/regextract-char.scala | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/junit/scala/util/matching/regextract-char.scala b/test/junit/scala/util/matching/regextract-char.scala new file mode 100644 index 0000000000..50fdcd9d46 --- /dev/null +++ b/test/junit/scala/util/matching/regextract-char.scala @@ -0,0 +1,58 @@ + +package scala.util.matching + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import PartialFunction._ + +/** Regex can match a Char. + * If the pattern includes a group, + * always return a single char. + */ +@RunWith(classOf[JUnit4]) +class CharRegexTest { + implicit class Averrable(val b: Boolean) /*extends AnyVal*/ { + def yes = assert(b) + def no = assert(!b) + } + val c: Char = 'c' // "cat"(0) + val d: Char = 'D' // "Dog"(0) + + @Test def comparesGroupCorrectly(): Unit = { + val r = """(\p{Lower})""".r + cond(c) { case r(x) => true } .yes + cond(c) { case r(_) => true } .yes + cond(c) { case r(_*) => true } .yes + cond(c) { case r() => true } .no + + cond(d) { case r(x) => true } .no + cond(d) { case r(_) => true } .no + cond(d) { case r(_*) => true } .no + cond(d) { case r() => true } .no + } + + @Test def comparesNoGroupCorrectly(): Unit = { + val rnc = """\p{Lower}""".r + cond(c) { case rnc(x) => true } .no + cond(c) { case rnc(_) => true } .no + cond(c) { case rnc(_*) => true } .yes + cond(c) { case rnc() => true } .yes + + cond(d) { case rnc(x) => true } .no + cond(d) { case rnc(_) => true } .no + cond(d) { case rnc(_*) => true } .no + cond(d) { case rnc() => true } .no + } + + @Test(expected = classOf[MatchError]) + def failCorrectly(): Unit = { + val headAndTail = """(\p{Lower})([a-z]+)""".r + val n = "cat"(0) match { + case headAndTail(ht @ _*) => ht.size + } + assert(false, s"Match size $n") + } +} |