Permalink
Browse files

WIP for supporting isA in Box for primitives

  • Loading branch information...
1 parent a780731 commit 2e1dc8350df1fb46cb35dc9e5559ea59b8f17f51 @dpp dpp committed Feb 22, 2011
@@ -59,6 +59,16 @@ object Box extends BoxTrait
* It also provides implicit methods to transform Option to Box, Box to Iterable, and Box to Option
*/
sealed trait BoxTrait {
+ val primativeMap: Map[Class[_], Class[_]] = Map(
+ java.lang.Boolean.TYPE -> classOf[java.lang.Boolean],
+ java.lang.Character.TYPE -> classOf[java.lang.Character],
+ java.lang.Byte.TYPE -> classOf[java.lang.Byte],
+ java.lang.Double.TYPE -> classOf[java.lang.Double],
+ java.lang.Float.TYPE -> classOf[java.lang.Float],
+ java.lang.Integer.TYPE -> classOf[java.lang.Integer],
+ java.lang.Long.TYPE -> classOf[java.lang.Long],
+ java.lang.Short.TYPE -> classOf[java.lang.Short])
+
/**
* Create a Box from the specified Option.
* @return a Box created from an Option. Full(x) if the Option is Some(x) and Empty otherwise
@@ -147,6 +147,47 @@ object BoxSpec extends Specification {
"define a 'asA' method returning Empty if the value is not the instance of a given type" in {
Full("s").asA[Double] must_== Empty
}
+
+ "define a 'asA' method must work with Boolean" in {
+ Full(true).asA[Boolean] must_== Full(true)
+ Full(3).asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Character" in {
+ Full('a').asA[Char] must_== Full('a')
+ Full('a').asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Byte" in {
+ Full(3.toByte).asA[Byte] must_== Full(3.toByte)
+ Full(3.toByte).asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Double" in {
+ Full(44d).asA[Double] must_== Full(44D)
+ Full(44d).asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Float" in {
+ Full(32f).asA[Float] must_== Full(32f)
+ Full(33f).asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Integer" in {
+ Full(3).asA[Int] must_== Full(3)
+ Full(3).asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Long" in {
+ Full(32L).asA[Long] must_== Full(32L)
+ Full(32L).asA[Boolean] must_== Empty
+ }
+
+ "define a 'asA' method must work with Short" in {
+ Full(8.toShort).asA[Short] must_== Full(8.toShort)
+ Full(8.toShort).asA[Boolean] must_== Empty
+ }
+
}
"An Empty Box" should {
"beEmpty" in {

0 comments on commit 2e1dc83

Please sign in to comment.