Permalink
Browse files

Improved lexer for Scenario Outlines

  • Loading branch information...
1 parent 9cdc403 commit ea2236145bf3ead720fda036b9aad66e6d29443a @pacovell pacovell committed Oct 5, 2011
Showing with 26 additions and 2 deletions.
  1. +1 −1 lib/kyuri/lexer.js
  2. +25 −1 test/simple-lexer-test.js
View
@@ -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,
@@ -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": {
@@ -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.