diff --git a/src/main/scala/salat/Field.scala b/src/main/scala/salat/Field.scala index c5f4a48e..46233f93 100644 --- a/src/main/scala/salat/Field.scala +++ b/src/main/scala/salat/Field.scala @@ -16,7 +16,7 @@ object IsOption { object IsMap { def unapply(t: Type): Option[(Type, Type)] = t match { - case TypeRefType(_, symbol, k :: v :: Nil) if symbol.path.endsWith("\\.Map") => Some(k -> v) + case TypeRefType(_, symbol, k :: v :: Nil) if symbol.path.endsWith(".Map") => Some(k -> v) case _ => None } } @@ -24,7 +24,10 @@ object IsMap { object IsSeq { def unapply(t: Type): Option[Type] = t match { - case TypeRefType(_, symbol, List(e)) if symbol.path.endsWith("\\.Seq") => Some(e) + case TypeRefType(_, symbol, List(e)) => + if (symbol.path.endsWith(".Seq")) Some(e) + else if (symbol.path.endsWith(".List")) Some(e) + else None case _ => None } } diff --git a/src/test/scala/salat/SalatSpec.scala b/src/test/scala/salat/SalatSpec.scala index 872e84ab..a7dcaeb9 100644 --- a/src/test/scala/salat/SalatSpec.scala +++ b/src/test/scala/salat/SalatSpec.scala @@ -51,11 +51,49 @@ class SalatSpec extends Specification with PendingUntilFixed with CasbahLogging } "correctly detect Map[_, _]" in { - fail - } pendingUntilFixed + "with primitive value type" in { + val arg = implicitly[Grater[D]].names("i").typeRefType match { + case IsMap(k, v @ TypeRefType(_,_,_)) => Some(v) + case _ => None + } + arg must beSome[TypeRefType].which { + t => t.symbol.path.split("\\.").last must_== "Int" + } + } + + "with something in context" in { + val arg = implicitly[Grater[D]].names("h").typeRefType match { + case IsMap(k, v @ TypeRefType(_,_,_)) => Some(v) + case _ => None + } + arg must beSome[TypeRefType].which { + t => t.symbol.path must_== classOf[A].getName + implicitly[Grater[D]].ctx.graters must haveKey(t.symbol.path) + } + } + } "correctly detect Seq[_]" in { - fail - } pendingUntilFixed + "with primitive value type" in { + val arg = implicitly[Grater[C]].names("l").typeRefType match { + case IsSeq(e @ TypeRefType(_,_,_)) => Some(e) + case _ => None + } + arg must beSome[TypeRefType].which { + t => t.symbol.path.split("\\.").last must_== "String" + } + } + + "with something in context" in { + val arg = implicitly[Grater[C]].names("n").typeRefType match { + case IsSeq(e @ TypeRefType(_,_,_)) => Some(e) + case _ => None + } + arg must beSome[TypeRefType].which { + t => t.symbol.path must_== classOf[D].getName + implicitly[Grater[C]].ctx.graters must haveKey(t.symbol.path) + } + } + } } } diff --git a/src/test/scala/salat/TestModel.scala b/src/test/scala/salat/TestModel.scala index ffcc175c..c6867119 100644 --- a/src/test/scala/salat/TestModel.scala +++ b/src/test/scala/salat/TestModel.scala @@ -10,10 +10,10 @@ import com.bumnetworks.salat.test._ import scala.collection.immutable.{Map => IMap} import scala.collection.mutable.{Map => MMap} -case class A(x: String, y: Option[String], z: B) -case class B(p: Option[Int], q: Int, r: C) -case class C(l: Seq[String], m: List[Int], n: List[D]) -case class D(h: IMap[String, A], i: MMap[String, C], j: Option[B]) +case class A(x: String, y: Option[String], z: B) +case class B(p: Option[Int], q: Int, r: C) +case class C(l: Seq[String], m: List[Int], n: List[D]) +case class D(h: IMap[String, A], i: MMap[String, Int], j: Option[B]) object `package` { implicit object GraterA extends Grater(classOf[A])