|
1 | 1 | import { describe, expect, test } from "vitest"; |
2 | | -import { upperCaseFirst } from "./string.utils"; |
| 2 | +import { |
| 3 | + camelCaseToSnakeCase, |
| 4 | + lowerCaseFirst, |
| 5 | + snakeCaseToCamelCase, |
| 6 | + upperCaseFirst, |
| 7 | +} from "./string.utils"; |
3 | 8 |
|
4 | 9 | describe("upperCaseFirst", () => { |
5 | 10 | test("should return an empty string when input is an empty string", () => { |
@@ -27,3 +32,64 @@ describe("upperCaseFirst", () => { |
27 | 32 | expect(upperCaseFirst(" hello")).toBe(" hello"); |
28 | 33 | }); |
29 | 34 | }); |
| 35 | + |
| 36 | +describe("lowerCaseFirst", () => { |
| 37 | + test("should return an empty string when input is an empty string", () => { |
| 38 | + expect(lowerCaseFirst("")).toBe(""); |
| 39 | + }); |
| 40 | + |
| 41 | + test("should lowercase the first letter of a single character string", () => { |
| 42 | + expect(lowerCaseFirst("A")).toBe("a"); |
| 43 | + }); |
| 44 | + |
| 45 | + test("should lowercase the first letter of a multiple character string", () => { |
| 46 | + expect(lowerCaseFirst("Hello")).toBe("hello"); |
| 47 | + }); |
| 48 | + |
| 49 | + test("should return the same string if the first character is already lowercase", () => { |
| 50 | + expect(lowerCaseFirst("hello")).toBe("hello"); |
| 51 | + }); |
| 52 | + |
| 53 | + test("should handle strings with special characters correctly", () => { |
| 54 | + expect(lowerCaseFirst("!Hello")).toBe("!Hello"); |
| 55 | + expect(lowerCaseFirst("123Hello")).toBe("123Hello"); |
| 56 | + }); |
| 57 | + |
| 58 | + test("should handle strings with leading whitespace correctly", () => { |
| 59 | + expect(lowerCaseFirst(" Hello")).toBe(" Hello"); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | +describe("camelCaseToSnakeCase", () => { |
| 64 | + test("should convert camelCase to snake_case", () => { |
| 65 | + expect(camelCaseToSnakeCase("helloWorld")).toBe("hello_world"); |
| 66 | + }); |
| 67 | + |
| 68 | + test("should handle strings with special characters correctly", () => { |
| 69 | + expect(camelCaseToSnakeCase("helloWorld!")).toBe("hello_world!"); |
| 70 | + expect(camelCaseToSnakeCase("helloWorld123")).toBe("hello_world123"); |
| 71 | + }); |
| 72 | + |
| 73 | + test("should handle strings with leading whitespace correctly", () => { |
| 74 | + expect(camelCaseToSnakeCase(" helloWorld")).toBe(" hello_world"); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +describe("snakeCaseToCamelCase", () => { |
| 79 | + test("should convert snake_case to camelCase", () => { |
| 80 | + expect(snakeCaseToCamelCase("hello_world")).toBe("HelloWorld"); |
| 81 | + }); |
| 82 | + |
| 83 | + test("should convert snake_case to lowerCamelCase", () => { |
| 84 | + expect(snakeCaseToCamelCase("hello_world", true)).toBe("helloWorld"); |
| 85 | + }); |
| 86 | + |
| 87 | + test("should handle strings with special characters correctly", () => { |
| 88 | + expect(snakeCaseToCamelCase("hello_world!")).toBe("HelloWorld!"); |
| 89 | + expect(snakeCaseToCamelCase("hello_world123")).toBe("HelloWorld123"); |
| 90 | + }); |
| 91 | + |
| 92 | + test("should handle strings with leading whitespace correctly", () => { |
| 93 | + expect(snakeCaseToCamelCase(" hello_world")).toBe(" helloWorld"); |
| 94 | + }); |
| 95 | +}); |
0 commit comments