Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 2, 2024
1 parent 56c3b48 commit 7fa6b83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,16 @@ Notice that nearly every feature below has at least subtle differences from Java
<td align="middle">✅</td>
<td align="middle">✅</td>
<td>
✔ Any char (any flags)<br>
✔ Any char (with any flags)<br>
✔ Identity escape in char class<br>
</td>
</tr>
<tr valign="top">
<td>Non-newline</td>
<td>Not newline</td>
<td><code>\N</code></td>
<td align="middle">✅</td>
<td align="middle">✅</td>
<td>
✔ Excludes only <code>\n</code> (any flags)<br>
✔ Identity escape in char class<br>
</td>
</tr>
Expand Down
12 changes: 11 additions & 1 deletion spec/helpers/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ const duplicateCaptureNamesSupported = (() => {
}
return true;
})();

const maxTargetForDuplicateNames = duplicateCaptureNamesSupported ? null : 'ES2024';

const patternModsSupported = (() => {
try {
new RegExp('(?i:)');
} catch (e) {
return false;
}
return true;
})();
const maxTargetForPatternMods = patternModsSupported ? null : 'ESNext';

export {
maxTargetForDuplicateNames,
maxTargetForPatternMods,
};
6 changes: 5 additions & 1 deletion spec/match-char-set.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {r} from '../src/utils.js';
import {maxTargetForPatternMods} from './helpers/features.js';
import {matchers} from './helpers/matchers.js';

beforeEach(() => {
Expand All @@ -14,7 +15,10 @@ describe('CharacterSet', () => {
});

it('should match line feed with flag m disabled', () => {
expect('\n').toExactlyMatch(r`(?-m)\O`);
expect('\n').toExactlyMatch({
pattern: r`(?-m)\O`,
maxTarget: maxTargetForPatternMods,
});
});

it('should be identity escape within a char class', () => {
Expand Down

0 comments on commit 7fa6b83

Please sign in to comment.