From 4589e46c0ccac48028466526411ecbff923d425c Mon Sep 17 00:00:00 2001 From: Steven Levithan Date: Mon, 30 Dec 2024 22:12:01 +0100 Subject: [PATCH] Tests: Error for quantified directives --- README.md | 2 +- spec/match-directive.spec.js | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 50eb00f..fa8bd27 100644 --- a/README.md +++ b/README.md @@ -693,7 +693,7 @@ Notice that nearly every feature below has at least subtle differences from Java ✔ Includes all JS forms
✔ Adds {,n} for min 0
✔ Explicit bounds have upper limit of 100,000 (unlimited in JS)
- ✔ Error with assertions (same as JS with flag u, v)
+ ✔ Error with assertions (same as JS with flag u, v) and directives
diff --git a/spec/match-directive.spec.js b/spec/match-directive.spec.js index d66bc8b..f306276 100644 --- a/spec/match-directive.spec.js +++ b/spec/match-directive.spec.js @@ -1,3 +1,4 @@ +import {toDetails} from '../dist/index.mjs'; import {r} from '../src/utils.js'; import {matchers} from './helpers/matchers.js'; @@ -5,17 +6,24 @@ beforeEach(() => { jasmine.addMatchers(matchers); }); -// TODO: Add me -// describe('Directive', () => { -// describe('flags', () => { -// it('should', () => { -// expect('').toExactlyMatch(r``); -// }); -// }); +describe('Directive', () => { + describe('flags', () => { + it('should not allow quantification', () => { + expect(() => toDetails('(?i)+')).toThrow(); + expect(() => toDetails('(?imx)+')).toThrow(); + expect(() => toDetails('(?-i)+')).toThrow(); + expect(() => toDetails('(?im-x)+')).toThrow(); + }); -// describe('keep', () => { -// it('should', () => { -// expect('').toExactlyMatch(r``); -// }); -// }); -// }); + // TODO: Add remaining + }); + + describe('keep', () => { + it('should not allow quantification', () => { + expect(() => toDetails(r`\K+`)).toThrow(); + expect(() => toDetails(r`a\K+a`)).toThrow(); + }); + + // TODO: Add remaining + }); +});