2019-08-25 12:29:51 +00:00
|
|
|
import RE2 from 're2';
|
2019-09-09 10:21:01 +00:00
|
|
|
import { regEx } from '../../lib/util/regex';
|
2020-01-12 07:50:11 +00:00
|
|
|
import { CONFIG_VALIDATION } from '../../lib/constants/error-messages';
|
2019-08-25 12:29:51 +00:00
|
|
|
|
|
|
|
describe('util/regex', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses RE2', () => {
|
2019-09-09 10:21:01 +00:00
|
|
|
expect(regEx('foo')).toBeInstanceOf(RE2);
|
|
|
|
});
|
|
|
|
it('throws unsafe 2', () => {
|
2020-01-12 07:50:11 +00:00
|
|
|
expect(() => regEx(`x++`)).toThrow(CONFIG_VALIDATION);
|
2019-08-25 12:29:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Falls back to RegExp', () => {
|
|
|
|
jest.doMock('re2', () => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
|
|
|
|
|
|
|
const regex = require('../../lib/util/regex');
|
2019-09-09 10:21:01 +00:00
|
|
|
expect(regex.regEx('foo')).toBeInstanceOf(RegExp);
|
2019-08-25 12:29:51 +00:00
|
|
|
});
|
|
|
|
});
|