Skip to content

Commit 902f16f

Browse files
authored
chore(scripts): add unit tests for toCamelCase utility (#359)
1 parent 98f99cf commit 902f16f

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

scripts/build-languages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { $ } from "bun";
22
import hljs from "highlight.js";
33
import type { ModuleNames } from "./build-styles";
44
import { createMarkdown } from "./utils/create-markdown";
5-
import { toCamelCase } from "./utils/to-pascal-case";
5+
import { toCamelCase } from "./utils/to-camel-case";
66
import { writeTo } from "./utils/write-to";
77

88
export async function buildLanguages() {

scripts/build-styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "node:path";
33
import postcss from "postcss";
44
import { createMarkdown } from "./utils/create-markdown";
55
import { minifyCss } from "./utils/minify-css";
6-
import { toCamelCase } from "./utils/to-pascal-case";
6+
import { toCamelCase } from "./utils/to-camel-case";
77
import { writeTo } from "./utils/write-to";
88

99
const createScopedStyles = (props: { source: string; moduleName: string }) => {

scripts/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { createMarkdown } from "./create-markdown";
2-
export { toCamelCase } from "./to-pascal-case";
2+
export { toCamelCase } from "./to-camel-case";
33
export { writeTo } from "./write-to";

scripts/utils/to-pascal-case.ts renamed to scripts/utils/to-camel-case.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Converts a dash/period separated string into pascal case
33
* @example
44
* "one-two-three" --> "oneTwoThree"
5+
* "one.two.three" --> "oneTwoThree"
56
*/
67
export const toCamelCase = (str: string) =>
78
str

tests/to-camel-case.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, it } from "bun:test";
2+
import { toCamelCase } from "../scripts/utils/to-camel-case";
3+
4+
describe("toCamelCase", () => {
5+
it("should convert dash-separated strings to camelCase", () => {
6+
expect(toCamelCase("one-two-three")).toBe("oneTwoThree");
7+
expect(toCamelCase("hello-world")).toBe("helloWorld");
8+
expect(toCamelCase("first-name")).toBe("firstName");
9+
});
10+
11+
it("should convert period-separated strings to camelCase", () => {
12+
expect(toCamelCase("one.two.three")).toBe("oneTwoThree");
13+
expect(toCamelCase("hello.world")).toBe("helloWorld");
14+
expect(toCamelCase("first.name")).toBe("firstName");
15+
});
16+
17+
it("should handle mixed dash and period separators", () => {
18+
expect(toCamelCase("one.two-three")).toBe("oneTwoThree");
19+
expect(toCamelCase("hello-world.example")).toBe("helloWorldExample");
20+
});
21+
22+
it("should handle single word inputs", () => {
23+
expect(toCamelCase("word")).toBe("word");
24+
expect(toCamelCase("hello")).toBe("hello");
25+
});
26+
27+
it("should preserve existing casing", () => {
28+
expect(toCamelCase("already-Capitalized-Word")).toBe(
29+
"alreadyCapitalizedWord",
30+
);
31+
expect(toCamelCase("UPPER.case.words")).toBe("UPPERCaseWords");
32+
});
33+
});

0 commit comments

Comments
 (0)