mirror of https://github.com/renovatebot/renovate
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { coerceString, looseEquals, replaceAt } from './string';
|
|
|
|
describe('util/string', () => {
|
|
describe('replaceAt', () => {
|
|
test('replaceAt inserts newString which is one char longer than oldString', () => {
|
|
const content = 'I am a dog';
|
|
const index = 2;
|
|
const newString = 'are';
|
|
const oldString = 'am';
|
|
|
|
const newContent = replaceAt(content, index, oldString, newString);
|
|
|
|
expect(newContent).toBe('I are a dog');
|
|
});
|
|
|
|
test('replaceAt inserts newString which is significantly longer than oldString', () => {
|
|
const content = 'I am a dog';
|
|
const index = 2;
|
|
const newString = 'want to have a new pet maybe';
|
|
const oldString = 'am';
|
|
|
|
const newContent = replaceAt(content, index, oldString, newString);
|
|
|
|
expect(newContent).toBe('I want to have a new pet maybe a dog');
|
|
});
|
|
});
|
|
|
|
describe('looseEquals', () => {
|
|
test('reverts to literal match if either is falsey', () => {
|
|
expect(looseEquals(undefined, null)).toBeFalse();
|
|
expect(looseEquals(null, null)).toBeTrue();
|
|
expect(looseEquals(null, '')).toBeFalse();
|
|
});
|
|
});
|
|
|
|
it('coerceString', () => {
|
|
expect(coerceString('foo')).toBe('foo');
|
|
expect(coerceString('')).toBe('');
|
|
expect(coerceString(undefined)).toBe('');
|
|
expect(coerceString(null)).toBe('');
|
|
expect(coerceString(null, 'foo')).toBe('foo');
|
|
});
|
|
});
|