Skip to content

Commit

Permalink
Improved lexer for Scenario Outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Covell committed Dec 5, 2011
1 parent 9cdc403 commit ea22361
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/kyuri/lexer.js
Expand Up @@ -12,7 +12,7 @@ var helpers = require('./helpers'),

var MULTI_DENT = /^(\t+)(\.)?/,
IS_EXAMPLE_ROW = /^([\|\s+\S+]+\s+\|\s*)$/,
PARSE_EXAMPLE_ROW = /\|\s*(\S+)/gi,
PARSE_EXAMPLE_ROW = /\|[^|]+/gi,
PYSTRING = /"""/,
TAGS_LENGTH = /[@\w+\s*]+/i,
TAGS = /(?:^@|\s+@)(\w+)/gi,
Expand Down
26 changes: 25 additions & 1 deletion test/simple-lexer-test.js
Expand Up @@ -12,6 +12,27 @@ var kyuri = require('kyuri'),
vows = require('vows'),
assert = require('assert'),
eyes = require('eyes');

var exampleRowTopic = function (row, values) {
return {
topic: kyuri.tokens(row),
"should be the right kind of row": function(tokens) {
assert.equal(tokens[0][0], 'EXAMPLE_ROW');
},
"should create valid tokens": function(tokens) {
assert.instanceOf(tokens, Array);
assert.equal(tokens.length, 3);
},
"should create the right token values": function(tokens) {
var lexedValues = tokens[0][1];

assert.equal(values.length, lexedValues.length);
for (var i = 0; i < values.length; i++) {
assert.equal(lexedValues[i], values[i]);
}
}
};
}

vows.describe('kyuri/lexer/simple').addBatch({
"When using the Kyuri lexer": {
Expand Down Expand Up @@ -49,6 +70,9 @@ vows.describe('kyuri/lexer/simple').addBatch({
assert.instanceOf(tokens, Array);
assert.equal(tokens.length, 4);
}
}
},
"a simple example row": exampleRowTopic('| title | element1 | element2 |', ['title', 'element1', 'element2']),
"an example row with spaces": exampleRowTopic('| title 1 | element 1 |', ['title 1', 'element 1']),
"an example row with blank elements": exampleRowTopic('| title | |', ['title', ''])
}
}).export(module);

0 comments on commit ea22361

Please sign in to comment.