-
Notifications
You must be signed in to change notification settings - Fork 6
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
797dfe7
commit f790832
Showing
2 changed files
with
34 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
module.exports = match => { | ||
if (match instanceof RegExp) { | ||
return match | ||
} | ||
if (match && match.re) { | ||
return new RegExp(match.re, match.flags) | ||
} | ||
|
||
} |
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,23 @@ | ||
'use strict' | ||
const { describe, it } = require('mocha') | ||
const assert = require('assert') | ||
const parseMatch = require('./parseMatch') | ||
|
||
describe('config/parseMatch', () => { | ||
it('keeps regular expression', () => { | ||
const re = /whatever/ | ||
assert.strictEqual(parseMatch(re), re) | ||
}) | ||
|
||
it('supports { re: "..." } syntax for configuration files', () => { | ||
const re = parseMatch({ re: 'whatever' }) | ||
assert.ok(re instanceof RegExp) | ||
assert.strictEqual('a whatever b'.replace(re, 'o'), 'a o b') | ||
}) | ||
|
||
it('supports { re: "...", flags: "..." } syntax for configuration files', () => { | ||
const re = parseMatch({ re: 'a', flags: 'g' }) | ||
assert.ok(re instanceof RegExp) | ||
assert.strictEqual('a whatever b'.replace(re, 'o'), 'o whotever b') | ||
}) | ||
}) |