Skip to content

Instantly share code, notes, and snippets.

@olabini
Created September 22, 2009 13:27
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 olabini/191064 to your computer and use it in GitHub Desktop.
Save olabini/191064 to your computer and use it in GitHub Desktop.
Then = Origin mimic
Then allThens = []
Then match = method(inputText,
allThens each(th,
if(th pattern =~ inputText,
th code call(*(it names map(nm, it[nm]))))))
then = dmacro(
[>pattern, code]
messages = pattern names map(nm,
Message fromText(nm asText))
messages << code
lexicalCode = LexicalBlock createFrom(messages, call ground)
Then allThens << Then with(pattern: pattern, code: lexicalCode)
)
then(#/I should have ({cukes}.*) cukes in my belly/,
cukes println)
then(#/I should have ({howMany}\d+) ({itemName}.*) in my belly/,
"got #{howMany} #{itemName}" println)
Then match("I should have 42 cukes in my belly")
Then match("I should have 25 banananananananas in my belly")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment