Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Dec 21, 2016
1 parent 53a8747 commit 90606e3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
.DS_Store
yarn.lock
coverage/
.nyc_output
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"jsesc": "^2.3.0",
"regenerate": "^1.3.2"
},
"devDependencies": {},
"devDependencies": {
"mocha": "^3.2.0"
},
"scripts": {
"test": "mocha"
},
Expand Down
6 changes: 0 additions & 6 deletions test.js

This file was deleted.

40 changes: 40 additions & 0 deletions test/test.js
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/);
})
});

0 comments on commit 90606e3

Please sign in to comment.