|
| 1 | +import { describe, expect, it } from '@effect/vitest'; |
| 2 | + |
| 3 | +// @ts-ignore - fix the ts setup |
| 4 | +import { toCamelCase, toPascalCase } from '../src/Utils.js'; |
| 5 | + |
| 6 | +describe('toCamelCase', () => { |
| 7 | + it('should convert space-separated words to camelCase', () => { |
| 8 | + expect(toCamelCase('Address line 1')).toBe('addressLine1'); |
| 9 | + expect(toCamelCase('Academic field')).toBe('academicField'); |
| 10 | + expect(toCamelCase('User profile')).toBe('userProfile'); |
| 11 | + expect(toCamelCase('Email address')).toBe('emailAddress'); |
| 12 | + expect(toCamelCase('Phone number')).toBe('phoneNumber'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should convert underscore-separated words to camelCase', () => { |
| 16 | + expect(toCamelCase('address_line_1')).toBe('addressLine1'); |
| 17 | + expect(toCamelCase('user_profile')).toBe('userProfile'); |
| 18 | + expect(toCamelCase('email_address')).toBe('emailAddress'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should convert hyphen-separated words to camelCase', () => { |
| 22 | + expect(toCamelCase('address-line-1')).toBe('addressLine1'); |
| 23 | + expect(toCamelCase('user-profile')).toBe('userProfile'); |
| 24 | + expect(toCamelCase('email-address')).toBe('emailAddress'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should convert mixed separators to camelCase', () => { |
| 28 | + expect(toCamelCase('address-line_1')).toBe('addressLine1'); |
| 29 | + expect(toCamelCase('address-line 1')).toBe('addressLine1'); |
| 30 | + expect(toCamelCase('user_profile-name')).toBe('userProfileName'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should handle already camelCase strings', () => { |
| 34 | + expect(toCamelCase('addressLine1')).toBe('addressLine1'); |
| 35 | + expect(toCamelCase('userProfile')).toBe('userProfile'); |
| 36 | + expect(toCamelCase('emailAddress')).toBe('emailAddress'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should handle PascalCase strings', () => { |
| 40 | + expect(toCamelCase('AddressLine1')).toBe('addressLine1'); |
| 41 | + expect(toCamelCase('UserProfile')).toBe('userProfile'); |
| 42 | + expect(toCamelCase('EmailAddress')).toBe('emailAddress'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should handle uppercase strings', () => { |
| 46 | + expect(toCamelCase('ADDRESS_LINE_1')).toBe('addressLine1'); |
| 47 | + expect(toCamelCase('USER_PROFILE')).toBe('userProfile'); |
| 48 | + expect(toCamelCase('EMAIL_ADDRESS')).toBe('emailAddress'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should handle single words', () => { |
| 52 | + expect(toCamelCase('Address')).toBe('address'); |
| 53 | + expect(toCamelCase('User')).toBe('user'); |
| 54 | + expect(toCamelCase('Email')).toBe('email'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should handle numbers', () => { |
| 58 | + expect(toCamelCase('Address1')).toBe('address1'); |
| 59 | + expect(toCamelCase('User2')).toBe('user2'); |
| 60 | + expect(toCamelCase('Email3')).toBe('email3'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should skip leading non-alphanumeric characters', () => { |
| 64 | + expect(toCamelCase('!Address')).toBe('address'); |
| 65 | + expect(toCamelCase('@User')).toBe('user'); |
| 66 | + expect(toCamelCase('#Email')).toBe('email'); |
| 67 | + expect(toCamelCase(' Address')).toBe('address'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should throw error for empty input or whitespace-only input', () => { |
| 71 | + expect(() => toCamelCase('')).toThrow(); |
| 72 | + expect(() => toCamelCase(' ')).toThrow(); |
| 73 | + expect(() => toCamelCase(' ')).toThrow(); |
| 74 | + expect(() => toCamelCase('\t')).toThrow(); |
| 75 | + expect(() => toCamelCase('\n')).toThrow(); |
| 76 | + expect(() => toCamelCase(' \t \n ')).toThrow(); |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +describe('toPascalCase', () => { |
| 81 | + it('should convert space-separated words to PascalCase', () => { |
| 82 | + expect(toPascalCase('Address line 1')).toBe('AddressLine1'); |
| 83 | + expect(toPascalCase('Academic field')).toBe('AcademicField'); |
| 84 | + expect(toPascalCase('User profile')).toBe('UserProfile'); |
| 85 | + expect(toPascalCase('Email address')).toBe('EmailAddress'); |
| 86 | + expect(toPascalCase('Phone number')).toBe('PhoneNumber'); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should convert underscore-separated words to PascalCase', () => { |
| 90 | + expect(toPascalCase('address_line_1')).toBe('AddressLine1'); |
| 91 | + expect(toPascalCase('user_profile')).toBe('UserProfile'); |
| 92 | + expect(toPascalCase('email_address')).toBe('EmailAddress'); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should convert hyphen-separated words to PascalCase', () => { |
| 96 | + expect(toPascalCase('address-line-1')).toBe('AddressLine1'); |
| 97 | + expect(toPascalCase('user-profile')).toBe('UserProfile'); |
| 98 | + expect(toPascalCase('email-address')).toBe('EmailAddress'); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should convert mixed separators to PascalCase', () => { |
| 102 | + expect(toPascalCase('address-line_1')).toBe('AddressLine1'); |
| 103 | + expect(toPascalCase('address-line 1')).toBe('AddressLine1'); |
| 104 | + expect(toPascalCase('user_profile-name')).toBe('UserProfileName'); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should handle already PascalCase strings', () => { |
| 108 | + expect(toPascalCase('AddressLine1')).toBe('AddressLine1'); |
| 109 | + expect(toPascalCase('UserProfile')).toBe('UserProfile'); |
| 110 | + expect(toPascalCase('EmailAddress')).toBe('EmailAddress'); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should handle camelCase strings', () => { |
| 114 | + expect(toPascalCase('addressLine1')).toBe('AddressLine1'); |
| 115 | + expect(toPascalCase('userProfile')).toBe('UserProfile'); |
| 116 | + expect(toPascalCase('emailAddress')).toBe('EmailAddress'); |
| 117 | + }); |
| 118 | + |
| 119 | + it('should handle uppercase strings', () => { |
| 120 | + expect(toPascalCase('ADDRESS_LINE_1')).toBe('AddressLine1'); |
| 121 | + expect(toPascalCase('USER_PROFILE')).toBe('UserProfile'); |
| 122 | + expect(toPascalCase('EMAIL_ADDRESS')).toBe('EmailAddress'); |
| 123 | + }); |
| 124 | + |
| 125 | + it('should handle single words', () => { |
| 126 | + expect(toPascalCase('Address')).toBe('Address'); |
| 127 | + expect(toPascalCase('User')).toBe('User'); |
| 128 | + expect(toPascalCase('Email')).toBe('Email'); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should handle numbers', () => { |
| 132 | + expect(toPascalCase('Address1')).toBe('Address1'); |
| 133 | + expect(toPascalCase('User2')).toBe('User2'); |
| 134 | + expect(toPascalCase('Email3')).toBe('Email3'); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should skip leading non-alphanumeric characters', () => { |
| 138 | + expect(toPascalCase('!Address')).toBe('Address'); |
| 139 | + expect(toPascalCase('@User')).toBe('User'); |
| 140 | + expect(toPascalCase('#Email')).toBe('Email'); |
| 141 | + expect(toPascalCase(' Address')).toBe('Address'); |
| 142 | + }); |
| 143 | + |
| 144 | + it('should throw error for empty input or whitespace-only input', () => { |
| 145 | + expect(() => toPascalCase('')).toThrow(); |
| 146 | + expect(() => toPascalCase(' ')).toThrow(); |
| 147 | + expect(() => toPascalCase(' ')).toThrow(); |
| 148 | + expect(() => toPascalCase('\t')).toThrow(); |
| 149 | + expect(() => toPascalCase('\n')).toThrow(); |
| 150 | + expect(() => toPascalCase(' \t \n ')).toThrow(); |
| 151 | + }); |
| 152 | +}); |
0 commit comments