import { expect, test } from "vitest" import { stringCalculateUnits, stringCamelCaseToKebabCase, stringHelloWord, stringKebabCaseToCamelCase, stringSliceByUnits, stringSmartSplit, stringSplit, stringTruncate, stringTruncateByUnits, } from "#Source/basic/index.ts" test("stringCamelCaseToKebabCase converts correctly", () => { expect(stringCamelCaseToKebabCase("helloWorld")).toBe("hello-world") expect(stringCamelCaseToKebabCase("ab2Cd")).toBe("ab2-cd") }) test("stringKebabCaseToCamelCase converts correctly", () => { expect(stringKebabCaseToCamelCase("hello-world")).toBe("helloWorld") expect(stringKebabCaseToCamelCase("ab2-cd")).toBe("ab2Cd") }) test("stringHelloWord returns a greeting", () => { const value = stringHelloWord() expect(typeof value).toBe("string") expect(value.length).toBeGreaterThan(0) }) test("stringCalculateUnits counts half-width and full-width", () => { expect(stringCalculateUnits("a中")).toBe(1.5) expect(stringCalculateUnits("中文")).toBe(2) }) test("stringTruncateByUnits respects unit limit", () => { expect(stringTruncateByUnits("a中文", 1.5)).toBe("a中") expect(stringTruncateByUnits("abc", 2)).toBe("abc") }) test("stringSliceByUnits slices by unit indices", () => { expect(stringSliceByUnits("a中文", 0, 1.5)).toBe("a中") expect(stringSliceByUnits("中文ab", 1, 2)).toBe("文") }) test("stringSplit returns overlapping chunks", () => { expect(stringSplit({ input: "hello world", chunkSize: 5, chunkOverlap: 2 })).toEqual([ "hello", "lo wo", "world", ]) }) test("stringSmartSplit respects max length", () => { const parts = stringSmartSplit("a\nb\nc", 2) expect(parts.join("\n")).toContain("a") expect(parts.join("\n")).toContain("b") expect(parts.join("\n")).toContain("c") expect(parts.every((part) => part.length <= 2)).toBe(true) }) test("stringTruncate adds ellipsis", () => { expect(stringTruncate("hello world", 5)).toBe("hello...") expect(stringTruncate("hi", 5)).toBe("hi") })