feat: add text repeat tool

- Added text repeat tool to repeat input text multiple times with optional delimiter.
- Included functionality for custom repetition amounts and delimiters.
This commit is contained in:
EugSh
2025-03-07 15:26:04 +03:00
parent 6a14840e91
commit eb9e3cbdf9
6 changed files with 205 additions and 1 deletions

View File

@@ -0,0 +1,55 @@
import { describe, expect, it } from 'vitest';
import { repeatText } from './service';
import { initialValues } from './initialValues';
describe('repeatText function', () => {
it('should repeat the letter correctly', () => {
const text = 'i';
const repeatAmount = '5';
const result = repeatText({ ...initialValues, repeatAmount }, text);
expect(result).toBe('iiiii');
});
it('should repeat the word correctly', () => {
const text = 'hello';
const repeatAmount = '3';
const result = repeatText({ ...initialValues, repeatAmount }, text);
expect(result).toBe('hellohellohello');
});
it('should repeat the word with a space delimiter correctly', () => {
const text = 'word';
const repeatAmount = '3';
const delimiter = ' ';
const result = repeatText(
{ ...initialValues, repeatAmount, delimiter },
text
);
expect(result).toBe('word word word');
});
it('should repeat the word with a space and a comma delimiter correctly', () => {
const text = 'test';
const repeatAmount = '3';
const delimiter = ', ';
const result = repeatText(
{ ...initialValues, repeatAmount, delimiter },
text
);
expect(result).toBe('test, test, test');
});
it('Should not repeat text if repeatAmount is zero', () => {
const text = 'something';
const repeatAmount = '0';
const result = repeatText({ ...initialValues, repeatAmount }, text);
expect(result).toBe('');
});
it('Should not repeat text if repeatAmount is not entered', () => {
const text = 'something';
const repeatAmount = '';
const result = repeatText({ ...initialValues, repeatAmount }, text);
expect(result).toBe('');
});
});