Skip to content

Commit

Permalink
bugfix: don't test the truthiness of result
Browse files Browse the repository at this point in the history
and add a test for atMost :X

fixes #14
  • Loading branch information
jneen committed Feb 4, 2014
1 parent 2078914 commit aa99876
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parsimmon.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
} }
} }


for (; times < max && result; times += 1) { for (; times < max; times += 1) {
result = self._(stream, i); result = self._(stream, i);
prevResult = furthestBacktrackFor(result, prevResult); prevResult = furthestBacktrackFor(result, prevResult);
if (result.status) { if (result.status) {
Expand Down
9 changes: 9 additions & 0 deletions test/parsimmon.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ suite('parser', function() {
assert.throws(function() { thenDigit.parse('x1'); }); assert.throws(function() { thenDigit.parse('x1'); });
}); });


test('atMost', function() {
var atMostTwo = letter.atMost(2);
debugger
assertEqualArray(atMostTwo.parse(''), []);
assertEqualArray(atMostTwo.parse('a'), ['a']);
assertEqualArray(atMostTwo.parse('ab'), ['a', 'b']);
assert.throws(function() { atMostTwo.parse('abc'); });
});

test('atLeast', function() { test('atLeast', function() {
var atLeastTwo = letter.atLeast(2); var atLeastTwo = letter.atLeast(2);


Expand Down

0 comments on commit aa99876

Please sign in to comment.