diff options
author | Philipp Haller <hallerp@gmail.com> | 2009-11-03 17:00:06 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2009-11-03 17:00:06 +0000 |
commit | 13d642151f0ad834fad3e8868608d5af5b4372bc (patch) | |
tree | 0bc45ab5991d241ca30be61c09c70e56142b76e5 | |
parent | d7f7a3e001fb825240554a02a7cff72bef96f409 (diff) | |
download | scala-13d642151f0ad834fad3e8868608d5af5b4372bc.tar.gz scala-13d642151f0ad834fad3e8868608d5af5b4372bc.tar.bz2 scala-13d642151f0ad834fad3e8868608d5af5b4372bc.zip |
Fix and test for #2527
-rw-r--r-- | src/library/scala/Enumeration.scala | 11 | ||||
-rw-r--r-- | test/files/run/enums.check | 1 | ||||
-rw-r--r-- | test/files/run/enums.scala | 20 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 8d38f71f79..d5153bd50d 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -121,9 +121,14 @@ abstract class Enumeration(initial: Int, names: String*) { * initialize each Enumeration with Value(String). Otherwise, the * names are determined automatically through reflection. * - * @param s an enumeration name - * @return <tt>Some(Value)</tt> if an enumeration's name matches <var>s</var>, - * else <tt>None</tt> + * Note the change here wrt 2.7 is intentional. You should know whether + * a name is in an Enumeration beforehand. If not, just use find on + * values. + * + * @param s an Enumeration name + * @return the Value of this Enumeration if its name matches <var>s</var> + * @throws java.util.NoSuchElementException if no Value with a matching + * name is in this Enumeration */ final def withName(s: String): Value = values.find(_.toString == s).get diff --git a/test/files/run/enums.check b/test/files/run/enums.check index b76705b9dd..f53aba8794 100644 --- a/test/files/run/enums.check +++ b/test/files/run/enums.check @@ -1,4 +1,5 @@ test Test1 was successful test Test2 was successful test Test3 was successful +test Test4 was successful diff --git a/test/files/run/enums.scala b/test/files/run/enums.scala index 99986787b7..fcca8d3438 100644 --- a/test/files/run/enums.scala +++ b/test/files/run/enums.scala @@ -46,6 +46,25 @@ object Test3 { } } +object Test4 { + + object Direction extends Enumeration("North", "South", "East", "West") { + val North, South, East, West = Value; + } + + def run: Int = { + val dir = Direction.withName("North") + assert(dir.toString == "North") + try { + Direction.withName("Nord") + assert(false) + } catch { + case e: Exception => /* do nothing */ + } + 0 + } +} + //############################################################################ // Test code @@ -73,6 +92,7 @@ object Test { check_success("Test1", Test1.run, 5); check_success("Test2", Test2.run, 5); check_success("Test3", Test3.run, 1); + check_success("Test4", Test4.run, 0); Console.println; } } |