Skip to content

Commit e667ad2

Browse files
committed
Add tests for github.com//issues/191
1 parent 95bbaf9 commit e667ad2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/regression_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,4 +786,40 @@ void main() {
786786
);
787787
});
788788
});
789+
group('github.com/petitparser/dart-petitparser/issues/191', () {
790+
test('simple', () {
791+
final zero = '0'.toParser();
792+
final one = '1'.toParser();
793+
final parser = [seq2(zero, one), one].toChoiceParser().star().flatten();
794+
expect(parser, isParseSuccess('1', result: '1'));
795+
expect(parser, isParseSuccess('01', result: '01'));
796+
expect(parser, isParseSuccess('11', result: '11'));
797+
expect(parser, isParseSuccess('011', result: '011'));
798+
expect(parser, isParseSuccess('0101', result: '0101'));
799+
});
800+
test('general', () {
801+
final zero = '0'.toParser();
802+
final one = '1'.toParser();
803+
final parser = [zero, one]
804+
.toChoiceParser()
805+
.callCC<String>((continuation, context) {
806+
// Parse the original choice parser (zero or one).
807+
final result = continuation(context);
808+
// If this is a success and the result is '0', build a new parser
809+
// and continue with that:
810+
if (result case Success(value: '0')) {
811+
return '1'.toParser().parseOn(result);
812+
}
813+
// Otherwise just return the result of the original choice parser.
814+
return result;
815+
})
816+
.star()
817+
.flatten();
818+
expect(parser, isParseSuccess('1', result: '1'));
819+
expect(parser, isParseSuccess('01', result: '01'));
820+
expect(parser, isParseSuccess('11', result: '11'));
821+
expect(parser, isParseSuccess('011', result: '011'));
822+
expect(parser, isParseSuccess('0101', result: '0101'));
823+
});
824+
});
789825
}

0 commit comments

Comments
 (0)