Created
August 4, 2009 11:15
-
-
Save fredriv/161159 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 | |
import Manifest._ | |
object CucumberScalaDsl extends Application { | |
def genValue(theType: String): Any = | |
theType match { | |
case "int" => 5 | |
case "long" => 123456789L | |
case "java.lang.String" => "belly" | |
} | |
// Uses experimental Manifest type, provided by the compiler | |
def Given[T](name: String)(proc: T)(implicit m: scala.reflect.Manifest[T]) { | |
val func1 = """scala.Function1\[([^ ,]+).+\]""".r | |
val func2 = """scala.Function2\[([^ ,]+), ([^ ,]+).+\]""".r | |
m.toString match { | |
case func1(t1) => proc.asInstanceOf[Any => _](genValue(t1)) | |
case func2(t1, t2) => proc.asInstanceOf[(Any, Any) => _](genValue(t1), genValue(t2)) | |
case _ => println("No test defined for type " + m.toString) | |
} | |
} | |
Given("I have (\\d+) cukes in my (.*)") ( (cukes: Int, where: String) => | |
println("You have " + cukes + " cukes in your " + where) ) | |
Given("I have (\\d+) cukes in my (.*)") ( (cukes: Long, 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