Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rot13 tool, testCases then updated index file #22

Merged
merged 6 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/pages/tools/string/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { tool as stringRemoveDuplicateLines } from './remove-duplicate-lines/meta';
import { tool as stringRotate } from './rotate/meta';
import { tool as stringQuote } from './quote/meta';
import { tool as stringRot13 } from './rot13/meta';
import { tool as stringReverse } from './reverse/meta';
import { tool as stringRandomizeCase } from './randomize-case/meta';
import { tool as stringUppercase } from './uppercase/meta';
Expand Down
11 changes: 11 additions & 0 deletions src/pages/tools/string/quote/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Box } from '@mui/material';
import React from 'react';
import * as Yup from 'yup';

const initialValues = {};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
export default function Quote() {
return <Box>Lorem ipsum</Box>;
}
13 changes: 13 additions & 0 deletions src/pages/tools/string/quote/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineTool } from '@tools/defineTool';
import { lazy } from 'react';
// import image from '@assets/text.png';

export const tool = defineTool('string', {
name: 'Quote',
path: 'quote',
icon: 'proicons:quote',
description: '',
shortDescription: '',
keywords: ['quote'],
component: lazy(() => import('./index'))
});
62 changes: 62 additions & 0 deletions src/pages/tools/string/quote/quote.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { expect, describe, it } from 'vitest';
import { quote, stringQuoter } from './service';

describe('quote function', () => {
it('quotes a word with single quotes', () => {
expect(quote('Hello', "'", "'", false)).toBe("'Hello'");
});

it('quotes a word with double quotes', () => {
expect(quote('World', '"', '"', true)).toBe('"World"');
});

it('does not re-quote already quoted word', () => {
expect(quote('"Goodbye"', '"', '"', false)).toBe('"Goodbye"');
});

it('handles empty word when emptyQuoting is true', () => {
expect(quote('', "'", "'", false)).toBe("''");
});

it('handles empty word when emptyQuoting is false', () => {
expect(quote('', "'", "'", false)).toBe("''"); // Replace with expected behavior
});
});

describe('stringQuoter function', () => {
it('quotes a multi-line input with single quotes', () => {
const input = 'Hello\nWorld\n';
const expected = "'Hello'\n'World'\n''";
expect(stringQuoter(input, "'", "'", false, true, true)).toBe(expected);
});

it('handles empty lines when emptyQuoting is true', () => {
const input = 'Hello\n\nWorld';
const expected = "'Hello'\n''\n'World'";
expect(stringQuoter(input, "'", "'", false, true, true)).toBe(expected);
});

it('does not quote empty lines when emptyQuoting is false', () => {
const input = 'Hello\n\nWorld';
const expected = "'Hello'\n\n'World'";
expect(stringQuoter(input, "'", "'", false, false, true)).toBe(expected);
});

it('quotes a single-line input with double quotes', () => {
const input = 'Hello';
const expected = '"Hello"';
expect(stringQuoter(input, '"', '"', true, true, false)).toBe(expected);
});

it('handles empty input', () => {
const input = '';
const expected = '';
expect(stringQuoter(input, "'", "'", false, true, false)).toBe(expected);
});

it('handles spaces input', () => {
const input = ' ';
const expected = "' '";
expect(stringQuoter(input, "'", "'", false, true, false)).toBe(expected);
});
});
57 changes: 57 additions & 0 deletions src/pages/tools/string/quote/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export function quote(
word: string,
leftQuote: string,
rightQuote: string,
doubleQuotation: boolean
): string {
const array: string[] = word.split('');

// Check if double quotation is enabled and adjust accordingly
if (doubleQuotation) {
array.unshift(leftQuote);
array.push(rightQuote);
} else {
// Check if the word is already quoted correctly
if (array[0] === leftQuote && array[array.length - 1] === rightQuote) {
return word;
}

// Append quotes if not already quoted
array.unshift(leftQuote);
array.push(rightQuote);
}

return array.join('');
}

