|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | +import { lcFirst, ucFirst } from "./string" |
| 3 | + |
| 4 | +describe("ucFirst", () => { |
| 5 | + test("should uppercase the first character of a string", () => { |
| 6 | + expect(ucFirst("hello")).toBe("Hello") |
| 7 | + expect(ucFirst("world")).toBe("World") |
| 8 | + }) |
| 9 | + |
| 10 | + test("should handle empty strings", () => { |
| 11 | + expect(ucFirst("")).toBe("") |
| 12 | + }) |
| 13 | + |
| 14 | + test("should handle single character strings", () => { |
| 15 | + expect(ucFirst("a")).toBe("A") |
| 16 | + expect(ucFirst("z")).toBe("Z") |
| 17 | + }) |
| 18 | + |
| 19 | + test("should handle non-string inputs", () => { |
| 20 | + expect(ucFirst(null as any)).toBe("") |
| 21 | + expect(ucFirst(undefined as any)).toBe("") |
| 22 | + expect(ucFirst(123 as any)).toBe("") |
| 23 | + }) |
| 24 | + |
| 25 | + test("should preserve the rest of the string", () => { |
| 26 | + expect(ucFirst("hello world")).toBe("Hello world") |
| 27 | + expect(ucFirst("HELLO")).toBe("HELLO") |
| 28 | + }) |
| 29 | +}) |
| 30 | + |
| 31 | +describe("lcFirst", () => { |
| 32 | + test("should lowercase the first character of a string", () => { |
| 33 | + expect(lcFirst("Hello")).toBe("hello") |
| 34 | + expect(lcFirst("World")).toBe("world") |
| 35 | + }) |
| 36 | + |
| 37 | + test("should handle empty strings", () => { |
| 38 | + expect(lcFirst("")).toBe("") |
| 39 | + }) |
| 40 | + |
| 41 | + test("should handle single character strings", () => { |
| 42 | + expect(lcFirst("A")).toBe("a") |
| 43 | + expect(lcFirst("Z")).toBe("z") |
| 44 | + }) |
| 45 | + |
| 46 | + test("should handle non-string inputs", () => { |
| 47 | + expect(lcFirst(null as any)).toBe("") |
| 48 | + expect(lcFirst(undefined as any)).toBe("") |
| 49 | + expect(lcFirst(123 as any)).toBe("") |
| 50 | + }) |
| 51 | + |
| 52 | + test("should preserve the rest of the string", () => { |
| 53 | + expect(lcFirst("Hello World")).toBe("hello World") |
| 54 | + expect(lcFirst("hello")).toBe("hello") |
| 55 | + }) |
| 56 | +}) |
0 commit comments