From 9040cd14a6a8ed9a779648f02ccd49d2de621d81 Mon Sep 17 00:00:00 2001 From: Hanns Holger Rutz Date: Sat, 17 Mar 2018 12:19:03 +0100 Subject: [PATCH] fixes #73 - do not use Enumeration#Value twice with the same id - bump version to 2.0.3-SNAPSHOT - adds ScalaTest test dependency with unit test for #73 --- build.sbt | 10 +++++-- project/build.properties | 2 +- project/plugins.sbt | 2 +- src/main/scala/scala/swing/RichWindow.scala | 2 +- src/test/scala/scala/swing/Issue73.scala | 30 +++++++++++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/test/scala/scala/swing/Issue73.scala diff --git a/build.sbt b/build.sbt index 6d6dddc0..efffc17e 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ scalaModuleSettings name := "scala-swing" -version := "2.0.2-SNAPSHOT" +version := "2.0.3-SNAPSHOT" scalacOptions ++= Seq("-deprecation", "-feature") @@ -20,7 +20,13 @@ mimaPreviousVersion := Some("2.0.0") // set the prompt (for this build) to include the project id. shellPrompt in ThisBuild := { state => Project.extract(state).currentRef.project + "> " } -lazy val swing = project.in( file(".") ) +lazy val swing = project.in(file(".")) + .settings( + libraryDependencies += { + val v = if (scalaVersion.value == "2.13.0-M3") "3.0.5-M1" else "3.0.5" + "org.scalatest" %% "scalatest" % v % "test" + } + ) lazy val examples = project.in( file("examples") ) .dependsOn(swing) diff --git a/project/build.properties b/project/build.properties index 133a8f19..d3f83a36 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.17 +sbt.version=0.13.17 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 314c55af..c2369199 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.13") +addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14") \ No newline at end of file diff --git a/src/main/scala/scala/swing/RichWindow.scala b/src/main/scala/scala/swing/RichWindow.scala index a7fe8bdb..1aa546e8 100644 --- a/src/main/scala/scala/swing/RichWindow.scala +++ b/src/main/scala/scala/swing/RichWindow.scala @@ -121,7 +121,7 @@ object Dialog { object Result extends Enumeration { import JOptionPane._ val Yes : Result.Value = Value(YES_OPTION) - val Ok : Result.Value = Value(OK_OPTION) + val Ok : Result.Value = Yes // N.B. Do not use `Value` because id 0 is already used val No : Result.Value = Value(NO_OPTION) val Cancel: Result.Value = Value(CANCEL_OPTION) val Closed: Result.Value = Value(CLOSED_OPTION) diff --git a/src/test/scala/scala/swing/Issue73.scala b/src/test/scala/scala/swing/Issue73.scala new file mode 100644 index 00000000..a4a73ec5 --- /dev/null +++ b/src/test/scala/scala/swing/Issue73.scala @@ -0,0 +1,30 @@ +package scala.swing + +import org.scalatest.{FlatSpec, Matchers} + +class Issue73 extends FlatSpec with Matchers { + "Enumerations" should "not contain duplicate ids" in { + // the initializers of any of these will through an + // assertion error if an enumeration `Value` id is used twice. + Alignment + BorderPanel.Position + Dialog.Message + Dialog.Options + Dialog.Result + FileChooser.Result + FileChooser.SelectionMode + FlowPanel.Alignment + FormattedTextField.FocusLostBehavior + GridBagPanel.Anchor + GridBagPanel.Fill + ListView.IntervalMode + Orientation + ScrollPane.BarPolicy + TabbedPane.Layout + Table.AutoResizeMode + Table.ElementMode + Table.IntervalMode + event.Key + event.Key.Location + } +}