mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
wip: code formatting nits continued
This commit is contained in:
27
test/escapeRegExp.spec.js
Normal file
27
test/escapeRegExp.spec.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import lodashStable from 'lodash';
|
||||
import { stubString } from './utils';
|
||||
import escapeRegExp from '../src/escapeRegExp';
|
||||
|
||||
describe('escapeRegExp', () => {
|
||||
const escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\';
|
||||
const unescaped = '^$.*+?()[]{}|\\';
|
||||
|
||||
it('should escape values', () => {
|
||||
expect(escapeRegExp(unescaped + unescaped)).toBe(escaped + escaped);
|
||||
});
|
||||
|
||||
it('should handle strings with nothing to escape', () => {
|
||||
expect(escapeRegExp('abc')).toBe('abc');
|
||||
});
|
||||
|
||||
it('should return an empty string for empty values', () => {
|
||||
const values = [, null, undefined, ''];
|
||||
const expected = lodashStable.map(values, stubString);
|
||||
|
||||
const actual = lodashStable.map(values, (value, index) =>
|
||||
index ? escapeRegExp(value) : escapeRegExp(),
|
||||
);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user