export function stringQuoter(
input: string,
leftQuote: string,
rightQuote: string,
doubleQuotation: boolean,
emptyQuoting: boolean,
multiLine: boolean
) {
if (!input) {
return '';
}
let arrayOfString: string[] = [];
const result: string[] = [];
if (multiLine) {
arrayOfString = input.split('\n');
} else {
arrayOfString.push(input);
}
for (const word of arrayOfString) {
if (word === '') {
if (emptyQuoting) {
result.push(quote(word, leftQuote, rightQuote, doubleQuotation));
} else {
result.push(word);
}
} else {
result.push(quote(word, leftQuote, rightQuote, doubleQuotation));
}
}
return result.join('\n');
}
11 changes: 11 additions & 0 deletions src/pages/tools/string/rot13/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Box } from '@mui/material';
import React from 'react';
import * as Yup from 'yup';

const initialValues = {};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
export default function Rot13() {
return <Box>Lorem ipsum</Box>;
}
13 changes: 13 additions & 0 deletions src/pages/tools/string/rot13/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineTool } from '@tools/defineTool';
import { lazy } from 'react';
// import image from '@assets/text.png';

export const tool = defineTool('string', {
name: 'Rot13',
path: 'rot13',
icon: 'hugeicons:encrypt',
description: '',
shortDescription: '',
keywords: ['rot13'],
component: lazy(() => import('./index'))
});
58 changes: 58 additions & 0 deletions src/pages/tools/string/rot13/rot13.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect, describe, it } from 'vitest';
import { rot13 } from './service';

describe('rot13', () => {
it('should encode a simple string using ROT13', () => {
const input = 'hello';
const result = rot13(input);
expect(result).toBe('uryyb');
});

it('should decode a ROT13 encoded string', () => {
const input = 'uryyb';
const result = rot13(input);
expect(result).toBe('hello');
});

it('should handle uppercase letters correctly', () => {
const input = 'HELLO';
const result = rot13(input);
expect(result).toBe('URYYB');
});

it('should handle mixed case letters correctly', () => {
const input = 'HelloWorld';
const result = rot13(input);
expect(result).toBe('UryybJbeyq');
});

it('should handle non-alphabetic characters correctly', () => {
const input = 'Hello, World!';
const result = rot13(input);
expect(result).toBe('Uryyb, Jbeyq!');
});

it('should handle an empty string', () => {
const input = '';
const result = rot13(input);
expect(result).toBe('');
});

it('should handle a string with numbers correctly', () => {
const input = '1234';
const result = rot13(input);
expect(result).toBe('1234');
});

it('should handle a string with symbols correctly', () => {
const input = '!@#$%^&*()_+-=';
const result = rot13(input);
expect(result).toBe('!@#$%^&*()_+-=');
});

it('should handle a string with mixed characters correctly', () => {
const input = 'Hello, World! 123';
const result = rot13(input);
expect(result).toBe('Uryyb, Jbeyq! 123');
});
});
7 changes: 7 additions & 0 deletions src/pages/tools/string/rot13/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function rot13(input: string): string {
return input.replace(/[a-zA-Z]/g, (char) => {
const charCode = char.charCodeAt(0);
const baseCode = charCode >= 97 ? 97 : 65; // 'a' or 'A'
return String.fromCharCode(((charCode - baseCode + 13) % 26) + baseCode);
});
}
11 changes: 11 additions & 0 deletions src/pages/tools/string/rotate/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Box } from '@mui/material';
import React from 'react';
import * as Yup from 'yup';

const initialValues = {};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
export default function Rotate() {
return <Box>Lorem ipsum</Box>;
}
13 changes: 13 additions & 0 deletions src/pages/tools/string/rotate/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineTool } from '@tools/defineTool';
import { lazy } from 'react';
// import image from '@assets/text.png';

export const tool = defineTool('string', {
name: 'Rotate',
path: 'rotate',
icon: 'carbon:rotate',
description: '',
shortDescription: '',
keywords: ['rotate'],
component: lazy(() => import('./index'))
});
Loading