Created
August 4, 2009 06:54
-
-
Save stoyle/161064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import reflect.Manifest | |
object CucumberScalaDsl extends Application { | |
/* Revision. Does not work because Manifest.classType uses erased types. | |
Hence you will get a ClassCastException when using a double in stead of an integer for example. | |
Thanks fredriv for spotting this! | |
type stringFunction = Function1[String, Unit] | |
type intStringFunction = Function2[Int, String, Unit] | |
// Uses experimental Manifest type, provided by the compiler | |
def Given[T](name: String)(proc: T)(implicit m: scala.reflect.Manifest[T]) { | |
if(m >:> Manifest.classType(classOf[intStringFunction])) proc.asInstanceOf[intStringFunction](5, "belly") | |
else if (m >:> Manifest.classType(classOf[stringFunction])) proc.asInstanceOf[stringFunction]("belly") | |
} | |
*/ | |
// Uses experimental Manifest type, provided by the compiler. However checking with Strings aint pretty... | |
def Given[T](name: String)(proc: T)(implicit m: scala.reflect.Manifest[T]) { | |
m.toString match { | |
case "scala.Function2[int, java.lang.String, void]" => proc.asInstanceOf[Function2[Int, String, Unit]](5, "belly") | |
case "scala.Function1[java.lang.String, void]" => proc.asInstanceOf[Function1[String, Unit]]("belly") | |
case _ => | |
} | |
} | |
Given("I have (\\d+) cukes in my (.*)") { (cukes: Int, where: String) => | |
println("You have " + cukes + " cukes in your " + where) | |
} | |
Given("my name is (.*)") { (name: String) => | |
println("Your name is " + name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment