mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
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:
55
src/pages/tools/string/repeat/repeatText.service.test.ts
Normal file
55
src/pages/tools/string/repeat/repeatText.service.test.ts
Normal 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('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user