Skip to content

Instantly share code, notes, and snippets.

@jroper
Created April 22, 2012 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jroper/2464615 to your computer and use it in GitHub Desktop.
Save jroper/2464615 to your computer and use it in GitHub Desktop.
ScalaFlect - The new strongly typed reflection library I'm writing for using in query DSLs
package au.id.jazzy.scalaflect
import org.specs2.mutable.Specification
object ScalaFlectSpec extends Specification {
"ScalaFlect" should {
"be able to look up simple case class properties" in {
val exampleCaseClass = new ScalaFlect(classOf[ExampleCaseClass])
val member = exampleCaseClass.reflect(_.property)
member.toString mustEqual "property"
}
"be able to follow a path of case class properties" in {
val exampleCaseClassParent = new ScalaFlect(classOf[ExampleCaseClassParent])
val member = exampleCaseClassParent.reflect(_.example.property)
member.toString mustEqual "example.property"
}
"be able to look up simple class properties" in {
val exampleClass = new ScalaFlect(classOf[ExampleClass])
val member = exampleClass.reflect(_.property)
member.toString mustEqual "property"
}
"be able to follow a path of class properties" in {
val exampleClassParent = new ScalaFlect(classOf[ExampleClassParent])
val member = exampleClassParent.reflect(_.example.property)
member.toString mustEqual "example.property"
}
}
}
case class ExampleCaseClass(property: String)
case class ExampleCaseClassParent(example: ExampleCaseClass)
class ExampleClass(val property: String)
class ExampleClassParent(val example: ExampleClass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment