All entries for Monday 12 June 2006
June 12, 2006
BDD Meta–programming
I'm working on a Boo macro library for Rhino Mocks . I'm "dog-fooding" my Specter behaviour driven development framework in the process.I have to be able to specify how a macro should expand into real code. The spec code is now looking like this:
specify "x as int arg is sent as 0":
check(
ast { disallow foo.Bar(x as int) },
ast { foo.Bar(0); Rhino.Mocks.LastCall.Repeat.Never() }
)I'm loving how flexible the Boo language is. It's hard to believe that the code is still Boo!
"check" is a function that expands the first argument using the macro being spec'd and makes sure it matches the second argument. (check is actual a partial application of a general check function that takes the macro first)
check = { input as MacroStatement, expected as Node | CheckMacro(macro, input, expected) }def CheckMacro(macro as AbstractAstMacro, input as MacroStatement, expected as Node):
m = Method()
m.Body.Add(input)
NUnit.Framework.Assert.AreEqual(
expected.ToCodeString().Trim(),
macro.Expand(input).ToCodeString().Trim()
)
Please wait - comments are loading

Loading…