-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {toDetails, toRegExp} from '../dist/esm/index.js'; | ||
import {r} from '../src/utils.js'; | ||
|
||
describe('AbsentFunction', () => { | ||
describe('absent repeater', () => { | ||
it('should match any input not matched by absent', () => { | ||
expect('abc'.match(toRegExp('(?~ab)', {global: true}))).toEqual(['', 'bc', '']); | ||
expect('abc'.match(toRegExp('(?~)', {global: true}))).toEqual(['', '', '', '']); | ||
expect('abc'.match(toRegExp('(?~a|b)', {global: true}))).toEqual(['', '', 'c', '']); | ||
}); | ||
|
||
it('should not match atomically', () => { | ||
expect('abc'.match(toRegExp('(?~ab).', {global: true}))).toEqual(['a', 'bc']); | ||
}); | ||
|
||
it('should allow quantification', () => { | ||
expect('abc'.match(toRegExp('(?~ab)?.', {global: true}))).toEqual(['a', 'bc']); | ||
expect('abc'.match(toRegExp('(?~ab)??.', {global: true}))).toEqual(['a', 'b', 'c']); | ||
expect('abc'.match(toRegExp('(?~ab)?+.', {global: true}))).toEqual(['a']); | ||
}); | ||
|
||
it('should throw for nested absent repeaters', () => { | ||
expect(() => toDetails('(?~(?~))')).toThrow(); | ||
expect(() => toDetails('(?~a(?~))')).toThrow(); | ||
expect(() => toDetails('(?~(?~a))')).toThrow(); | ||
expect(() => toDetails('(?~a(?~b))')).toThrow(); | ||
}); | ||
}); | ||
|
||
describe('absent expression', () => { | ||
// Not supported | ||
it('should throw', () => { | ||
expect(() => toDetails(r`(?~|abc|\O*)`)).toThrow(); | ||
}); | ||
}); | ||
|
||
describe('absent stopper', () => { | ||
// Not supported | ||
it('should throw', () => { | ||
expect(() => toDetails('(?~|abc)')).toThrow(); | ||
}); | ||
}); | ||
|
||
describe('absent clearer', () => { | ||
// Not supported | ||
it('should throw', () => { | ||
expect(() => toDetails('(?~|)')).toThrow(); | ||
expect(() => toDetails('(?~|abc)(?~|)')).toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters