summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-06-20 09:41:08 -0700
committerSom Snytt <som.snytt@gmail.com>2013-07-04 12:40:56 -0700
commit06606e83dc942693dd95a30f704876c41eb4d8e5 (patch)
treead303e79331ba9b714e4d72c024d4ca4ec0149c0 /test/files
parentd0df4c514f662312e2a9284fef2cf24a284aff28 (diff)
downloadscala-06606e83dc942693dd95a30f704876c41eb4d8e5.tar.gz
scala-06606e83dc942693dd95a30f704876c41eb4d8e5.tar.bz2
scala-06606e83dc942693dd95a30f704876c41eb4d8e5.zip
SI-7265 General test for spec version
The test for isJavaAtLeast uses the specification.version. The method argument must have the form "major.minor". The scaladoc is updated to reflect the new reality and a test is added under junit. Note that this implementation aims to be a simple compromise between the functional and imperative camps, that is, to be free of both closures and while loops. And to elicit no cruft like regexes and wrappers for strings. No doubt even more could be done in this department, but we don't wish to spoil the fun on codegolf.stackexchange.com. However, we might decide to sponsor a new site: codereviewpingpong.com For 2.10.x, javaSpecVersion is provided as a private member. The active test is under `run` and the `junit` test must bide its time in `pending`. For 2.11, the private members can be public and the app test replaced with the unit test.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/t7265.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/files/run/t7265.scala b/test/files/run/t7265.scala
new file mode 100644
index 0000000000..c556930303
--- /dev/null
+++ b/test/files/run/t7265.scala
@@ -0,0 +1,27 @@
+
+import scala.util.Properties._
+
+object Test extends App {
+
+ setProp("java.specification.version", "1.7")
+
+ assert( isJavaAtLeast("1.5"))
+ assert( isJavaAtLeast("1.6"))
+ assert( isJavaAtLeast("1.7"))
+ assert(!isJavaAtLeast("1.8"))
+ assert(!isJavaAtLeast("1.71"))
+
+ failing(isJavaAtLeast("1.a"))
+ failing(isJavaAtLeast("1"))
+ failing(isJavaAtLeast(""))
+ failing(isJavaAtLeast("."))
+ failing(isJavaAtLeast(".5"))
+ failing(isJavaAtLeast("1.7.1"))
+
+ def failing(u: =>Unit) = try {
+ u
+ assert(false, "Expected Exception")
+ } catch {
+ case _: NumberFormatException =>
+ }
+}