Skip to content

Commit

Permalink
Write a test for codingwell#42 and related to higher-kinded types.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Jan 22, 2015
1 parent 3c71f40 commit 3bbfeef
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/scala/net/codingwell/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ package object scalaguice {
}

private def isArray[T: TypeTag]: Boolean = synchronized {
isArray(typeOf[T])
isArray(typeTag[T])
}

private def isArray(typ: Type): Boolean = synchronized {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ object Outer {
}
}

import scala.language.higherKinds
class HigherKindedType[T[_]]

trait A
class B extends A

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InjectorExtensionsSpec extends WordSpec with Matchers {
bind[A].annotatedWith(named("d")).to[B]
bind[B].annotatedWith(classOf[Named]).to[B]
bind[Gen[String]].to[C]
bind[HigherKindedType[List]]
}
}

Expand All @@ -53,5 +54,9 @@ class InjectorExtensionsSpec extends WordSpec with Matchers {
"allow instance to be retreived using a type parameter and an annotation class" in {
injector.instance[B, Named]
}

"allow instance of higher order type" in {
injector.instance[HigherKindedType[List]]
}
}
}
20 changes: 20 additions & 0 deletions src/test/scala/net/codingwell/scalaguice/ScalaModuleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ class ScalaModuleSpec extends WordSpec with Matchers {
val say = Guice.createInjector(module).getInstance(classOf[Say])
say.hi("Bob") should be ("Hi Bob")
}

"allow binding of higher-kinded types" in {
val module = new AbstractModule with ScalaModule {
def configure() = {
bind[HigherKindedType[List]]
}
}
Guice.createInjector(module).getInstance(new Key[HigherKindedType[List]] {})
}

"allow binding of differently parameterized higher-kinded types" in {
val module = new AbstractModule with ScalaModule {
def configure() = {
bind[HigherKindedType[List]]
bind[HigherKindedType[Set]]
}
}
Guice.createInjector(module).getInstance(new Key[HigherKindedType[List]] {})
Guice.createInjector(module).getInstance(new Key[HigherKindedType[Set]] {})
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ class ScalaPrivateModuleSpec extends WordSpec with Matchers {
Guice.createInjector(module).getInstance(Key.get(classOf[A],classOf[Named]))
}

"allow binding of higher-order types" in {
val module = new PrivateModule with ScalaPrivateModule {
def configure() = {
bind[HigherKindedType[List]]
expose[HigherKindedType[List]]
}
}
Guice.createInjector(module).getInstance(new Key[HigherKindedType[List]] {})
}

"give a useful error when bound on itself" in {
val module = new PrivateModule with ScalaPrivateModule {
def configure() = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ class TypeLiteralSpec extends FunSpec with Matchers {
it("should handle type parameters that are nested arrays") {
typeLiteral[Array[Array[Int]]] should equal (new TypeLiteral[Array[Array[Int]]] {})
}

it("should handle type parameters of higher-kinded types") {
typeLiteral[HigherKindedType[Set]] should equal (new TypeLiteral[HigherKindedType[Set]] {})
}

it("should handle type parameters of higher-kinded types parameterized with an Array") {
typeLiteral[HigherKindedType[Array]] should equal (new TypeLiteral[HigherKindedType[Array]] {})
}
}
}

0 comments on commit 3bbfeef

Please sign in to comment.