diff options
author | Som Snytt <som.snytt@gmail.com> | 2015-02-20 16:46:00 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-02-20 17:22:33 -0800 |
commit | 80362f9fc2dfa1c9d5560ad2aa8b2eef320e5fd6 (patch) | |
tree | 97a955f7778dfd4fc01b758d4d62cf35beb692e3 /test | |
parent | 178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff) | |
download | scala-80362f9fc2dfa1c9d5560ad2aa8b2eef320e5fd6.tar.gz scala-80362f9fc2dfa1c9d5560ad2aa8b2eef320e5fd6.tar.bz2 scala-80362f9fc2dfa1c9d5560ad2aa8b2eef320e5fd6.zip |
SI-9167 Clarify ScalaVersion parsing
Probably it was unintended to accept "2.." and "2.-11.7".
This commit makes it a bit more regular and also accepts arbitrary
text after the dash in the build string, including newlines.
Since the number parts must be numbers, accept only digits.
That also disallows "2.+11.7", which could be misconstrued as
some sort of range.
As before, the special build string prefixes "rc" and "m" are
case-insensitive, but "FINAL" is not.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/classfile-format-51.scala | 1 | ||||
-rw-r--r-- | test/files/run/classfile-format-52.scala | 1 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala | 44 |
3 files changed, 43 insertions, 3 deletions
diff --git a/test/files/run/classfile-format-51.scala b/test/files/run/classfile-format-51.scala index 24b1ee8397..4351757a64 100644 --- a/test/files/run/classfile-format-51.scala +++ b/test/files/run/classfile-format-51.scala @@ -1,6 +1,5 @@ import java.io.{File, FileOutputStream} -import scala.tools.nsc.settings.ScalaVersion import scala.tools.partest._ import scala.tools.asm import asm.{AnnotationVisitor, ClassWriter, FieldVisitor, Handle, MethodVisitor, Opcodes} diff --git a/test/files/run/classfile-format-52.scala b/test/files/run/classfile-format-52.scala index e12c84124c..6646e081c4 100644 --- a/test/files/run/classfile-format-52.scala +++ b/test/files/run/classfile-format-52.scala @@ -1,6 +1,5 @@ import java.io.{File, FileOutputStream} -import scala.tools.nsc.settings.ScalaVersion import scala.tools.partest._ import scala.tools.asm import asm.{AnnotationVisitor, ClassWriter, FieldVisitor, Handle, MethodVisitor, Opcodes} diff --git a/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala b/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala index 77a2da828e..acbf39fe23 100644 --- a/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala +++ b/test/junit/scala/tools/nsc/settings/ScalaVersionTest.scala @@ -13,6 +13,48 @@ class ScalaVersionTest { @Test def versionUnparse() { val v = "2.11.3" - assertEquals(ScalaVersion(v).unparse, v) + assertEquals(v, ScalaVersion(v).unparse) + assertEquals("2.11.3-RC4", ScalaVersion("2.11.3-rc4").unparse) + } + + // SI-9167 + @Test def `version parses with rigor`() { + import settings.{ SpecificScalaVersion => V } + import ScalaVersion._ + + // no-brainers + assertEquals(V(2,11,7,Final), ScalaVersion("2.11.7")) + assertEquals(V(2,11,7,Final), ScalaVersion("2.11.7-FINAL")) + assertEquals(V(2,11,7,Milestone(3)), ScalaVersion("2.11.7-M3")) + assertEquals(V(2,11,7,RC(3)), ScalaVersion("2.11.7-RC3")) + assertEquals(V(2,11,7,Development("devbuild")), ScalaVersion("2.11.7-devbuild")) + + // partial-brainers + assertEquals(V(2,11,7,Milestone(3)), ScalaVersion("2.11.7-m3")) + assertEquals(V(2,11,7,RC(3)), ScalaVersion("2.11.7-rc3")) + assertEquals(V(2,11,7,Development("maybegood")), ScalaVersion("2.11.7-maybegood")) + assertEquals(V(2,11,7,Development("RCCola")), ScalaVersion("2.11.7-RCCola")) + assertEquals(V(2,11,7,Development("RC1.5")), ScalaVersion("2.11.7-RC1.5")) + assertEquals(V(2,11,7,Development("")), ScalaVersion("2.11.7-")) + assertEquals(V(2,11,7,Development("0.5")), ScalaVersion("2.11.7-0.5")) + assertEquals(V(2,11,7,Development("devbuild\nSI-9167")), ScalaVersion("2.11.7-devbuild\nSI-9167")) + assertEquals(V(2,11,7,Development("final")), ScalaVersion("2.11.7-final")) + + // oh really + assertEquals(NoScalaVersion, ScalaVersion("none")) + assertEquals(AnyScalaVersion, ScalaVersion("any")) + + assertThrows[NumberFormatException] { ScalaVersion("2.11.7.2") } + assertThrows[NumberFormatException] { ScalaVersion("2.11.7.beta") } + assertThrows[NumberFormatException] { ScalaVersion("2.x.7") } + assertThrows[NumberFormatException] { ScalaVersion("2.-11.7") } + assertThrows[NumberFormatException] { ScalaVersion("2. ") } + assertThrows[NumberFormatException] { ScalaVersion("2.1 .7") } + assertThrows[NumberFormatException] { ScalaVersion("2.") } + assertThrows[NumberFormatException] { ScalaVersion("2..") } + assertThrows[NumberFormatException] { ScalaVersion("2...") } + assertThrows[NumberFormatException] { ScalaVersion("2-") } + assertThrows[NumberFormatException] { ScalaVersion("2-.") } // scalacheck territory + assertThrows[NumberFormatException] { ScalaVersion("any.7") } } } |