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