Permalink
Browse files

bugfix: don't test the truthiness of `result`

and add a test for atMost :X

fixes #14
  • Loading branch information...
jneen committed Feb 4, 2014
1 parent 2078914 commit aa99876ebc6129d5d96eb36fff3795fc9a4a06ef
Showing with 10 additions and 1 deletion.
  1. +1 −1 src/parsimmon.js
  2. +9 −0 test/parsimmon.test.js
View
@@ -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);
prevResult = furthestBacktrackFor(result, prevResult);
if (result.status) {
View
@@ -182,6 +182,15 @@ suite('parser', function() {
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() {
var atLeastTwo = letter.atLeast(2);

0 comments on commit aa99876

Please sign in to comment.