UNPKG

@mbc-cqrs-serverless/cli

Version:

a CLI to get started with MBC CQRS serverless framework

111 lines (110 loc) 7.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const formatting_1 = require("./formatting"); describe('Formatting Utilities', () => { describe('Overview: String normalization functionality', () => { describe('Purpose: Test normalizeToKebabOrSnakeCase with various input formats', () => { it('should convert camelCase to kebab-case', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('camelCaseString')).toBe('camel-case-string'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('myTestVariable')).toBe('my-test-variable'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('XMLHttpRequest')).toBe('xmlhttp-request'); }); it('should convert PascalCase to kebab-case', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('PascalCaseString')).toBe('pascal-case-string'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('MyTestClass')).toBe('my-test-class'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('HTTPSConnection')).toBe('httpsconnection'); }); it('should handle strings with spaces', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('string with spaces')).toBe('string-with-spaces'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('Multiple spaces here')).toBe('multiple---spaces---here'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)(' leading and trailing spaces ')).toBe('-leading-and-trailing-spaces-'); }); it('should handle strings with underscores', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('snake_case_string')).toBe('snake_case_string'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('mixed_snake_camelCase')).toBe('mixed_snake_camel-case'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('__double__underscores__')).toBe('__double__underscores__'); }); it('should handle already kebab-case strings', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('kebab-case-string')).toBe('kebab-case-string'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('already-formatted')).toBe('already-formatted'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('single')).toBe('single'); }); }); describe('Purpose: Test edge cases and special characters', () => { it('should handle empty inputs', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('')).toBe(''); }); it('should handle null and undefined inputs with error', () => { expect(() => (0, formatting_1.normalizeToKebabOrSnakeCase)(null)).toThrow(); expect(() => (0, formatting_1.normalizeToKebabOrSnakeCase)(undefined)).toThrow(); }); it('should handle numeric strings', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('123')).toBe('123'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('version2')).toBe('version2'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('test123Variable')).toBe('test123-variable'); }); it('should handle special characters', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('test@email.com')).toBe('test@email.com'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('file.name.extension')).toBe('file.name.extension'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('path/to/file')).toBe('path/to/file'); }); it('should handle mixed case with numbers', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('HTML5Parser')).toBe('html5-parser'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('CSS3Styles')).toBe('css3-styles'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('API2Client')).toBe('api2-client'); }); it('should handle consecutive uppercase letters', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('XMLParser')).toBe('xmlparser'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('HTTPSRequest')).toBe('httpsrequest'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('JSONData')).toBe('jsondata'); }); }); describe('Purpose: Test boundary conditions', () => { it('should handle very long strings', () => { const longString = 'thisIsAVeryLongCamelCaseStringThatShouldBeConvertedToKebabCase'; const expected = 'this-is-avery-long-camel-case-string-that-should-be-converted-to-kebab-case'; expect((0, formatting_1.normalizeToKebabOrSnakeCase)(longString)).toBe(expected); }); it('should handle single character strings', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('a')).toBe('a'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('A')).toBe('a'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('1')).toBe('1'); }); it('should handle strings with only special characters', () => { expect((0, formatting_1.normalizeToKebabOrSnakeCase)('___')).toBe('___'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('---')).toBe('---'); expect((0, formatting_1.normalizeToKebabOrSnakeCase)('...')).toBe('...'); }); }); describe('Purpose: Test performance with various input sizes', () => { it('should handle repeated transformations consistently', () => { const input = 'testCamelCaseString'; const expected = 'test-camel-case-string'; for (let i = 0; i < 100; i++) { expect((0, formatting_1.normalizeToKebabOrSnakeCase)(input)).toBe(expected); } }); it('should handle array of different string formats', () => { const inputs = [ 'camelCase', 'PascalCase', 'snake_case', 'kebab-case', 'UPPERCASE', 'lowercase', 'Mixed_Format-String' ]; const results = inputs.map(input => (0, formatting_1.normalizeToKebabOrSnakeCase)(input)); expect(results).toEqual([ 'camel-case', 'pascal-case', 'snake_case', 'kebab-case', 'uppercase', 'lowercase', 'mixed_format-string' ]); }); }); }); });