-
Notifications
You must be signed in to change notification settings - Fork 101
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
1 parent
53a8747
commit 90606e3
Showing
4 changed files
with
46 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
node_modules/ | ||
.DS_Store | ||
yarn.lock | ||
coverage/ | ||
.nyc_output |
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,40 @@ | ||
const assert = require('assert'); | ||
const regexgen = require('../'); | ||
|
||
describe('regexgen', function () { | ||
it('should generate a char class', function () { | ||
assert.deepEqual(regexgen(['a', 'b', 'c']), /[a-c]/); | ||
}); | ||
|
||
it('should generate an alternation', function () { | ||
assert.deepEqual(regexgen(['abc', '123']), /123|abc/); | ||
}); | ||
|
||
it('should extract common prefixes at the start', function () { | ||
assert.deepEqual(regexgen(['foobar', 'foozap']), /foo(?:zap|bar)/); | ||
}); | ||
|
||
it('should extract common prefixes at the end', function () { | ||
assert.deepEqual(regexgen(['barfoo', 'zapfoo']), /(?:zap|bar)foo/); | ||
}); | ||
|
||
it('should extract common prefixes at the start and end', function () { | ||
assert.deepEqual(regexgen(['foobarfoo', 'foozapfoo']), /foo(?:zap|bar)foo/); | ||
}); | ||
|
||
it('should generate an optional group', function () { | ||
assert.deepEqual(regexgen(['foo', 'foobar']), /foo(?:bar)?/); | ||
}); | ||
|
||
it('should generate multiple optional groups', function () { | ||
assert.deepEqual(regexgen(['f', 'fo', 'fox']), /f(?:ox?)?/); | ||
}); | ||
|
||
it('should escape meta characters', function () { | ||
assert.deepEqual(regexgen(['foo|bar[test]+']), /foo\|bar\[test\]\+/); | ||
}); | ||
|
||
it('should escape non-ascii characters', function () { | ||
assert.deepEqual(regexgen(['🎉']), /\uD83C\uDF89/); | ||
}) | ||
}); |