Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions frontend/__tests__/test/funbox/funbox-functions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, it, expect } from "vitest";
import {
getFunboxFunctions,
FunboxFunctions,
} from "../../../src/ts/test/funbox/funbox-functions";

describe("funbox functions", () => {
describe("l33t funbox", () => {
const funboxFunctions = getFunboxFunctions();
const l33tFunbox = funboxFunctions.l33t as Required<
Pick<FunboxFunctions, "alterText">
>;

const alterText = (word: string): string =>
l33tFunbox.alterText(word, 0, word.length);

it("should convert lowercase letters to l33t speak", () => {
expect(alterText("hello world")).toBe("h3110 w0r1d");
});

it("should handle uppercase letters", () => {
expect(alterText("Hello")).toBe("H3110");
});

it("should handle mixed case", () => {
expect(alterText("HeLLo")).toBe("H3110");
});

it("should keep non-letter characters unchanged", () => {
expect(alterText("h3llo!")).toBe("h3110!");
});

it("should handle spaces", () => {
const result = alterText("hello world");
expect(result.startsWith("h3110 ")).toBe(true);
expect(result.endsWith("w0r1d")).toBe(true);
expect(result).not.toContain("/");
});

it("should handle all l33t characters", () => {
expect(alterText("abcdefg")).toBe("4bcd3f6");
});

it("should handle all l33t characters (uppercase)", () => {
expect(alterText("ABCDEFG")).toBe("4BCD3F6");
});

it("should convert xyz to l33t", () => {
expect(alterText("xyz")).toBe("xy2");
});

it("should handle empty string", () => {
expect(alterText("")).toBe("");
});

it("should handle string with no letters", () => {
expect(alterText("123 !@#")).toBe("123 !@#");
});
});
});
20 changes: 20 additions & 0 deletions frontend/src/ts/test/funbox/funbox-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ export class PolyglotWordset extends Wordset {
}
}

const l33tMap: Record<string, string> = {
a: "4",
e: "3",

g: "6",
i: "1",
l: "1",
o: "0",
s: "5",
t: "7",
z: "2",
};

const list: Partial<Record<FunboxName, FunboxFunctions>> = {
"58008": {
getWord(): string {
Expand Down Expand Up @@ -650,6 +663,13 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
return word.toUpperCase();
},
},
l33t: {
alterText(word: string): string {
return word.replace(/[a-zA-Z]/g, (ch) => {
return l33tMap[ch.toLowerCase()] ?? ch;
});
},
},
polyglot: {
async withWords(_words) {
const promises = Config.customPolyglot.map(async (language) =>
Expand Down
8 changes: 8 additions & 0 deletions packages/funbox/src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ const list: Record<FunboxName, FunboxMetadata> = {
difficultyLevel: 0,
name: "no_quit",
},
l33t: {
description: "1 533t 5p34k. C0nv3r7 7h3 73x7 70 l337.",
canGetPb: true,
difficultyLevel: 1,
properties: ["changesCapitalisation"],
frontendFunctions: ["alterText"],
name: "l33t",
},
};

export function getObject(): Record<FunboxName, FunboxMetadata> {
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const FunboxNameSchema = z.enum([
"polyglot",
"asl",
"rot13",
"l33t",
"no_quit",
]);
export type FunboxName = z.infer<typeof FunboxNameSchema>;
Expand Down
Loading