-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from jneen/topic/test-coverage
Fixes #187 regexp group out of range; 100% tests
- Loading branch information
Showing
16 changed files
with
181 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules | |
npm-*.log | ||
.nyc_output | ||
coverage | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
"Parsimmon": true, | ||
"assert": true, | ||
"suite": true, | ||
"setup": true, | ||
"teardown": true, | ||
"test": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,48 @@ | ||
'use strict'; | ||
|
||
test('Parsimmon()', function() { | ||
var good = 'just a Q'; | ||
var bad = 'all I wanted was a Q'; | ||
var justQ = Parsimmon(function(str, i) { | ||
if (str.charAt(i) === 'Q') { | ||
return Parsimmon.makeSuccess(i + 1, good); | ||
} else { | ||
return Parsimmon.makeFailure(i, bad); | ||
} | ||
}); | ||
var result1 = justQ.parse('Q'); | ||
var result2 = justQ.parse('x'); | ||
assert.deepEqual(result1, { | ||
status: true, | ||
value: good, | ||
suite('Parsimmon()', function() { | ||
|
||
test('should work in general', function() { | ||
var good = 'just a Q'; | ||
var bad = 'all I wanted was a Q'; | ||
var justQ = Parsimmon(function(str, i) { | ||
if (str.charAt(i) === 'Q') { | ||
return Parsimmon.makeSuccess(i + 1, good); | ||
} else { | ||
return Parsimmon.makeFailure(i, bad); | ||
} | ||
}); | ||
var result1 = justQ.parse('Q'); | ||
var result2 = justQ.parse('x'); | ||
assert.deepEqual(result1, { | ||
status: true, | ||
value: good, | ||
}); | ||
assert.deepEqual(result2, { | ||
status: false, | ||
index: { | ||
offset: 0, | ||
line: 1, | ||
column: 1 | ||
}, | ||
expected: [bad] | ||
}); | ||
}); | ||
assert.deepEqual(result2, { | ||
status: false, | ||
index: { | ||
offset: 0, | ||
line: 1, | ||
column: 1 | ||
}, | ||
expected: [bad] | ||
|
||
test('unsafeUnion works on poorly formatted custom parser', function() { | ||
var p1 = Parsimmon.string('a').or(Parsimmon.string('b')); | ||
var p2 = Parsimmon(function(str, i) { | ||
return { | ||
status: false, | ||
index: -1, | ||
value: null, | ||
furthest: i, | ||
expected: [] | ||
}; | ||
}); | ||
var p3 = Parsimmon.alt(p2, p1); | ||
var result = p3.parse('x'); | ||
assert.deepStrictEqual(result.expected, ['\'a\'', '\'b\'']); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
'use strict'; | ||
|
||
test('Parsimmon.formatError', function() { | ||
var parser = | ||
Parsimmon.alt( | ||
Parsimmon.fail('a'), | ||
Parsimmon.fail('b'), | ||
Parsimmon.fail('c') | ||
); | ||
var expectation = 'expected one of a, b, c, got the end of the input'; | ||
var input = ''; | ||
var answer = Parsimmon.formatError(input, parser.parse(input)); | ||
assert.deepEqual(answer, expectation); | ||
suite('formatError', function() { | ||
|
||
test('end of input', function() { | ||
var parser = | ||
Parsimmon.alt( | ||
Parsimmon.fail('a'), | ||
Parsimmon.fail('b'), | ||
Parsimmon.fail('c') | ||
); | ||
var expectation = 'expected one of a, b, c, got the end of the input'; | ||
var input = ''; | ||
var answer = Parsimmon.formatError(input, parser.parse(input)); | ||
assert.deepEqual(answer, expectation); | ||
}); | ||
|
||
test('middle of input', function() { | ||
var parser = | ||
Parsimmon.seq( | ||
Parsimmon.string('1'), | ||
Parsimmon.alt( | ||
Parsimmon.fail('a'), | ||
Parsimmon.fail('b'), | ||
Parsimmon.fail('c') | ||
) | ||
); | ||
var expectation = | ||
'expected one of a, b, c at line 1 column 2, got \'...x11111111111...\''; | ||
var input = '1x1111111111111111111111111111'; | ||
var answer = Parsimmon.formatError(input, parser.parse(input)); | ||
assert.deepEqual(answer, expectation); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
suite('noneOf', function() { | ||
|
||
test('matches EVERYTHING BUT the characters specified', function() { | ||
var parser = Parsimmon.noneOf('abc'); | ||
var a = 'a'.charCodeAt(0); | ||
var c = 'c'.charCodeAt(0); | ||
for (var i = 0; i < 65535; i++) { | ||
var s = String.fromCharCode(i); | ||
if (a <= i && i <= c) { | ||
assert.strictEqual(parser.parse(s).status, false); | ||
} else { | ||
assert.strictEqual(parser.parse(s).status, true); | ||
} | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
suite('oneOf', function() { | ||
|
||
test('matches ONLY the characters specified', function() { | ||
var parser = Parsimmon.oneOf('abc'); | ||
var a = 'a'.charCodeAt(0); | ||
var c = 'c'.charCodeAt(0); | ||
for (var i = 0; i < 65535; i++) { | ||
var s = String.fromCharCode(i); | ||
if (a <= i && i <= c) { | ||
assert.strictEqual(parser.parse(s).status, true); | ||
} else { | ||
assert.strictEqual(parser.parse(s).status, false); | ||
} | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters