Skip to content

Commit

Permalink
Add test for workaround described in #80.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Dec 2, 2024
1 parent c867078 commit a48ffec
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/regression_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,27 @@ void main() {
expect(parser, isParseSuccess('third'));
});
});
group('github.com/petitparser/dart-petitparser/issues/80', () {
final surrogatePair = seq2(
pattern('\uD800-\uDBFF'),
pattern('\uDC00-\uDFFF'),
);
final decodedSurrogatePair = surrogatePair.map2((hi, lo) =>
0x400 * (hi.codeUnitAt(0) - 0xD800) +
(lo.codeUnitAt(0) - 0xDC00) +
0x10000);
test('en.wikipedia.org/wiki/UTF-16#Examples', () {
expect(
decodedSurrogatePair, isParseSuccess('\u{10437}', result: 0x10437));
expect(
decodedSurrogatePair, isParseSuccess('\u{24B62}', result: 0x24B62));
});
test('#issuecomment-2510905396', () {
final parser = decodedSurrogatePair
.where((value) => 0x20000 <= value && value <= 0x2FFFF);
expect(parser, isParseSuccess('\u{20000}', result: 0x20000));
expect(parser, isParseSuccess('\u{2abcd}', result: 0x2abcd));
expect(parser, isParseSuccess('\u{2FFFF}', result: 0x2FFFF));
});
});
}

0 comments on commit a48ffec

Please sign in to comment.