Created
April 19, 2011 23:15
-
-
Save aslakhellesoy/929952 to your computer and use it in GitHub Desktop.
A little example illustrating how to lex a Gherkin file with node.js
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
// First: npm install gherkin | |
// Usage: node cukelite.js path/to/some.feature | |
var fs = require('fs'); | |
var Lexer = require('gherkin').Lexer('en'); | |
var lexer = new Lexer({ | |
comment: function(value, line) { | |
console.log(value); | |
}, | |
tag: function(value, line) { | |
console.log(value); | |
}, | |
feature: function(keyword, name, description, line) { | |
console.log(keyword + ': ' + name); | |
}, | |
background: function(keyword, name, description, line) { | |
console.log(' ' + keyword + ': ' + name); | |
}, | |
scenario: function(keyword, name, description, line) { | |
console.log(' ' + keyword + ': ' + name); | |
}, | |
scenario_outline: function(keyword, name, description, line) { | |
console.log(' ' + keyword + ': ' + name); | |
}, | |
examples: function(keyword, name, description, line) { | |
console.log(' ' + keyword + ': ' + name); | |
}, | |
step: function(keyword, name, line) { | |
console.log(' ' + keyword + name); | |
}, | |
py_string: function(string, line) { | |
console.log(' """\n' + string + '\n """'); | |
}, | |
row: function(row, line) { | |
console.log(' | ' + row.join(' | ') + ' |'); | |
}, | |
eof: function() { | |
console.log('====='); | |
} | |
}); | |
lexer.scan(fs.readFileSync(process.ARGV[2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment