2019-10-29 03:41:52 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
|
|
import { regexpType } from '../../../src/config/type/Regexp';
|
2019-11-16 01:01:28 +00:00
|
|
|
import { InvalidArgumentError } from '../../../src/error/InvalidArgumentError';
|
2019-10-29 03:41:52 +00:00
|
|
|
import { describeLeaks, itLeaks } from '../../helpers/async';
|
|
|
|
|
|
|
|
describeLeaks('regexp config type', async () => {
|
|
|
|
itLeaks('match slashed strings', async () => {
|
|
|
|
expect(regexpType.resolve('/foo/')).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should match flags', async () => {
|
|
|
|
const regexp: RegExp = regexpType.construct('/foo/g');
|
|
|
|
expect(regexp.flags).to.equal('g');
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should not match bare strings', async () => {
|
|
|
|
expect(regexpType.resolve('foo')).to.equal(false);
|
|
|
|
});
|
2019-11-13 13:50:56 +00:00
|
|
|
|
|
|
|
itLeaks('should not match invalid flags', async () => {
|
|
|
|
expect(regexpType.resolve('/foo/notrealflags')).to.equal(false);
|
|
|
|
});
|
|
|
|
|
2019-11-16 01:01:28 +00:00
|
|
|
itLeaks('should not match regexp embedded in a longer string', async () => {
|
|
|
|
expect(regexpType.resolve('some/regexp/with-padding')).to.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should throw when constructing an invalid regexp', async () => {
|
|
|
|
expect(() => regexpType.construct('/foo/notrealflags')).to.throw(InvalidArgumentError);
|
2019-11-13 13:50:56 +00:00
|
|
|
});
|
2019-10-29 03:41:52 +00:00
|
|
|
});
|