Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 3, 2024
1 parent 8e5d94c commit bc74540
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,15 @@ Notice that nearly every feature below has at least subtle differences from Java
</td>
</tr>
<tr valign="top">
<td colspan="2">Other (rare)</td>
<td colspan="2">Other (extremely rare)</td>
<td align="middle">❌</td>
<td align="middle">❌</td>
<td>
Not yet supported:<br>
● <code>\cx</code>, <code>\C-x</code> with non-A-Za-z<br>
Non-A-Za-z with <code>\cx</code>, <code>\C-x</code><br>
● Meta <code>\M-x</code>, <code>\M-\C-x</code><br>
● Multibyte octal <code>\o{…}</code><br>
● Octal code point <code>\o{…}</code><br>
● UTF-8 encoded bytes in octal<br>
</td>
</tr>

Expand Down
11 changes: 9 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ <h2>Try it</h2>
</details>
</main>

<script src="https://cdn.jsdelivr.net/npm/oniguruma-to-es/dist/index.min.js"></script>
<!-- <script src="../dist/index.min.js"></script> -->
<!-- Only available if running locally -->
<script src="../dist/index.min.js"></script>
<script>
// Hack to make it work on GitHub Pages, where `dist/` isn't checked in; use the last published
// release's copy
if (typeof OnigurumaToES === 'undefined') {
document.write('<script src="https://cdn.jsdelivr.net/npm/oniguruma-to-es/dist/index.min.js"><\/script>');
}
</script>
<script src="./demo.js"></script>
<script>
// For testing in the console
Expand Down
14 changes: 10 additions & 4 deletions spec/match-char-class-range.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ describe('CharacterClassRange', () => {
});
});

it('should match unescaped hyphen as literal at right of range', () => {
it('should match unescaped hyphen as literal if follows range', () => {
expect('-').toExactlyMatch(r`[a-z-0]`);
expect('-').toExactlyMatch(r`[a-z-\w]`);
expect('-').toExactlyMatch(r`[a-z-0-9]`);
expect(['a', 'b', 'c', '-', 'z']).toExactlyMatch(r`[a-c-z]`);
expect('d').not.toFindMatch(r`[a-c-z]`);
});

it('should throw for reversed ranges', () => {
expect(() => compile(r`[z-a]`)).toThrow();
expect(() => compile(r`[\u{1}-\0]`)).toThrow();
it('should throw for range with range', () => {
expect(() => compile(r`[a-0-9]`)).toThrow();
});

it('should throw for range with set', () => {
Expand All @@ -65,4 +66,9 @@ describe('CharacterClassRange', () => {
expect(() => compile(r`[a-z-\w]`)).toThrow();
expect(() => compile(r`[\w-\s]`)).toThrow();
});

it('should throw for reversed ranges', () => {
expect(() => compile(r`[z-a]`)).toThrow();
expect(() => compile(r`[\u{1}-\0]`)).toThrow();
});
});

0 comments on commit bc74540

Please sign in to comment.