File size: 1,095 Bytes
a33a583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { describe, it, expect } from "vitest";
import { normalizePhrase, matchRule, DEFAULT_RULES } from "../../lib/rules.js";

describe("normalizePhrase", () => {
    it("uppercases and strips spaces + punctuation", () => {
        expect(normalizePhrase("U OK?")).toBe("UOK");
        expect(normalizePhrase("u ok")).toBe("UOK");
        expect(normalizePhrase("S.O.S")).toBe("SOS");
    });
});

describe("matchRule", () => {
    it("fires on punctuation/spacing variants of the input", () => {
        expect(matchRule("U OK", DEFAULT_RULES)?.output).toBe("Y");
        expect(matchRule("UOK", DEFAULT_RULES)?.output).toBe("Y");
        expect(matchRule("SOS", DEFAULT_RULES)?.output).toBe("WTF");
    });

    it("returns null for no match or empty text", () => {
        expect(matchRule("HELLO", DEFAULT_RULES)).toBeNull();
        expect(matchRule("", DEFAULT_RULES)).toBeNull();
    });

    it("ignores rules missing input or output", () => {
        const rules = [{ input: "A", output: "" }, { input: "", output: "B" }];
        expect(matchRule("A", rules)).toBeNull();
    });
});