diff options
author | Paul Phillips <paulp@improving.org> | 2012-05-02 14:20:14 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-05-02 15:20:56 -0700 |
commit | 00b22ed4a307b3c49a09a03508a28a933aeb1a9f (patch) | |
tree | c778f40a4d2006972b72b1bf08841eb16ceabb79 /test | |
parent | bf0f008df8feb8357fcad9aa455ff63b409d59bf (diff) | |
parent | 1475df9bedc03417708f20d94b5e3db5c80f3036 (diff) | |
download | scala-00b22ed4a307b3c49a09a03508a28a933aeb1a9f.tar.gz scala-00b22ed4a307b3c49a09a03508a28a933aeb1a9f.tar.bz2 scala-00b22ed4a307b3c49a09a03508a28a933aeb1a9f.zip |
Merge branch 'may2' of /scala/trunk into develop
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/si5045.check | 6 | ||||
-rw-r--r-- | test/files/run/si5045.scala | 46 |
2 files changed, 52 insertions, 0 deletions
diff --git a/test/files/run/si5045.check b/test/files/run/si5045.check new file mode 100644 index 0000000000..7e9c1961b7 --- /dev/null +++ b/test/files/run/si5045.check @@ -0,0 +1,6 @@ + extract an exact match 2011-07-15 2011-07-15 + extract from middle of string 2011-07-15 2011-07-15 + extract from middle of string (P2) 2011-07-15 2011-07-15 + extract from middle of string (P3) 2011-07-15 2011-07-15 + copyright example has date Copyright 2011 Copyright 2011 + copyright example missing date No copyright No copyright diff --git a/test/files/run/si5045.scala b/test/files/run/si5045.scala new file mode 100644 index 0000000000..e198b101f3 --- /dev/null +++ b/test/files/run/si5045.scala @@ -0,0 +1,46 @@ +object Test extends App { + + import scala.util.matching.{ Regex, UnanchoredRegex } + + val dateP1 = """(\d\d\d\d)-(\d\d)-(\d\d)""".r.unanchored + val dateP2 = """(\d\d\d\d)-(\d\d)-(\d\d)""" r ("year", "month", "day") unanchored + val dateP3 = new Regex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day") with UnanchoredRegex + + val yearStr = "2011" + val dateStr = List(yearStr,"07","15").mkString("-") + + def test(msg: String)(strs: Seq[String]): Unit = println("%40s %s".format(msg, strs mkString " ")) + + test("extract an exact match") { + val dateP1(y,m,d) = dateStr + Seq(List(y,m,d).mkString("-"), dateStr) + } + + test("extract from middle of string") { + val dateP1(y,m,d) = "Tested on "+dateStr+"." + Seq(List(y,m,d).mkString("-"), dateStr) + } + + test("extract from middle of string (P2)") { + val dateP2(y,m,d) = "Tested on "+dateStr+"." + Seq(List(y,m,d).mkString("-"), dateStr) + } + + test("extract from middle of string (P3)") { + val dateP2(y,m,d) = "Tested on "+dateStr+"." + Seq(List(y,m,d).mkString("-"), dateStr) + } + + def copyright(in: String): String = in match { + case dateP1(year, month, day) => "Copyright "+year + case _ => "No copyright" + } + + test("copyright example has date") { + Seq(copyright("Date of this document: "+dateStr), "Copyright "+yearStr) + } + + test("copyright example missing date") { + Seq(copyright("Date of this document: unknown"), "No copyright") + } +} |