Skip to content

Commit

Permalink
github.com//issues/162
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Dec 25, 2023
1 parent af95765 commit 8d769ab
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/regression_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,31 @@ void main() {
expect(extended, isParseSuccess('ä', result: 'ä'));
expect(extended, isParseSuccess('ï', result: 'ï'));
});
group('github.com/petitparser/dart-petitparser/issues/162', () {
final uppercase = char('A').plus().map((_) => 'success');
final anycase = charIgnoringCase('A').plus().map((_) => 'fallback');
test('question', () {
final parser = [uppercase, anycase].toChoiceParser().end();
expect(parser, isParseSuccess('AAAA', result: 'success'));
expect(parser, isParseSuccess('aaaAAaaa', result: 'fallback'));
expect(
parser,
isParseFailure('AAaaAA',
position: 2, message: 'end of input expected'));
});
test('possible fix', () {
final parser = [uppercase.end(), anycase.end()].toChoiceParser();
expect(parser, isParseSuccess('AAAA', result: 'success'));
expect(parser, isParseSuccess('aaaAAaaa', result: 'fallback'));
expect(parser, isParseSuccess('AAaaAA', result: 'fallback'));
});
test('more general', () {
final parser = [uppercase.skip(after: anycase.not()), anycase]
.toChoiceParser()
.end();
expect(parser, isParseSuccess('AAAA', result: 'success'));
expect(parser, isParseSuccess('aaaAAaaa', result: 'fallback'));
expect(parser, isParseSuccess('AAaaAA', result: 'fallback'));
});
});
}

0 comments on commit 8d769ab

Please sign in to comment.