Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Seq tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaf committed Jan 1, 2011
1 parent 8afe631 commit dacf66c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/main/scala/salat/Field.scala
Expand Up @@ -16,15 +16,18 @@ 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
}
}

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
}
}
Expand Down
46 changes: 42 additions & 4 deletions src/test/scala/salat/SalatSpec.scala
Expand Up @@ -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)
}
}
}
}
}
8 changes: 4 additions & 4 deletions src/test/scala/salat/TestModel.scala
Expand Up @@ -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])
Expand Down

0 comments on commit dacf66c

Please sign in to comment.