Skip to content

Commit

Permalink
More improvements on style
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydmeta committed Feb 20, 2015
1 parent c1e99cd commit a14137b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions enumeratum-play/src/test/scala/enumeratum/FormSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package enumeratum

import org.scalatest._
import play.api.data.Form
import org.scalatest.OptionValues._

/**
* Created by Lloyd on 2/3/15.
Expand All @@ -17,8 +18,8 @@ class FormSpec extends FunSpec with Matchers {
it("should bind proper strings into an Enum value") {
val r1 = subject.bind(Map("hello" -> "A"))
val r2 = subject.bind(Map("hello" -> "B"))
r1.value.get shouldBe Dummy.A
r2.value.get shouldBe Dummy.B
r1.value.value shouldBe Dummy.A
r2.value.value shouldBe Dummy.B
}

it("should fail to bind random strings") {
Expand Down
5 changes: 3 additions & 2 deletions enumeratum-play/src/test/scala/enumeratum/JsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package enumeratum

import org.scalatest.{ Matchers, FunSpec }
import play.api.libs.json.{ JsNumber, JsString }
import org.scalatest.OptionValues._

class JsonSpec extends FunSpec with Matchers {

describe("reads") {
val reads = Json.reads(Dummy)

it("should create a reads that works with valid values") {
reads.reads(JsString("A")).get should be(Dummy.A)
reads.reads(JsString("A")).asOpt.value should be(Dummy.A)
}

it("should create a reads that fails with invalid values") {
Expand All @@ -30,7 +31,7 @@ class JsonSpec extends FunSpec with Matchers {
val format = Json.formats(Dummy)

it("should create a format that works with valid values") {
format.reads(JsString("A")).get should be(Dummy.A)
format.reads(JsString("A")).asOpt.get should be(Dummy.A)
}

it("should create a format that fails with invalid values") {
Expand Down
9 changes: 6 additions & 3 deletions macros/src/main/scala/enumeratum/EnumMacros.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package enumeratum

import scala.reflect.macros.Context // TODO switch to blackbox.Context when dropping support for 2.10.x
import scala.reflect.macros.Context
import scala.util.control.NonFatal

// TODO switch to blackbox.Context when dropping support for 2.10.x

object EnumMacros {

Expand Down Expand Up @@ -46,12 +49,12 @@ object EnumMacros {
case _ => false
}
} catch {
case e: Throwable =>
case NonFatal(e) =>
c.warning(c.enclosingPosition, s"Got an exception, indicating a possible bug in Enumeratum. Message: ${e.getMessage}")
false
}
}.map(_.symbol)
} catch { case e: Throwable => c.abort(c.enclosingPosition, s"Unexpected error: ${e.getMessage}") }
} catch { case NonFatal(e) => c.abort(c.enclosingPosition, s"Unexpected error: ${e.getMessage}") }
if (!enclosingBodySubclasses.forall(x => x.isModule))
c.abort(c.enclosingPosition, "All subclasses must be objects.")
else enclosingBodySubclasses
Expand Down

0 comments on commit a14137b

Please sign in to comment.