Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bin/kyuri failing to exit when testing something with a keep-alive loop. #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


test: vows kyuri

vows:
vows --spec

kyuri:
./bin/kyuri examples

.PHONY: test vows kyuri

4 changes: 4 additions & 0 deletions bin/kyuri
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ catch (err) {
var _waitComplete = function () {
if (!complete) {
process.nextTick(_waitComplete);
} else {
// make sure the script exits even if something we are testing has anohter
// wait for next tick loop going.
process.exit();
}
};

Expand Down
31 changes: 31 additions & 0 deletions examples/complex_space.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Complex Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers

Background:
Given I have a calculator

Scenario: Add two numbers
Given I have entered "50" and "75" into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen

Scenario Outline: Add three numbers
Given I have entered <number1> into the calculator
And I have entered <number2> into the calculator
And I have entered 120 into the calculator
When I press add
Then the result should be <number3> on the screen

Examples:
| number1 | number2 | number3 |
| 10 | 20 | 150 |
| 20 | 40 | 180 |

Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
22 changes: 17 additions & 5 deletions lib/kyuri/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var helpers = require('./helpers'),
eyes = require('eyes');

var MULTI_DENT = /^(\t+)(\.)?/,
var MULTI_DENT = /^([\t ]+)(\.)?/,
IS_EXAMPLE_ROW = /^([\|\s+\S+]+\s+\|\s*)$/,
PARSE_EXAMPLE_ROW = /\|[^|]+/gi,
PYSTRING = /"""/,
Expand Down Expand Up @@ -72,6 +72,7 @@ Lexer.prototype = {
this.source = source; // Source code we are attempting to lex
this.lineNum = 0; // Line number of the lexing operation
this.indents = 0; // Number of indents
this.indent_size = null; // tabstop
this.tokens = []; // Stream of parsed tokens in the form ['TYPE', value, line]
this.lines = this.source.split('\n'); // Split the source code by \n since we have no multi-line statements

Expand Down Expand Up @@ -232,20 +233,31 @@ Lexer.prototype = {
},

lineToken: function () {
var diff, indent, size;
if (!(indent = this.match(MULTI_DENT, 1))) {
var diff, size, indent;
if (this.i > 0) { // only check line token at the first of the line.
return false;
}
indent = this.match(MULTI_DENT, 1);
if (!indent) {
return false;
}

size = indent.length;
this.i += size;

if (!this.indent_size) { // assume that first indent is one tabstop
this.indent_size = size;
}

if (size > this.indents) {
diff = size - this.indents;
diff = Math.round(diff / this.indent_size);
this.token('INDENT', diff);
}
else if (size < this.indents) {
this.token('OUTDENT', this.indents - size);
diff = this.indents - size;
diff = Math.round(diff / this.indent_size);
this.token('OUTDENT', diff);
}

this.indents = size;
Expand Down Expand Up @@ -294,4 +306,4 @@ Lexer.prototype = {
}
};

exports.Lexer = Lexer;
exports.Lexer = Lexer;
10 changes: 9 additions & 1 deletion test/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ vows.describe('kyuri/parser').addBatch({
assert.isObject(ast);
assert.include(ast, 1);
}
},
"parsing complex_space.feature": {
topic: parseAllLines(path.join(__dirname, '..', 'examples', 'complex_space.feature')),
"should parse correctly": function (err, ast) {
assert.isNull(err);
assert.isObject(ast);
assert.include(ast, 1);
}
}
}
}).export(module);
}).export(module);