Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 27, 2024
1 parent cf35d2d commit 7cf0d9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/match-char-class-range.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@ describe('CharacterClassRange', () => {
expect(() => toDetails(r`[\u{1}-\0]`)).toThrow();
expect(() => toDetails(r`[a-0-9]`)).toThrow();
});

it(r`should match UTF-8 encoded byte sequences with \xNN above 7F`, () => {
// Encoded byte sequence `\xE2\x82\xAC` is € U+20AC
expect(['\u1000', '\u1001', '\u{20AC}']).toExactlyMatch(r`[\u1000-\xE2\x82\xAC]`);
expect(['\0', '\u0FFF', '\xE2', '\x82', '\xAC', '\u{20AD}']).not.toFindMatch(r`[\u1000-\xE2\x82\xAC]`);
});

it(r`should throw for invalid UTF-8 encoded byte sequences with \xNN above 7F`, () => {
expect(() => toDetails(r`[\0-\x80]`)).toThrow();
expect(() => toDetails(r`[\0-\xF4]`)).toThrow();
expect(() => toDetails(r`[\0-\xEF\xC0\xBB]`)).toThrow();
// In Onig, the unused encoded UTF-8 bytes F5-FF don't throw, but they don't match anything and
// cause buggy, undesirable behavior in ranges
expect(() => toDetails(r`[\0-\xFF]`)).toThrow();
});
});
5 changes: 4 additions & 1 deletion spec/match-char.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ describe('Character', () => {

it(r`should throw for invalid UTF-8 encoded byte sequences \xNN (above 7F)`, () => {
expect(() => toDetails(r`\x80`)).toThrow();
expect(() => toDetails(r`\xFF`)).toThrow();
expect(() => toDetails(r`\xF4`)).toThrow();
expect(() => toDetails(r`\xEF\xC0\xBB`)).toThrow();
// In Onig, the unused encoded UTF-8 bytes F5-FF don't throw, but they don't match anything
// (likely a bug in Onig)
expect(() => toDetails(r`\xFF`)).toThrow();
});

it(r`should throw for incomplete \x`, () => {
Expand Down

0 comments on commit 7cf0d9a

Please sign in to comment.