Created
September 22, 2013 20:18
-
-
Save andrewrlee/6663394 to your computer and use it in GitHub Desktop.
Simple Coffeescript substeps style test runner.
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
class Runner | |
constructor: (@steps) -> | |
_execute = (input, name, step) -> | |
args = step.pattern.exec input | |
step.method args.slice(1)... | |
execute : (input) -> _execute(input, name, step) for name, step of @steps \ | |
when input.match step.pattern | |
executeScript : (script) -> @execute statement.trim() for statement in script.split "\n" | |
###################################################################################################### | |
steps = | |
aaa : | |
pattern : /^aaa$/ | |
method : () -> console.log "111" | |
bbb: | |
pattern : /^bbb(.+)kk(.+)$/ | |
method : (val, val2) -> console.log val + " XXX " + val2 | |
run = new Runner(steps) | |
run.execute "aaa" | |
run.executeScript """ | |
aaa | |
ccc | |
bbbaakksdasfkadfjdjvcldajciad | |
aaadvgsfggdaaaafdfdsfaaasdgsg | |
bbbsdsdsadaskkfdfdfef | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment