mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-27 18:20:40 +00:00
785de9231a
Replaces the wordle stub with a full implementation mirroring the loldle module layout: compare/lookup/daily/render/state/handlers/index split, per-subject KV state, standard 6 guesses, two-pass duplicate-letter marking. Commands: /wordle, /wordle_new, /wordle_giveup, /wordle_stats. Word list (14,855 entries) sourced from dracos's gist (https://gist.github.com/dracos/dd0668f281e685bad51479e5acaadb93) and bundled via scripts/build-wordle-data.js. Credits in module README and generated file headers. Dispatcher test updated for the new command count (12 → 13).
40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import { makeWordSet, normalizeWord, validateGuess } from "../../../src/modules/wordle/lookup.js";
|
|
|
|
const dict = makeWordSet(["crane", "shale", "abbey", "lever"]);
|
|
|
|
describe("normalizeWord", () => {
|
|
it("lowercases and strips non-letters", () => {
|
|
expect(normalizeWord(" CRANE ")).toBe("crane");
|
|
expect(normalizeWord("cr-ane")).toBe("crane");
|
|
expect(normalizeWord("cr4ne")).toBe("crne");
|
|
});
|
|
|
|
it("handles null/undefined/empty", () => {
|
|
expect(normalizeWord("")).toBe("");
|
|
expect(normalizeWord(null)).toBe("");
|
|
expect(normalizeWord(undefined)).toBe("");
|
|
});
|
|
});
|
|
|
|
describe("validateGuess", () => {
|
|
it("accepts in-dictionary 5-letter words", () => {
|
|
expect(validateGuess(dict, "crane")).toEqual({ ok: true, word: "crane" });
|
|
expect(validateGuess(dict, "CRANE")).toEqual({ ok: true, word: "crane" });
|
|
});
|
|
|
|
it("rejects empty input as 'empty'", () => {
|
|
expect(validateGuess(dict, "")).toMatchObject({ ok: false, reason: "empty" });
|
|
expect(validateGuess(dict, "---")).toMatchObject({ ok: false, reason: "empty" });
|
|
});
|
|
|
|
it("rejects wrong length as 'length'", () => {
|
|
expect(validateGuess(dict, "cat")).toMatchObject({ ok: false, reason: "length" });
|
|
expect(validateGuess(dict, "catnaps")).toMatchObject({ ok: false, reason: "length" });
|
|
});
|
|
|
|
it("rejects unknown word as 'unknown'", () => {
|
|
expect(validateGuess(dict, "zzzzz")).toMatchObject({ ok: false, reason: "unknown" });
|
|
});
|
|
});
|