mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
29 lines
929 B
TypeScript
29 lines
929 B
TypeScript
import assert from 'node:assert';
|
|
import lodashStable from 'lodash';
|
|
import { stubString } from './utils';
|
|
import escapeRegExp from '../src/escapeRegExp';
|
|
|
|
describe('escapeRegExp', () => {
|
|
const escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
|
|
unescaped = '^$.*+?()[]{}|\\';
|
|
|
|
it('should escape values', () => {
|
|
assert.strictEqual(escapeRegExp(unescaped + unescaped), escaped + escaped);
|
|
});
|
|
|
|
it('should handle strings with nothing to escape', () => {
|
|
assert.strictEqual(escapeRegExp('abc'), 'abc');
|
|
});
|
|
|
|
it('should return an empty string for empty values', () => {
|
|
const values = [, null, undefined, ''],
|
|
expected = lodashStable.map(values, stubString);
|
|
|
|
const actual = lodashStable.map(values, (value, index) =>
|
|
index ? escapeRegExp(value) : escapeRegExp(),
|
|
);
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
});
|