|
| 1 | +import { expect, test } from 'bun:test' |
| 2 | +import { convertCase } from '../convert-case' |
| 3 | + |
| 4 | +test.each([ |
| 5 | + ['hello_world', 'snake', 'hello_world'], |
| 6 | + ['my_variable_name', 'snake', 'my_variable_name'], |
| 7 | + ['snake_case_string', 'snake', 'snake_case_string'], |
| 8 | +])('converts to snake_case: %s -> %s', (input, caseType, expected) => { |
| 9 | + expect(convertCase(input, caseType as 'snake')).toBe(expected) |
| 10 | +}) |
| 11 | + |
| 12 | +test.each([ |
| 13 | + ['HelloWorld', 'snake', 'hello_world'], |
| 14 | + ['MyVariableName', 'snake', 'my_variable_name'], |
| 15 | + ['PascalCaseString', 'snake', 'pascal_case_string'], |
| 16 | +])('converts PascalCase to snake_case: %s -> %s', (input, caseType, expected) => { |
| 17 | + expect(convertCase(input, caseType as 'snake')).toBe(expected) |
| 18 | +}) |
| 19 | + |
| 20 | +test.each([ |
| 21 | + ['helloWorld', 'snake', 'hello_world'], |
| 22 | + ['myVariableName', 'snake', 'my_variable_name'], |
| 23 | + ['camelCaseString', 'snake', 'camel_case_string'], |
| 24 | +])('converts camelCase to snake_case: %s -> %s', (input, caseType, expected) => { |
| 25 | + expect(convertCase(input, caseType as 'snake')).toBe(expected) |
| 26 | +}) |
| 27 | + |
| 28 | +test.each([ |
| 29 | + ['hello_world', 'camel', 'helloWorld'], |
| 30 | + ['my_variable_name', 'camel', 'myVariableName'], |
| 31 | + ['snake_case_string', 'camel', 'snakeCaseString'], |
| 32 | +])('converts to camelCase: %s -> %s', (input, caseType, expected) => { |
| 33 | + expect(convertCase(input, caseType as 'camel')).toBe(expected) |
| 34 | +}) |
| 35 | + |
| 36 | +test.each([ |
| 37 | + ['HelloWorld', 'camel', 'helloWorld'], |
| 38 | + ['MyVariableName', 'camel', 'myVariableName'], |
| 39 | + ['PascalCaseString', 'camel', 'pascalCaseString'], |
| 40 | +])('converts PascalCase to camelCase: %s -> %s', (input, caseType, expected) => { |
| 41 | + expect(convertCase(input, caseType as 'camel')).toBe(expected) |
| 42 | +}) |
| 43 | + |
| 44 | +test.each([ |
| 45 | + ['helloWorld', 'camel', 'helloWorld'], |
| 46 | + ['myVariableName', 'camel', 'myVariableName'], |
| 47 | + ['camelCaseString', 'camel', 'camelCaseString'], |
| 48 | +])('returns camelCase strings unchanged: %s -> %s', (input, caseType, expected) => { |
| 49 | + expect(convertCase(input, caseType as 'camel')).toBe(expected) |
| 50 | +}) |
| 51 | + |
| 52 | +test.each([ |
| 53 | + ['hello_world', 'pascal', 'HelloWorld'], |
| 54 | + ['my_variable_name', 'pascal', 'MyVariableName'], |
| 55 | + ['snake_case_string', 'pascal', 'SnakeCaseString'], |
| 56 | +])('converts to PascalCase: %s -> %s', (input, caseType, expected) => { |
| 57 | + expect(convertCase(input, caseType as 'pascal')).toBe(expected) |
| 58 | +}) |
| 59 | + |
| 60 | +test.each([ |
| 61 | + ['helloWorld', 'pascal', 'HelloWorld'], |
| 62 | + ['myVariableName', 'pascal', 'MyVariableName'], |
| 63 | + ['camelCaseString', 'pascal', 'CamelCaseString'], |
| 64 | +])('converts camelCase to PascalCase: %s -> %s', (input, caseType, expected) => { |
| 65 | + expect(convertCase(input, caseType as 'pascal')).toBe(expected) |
| 66 | +}) |
| 67 | + |
| 68 | +test.each([ |
| 69 | + ['HelloWorld', 'pascal', 'HelloWorld'], |
| 70 | + ['MyVariableName', 'pascal', 'MyVariableName'], |
| 71 | + ['PascalCaseString', 'pascal', 'PascalCaseString'], |
| 72 | +])('returns PascalCase strings unchanged: %s -> %s', (input, caseType, expected) => { |
| 73 | + expect(convertCase(input, caseType as 'pascal')).toBe(expected) |
| 74 | +}) |
| 75 | + |
| 76 | +test.each([ |
| 77 | + ['hello_world', 'maintain', 'hello_world'], |
| 78 | + ['myVariableName', 'maintain', 'myVariableName'], |
| 79 | + ['HelloWorld', 'maintain', 'HelloWorld'], |
| 80 | + ['any_string-here', 'maintain', 'any_string-here'], |
| 81 | +])('maintains original case: %s -> %s', (input, caseType, expected) => { |
| 82 | + expect(convertCase(input, caseType as 'maintain')).toBe(expected) |
| 83 | +}) |
| 84 | + |
| 85 | +test.each([ |
| 86 | + ['hello_world', undefined, 'helloWorld'], |
| 87 | + ['my_variable_name', undefined, 'myVariableName'], |
| 88 | + ['snake_case_string', undefined, 'snakeCaseString'], |
| 89 | +])('defaults to camelCase when caseType is undefined: %s -> %s', (input, caseType, expected) => { |
| 90 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default behavior with undefined caseType |
| 91 | + expect(convertCase(input, caseType as any)).toBe(expected) |
| 92 | +}) |
| 93 | + |
| 94 | +test.each([ |
| 95 | + ['hello_world', 'helloWorld'], |
| 96 | + ['my_variable_name', 'myVariableName'], |
| 97 | + ['snake_case_string', 'snakeCaseString'], |
| 98 | +])('defaults to camelCase when caseType is not provided: %s -> %s', (input, expected) => { |
| 99 | + expect(convertCase(input)).toBe(expected) |
| 100 | +}) |
| 101 | + |
| 102 | +test.each([ |
| 103 | + ['', 'camel', ''], |
| 104 | + ['a', 'camel', 'a'], |
| 105 | + ['A', 'camel', 'a'], |
| 106 | +])('handles empty string and single characters: %s -> %s', (input, caseType, expected) => { |
| 107 | + expect(convertCase(input, caseType as 'camel')).toBe(expected) |
| 108 | +}) |
| 109 | + |
| 110 | +test.each([ |
| 111 | + ['hello_world123', 'camel', 'helloWorld123'], |
| 112 | + ['my_variable2_name', 'camel', 'myVariable2Name'], |
| 113 | + ['test123_case', 'camel', 'test123Case'], |
| 114 | +])('handles strings with numbers: %s -> %s', (input, caseType, expected) => { |
| 115 | + expect(convertCase(input, caseType as 'camel')).toBe(expected) |
| 116 | +}) |
| 117 | + |
| 118 | +test.each([ |
| 119 | + ['hello_world', 'invalid', 'hello_world'], |
| 120 | + ['myVariableName', 'unknown', 'myVariableName'], |
| 121 | + ['HelloWorld', 'wrong', 'HelloWorld'], |
| 122 | +])('default case returns original string for invalid caseType: %s -> %s', (input, caseType, expected) => { |
| 123 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default case with invalid caseType values |
| 124 | + expect(convertCase(input, caseType as any)).toBe(expected) |
| 125 | +}) |
0 commit comments