pashto-inflector/src/lib/diacritics-helpers.test.ts

104 lines
2.0 KiB
TypeScript
Raw Normal View History

import {
splitFIntoPhonemes,
last,
addP,
prev2Chars,
advanceP,
reverseP,
overwriteP,
advanceForAin,
advanceForAinOrHamza,
advanceForHamzaMid,
} from "./diacritics-helpers";
const phonemeSplits: Array<{
in: string,
out: string[],
}> = [
{
in: "kor",
out: ["k", "o", "r"],
},
{
in: "raaghey",
out: ["r", "aa", "gh", "ey"],
},
{
in: "hatsa",
out: ["h", "a", "ts", "a"],
},
{
in: "ba",
out: ["b", "a"],
},
{
in: "peydáa",
out: ["p", "ey", "d", "aa"],
},
{
in: "be kaar",
out: ["b", "e", "k", "aa", "r"],
},
{
in: "raadzeyy",
out: ["r", "aa", "dz", "eyy"],
},
{
in: "badanuy ??",
out: ["b", "a", "d", "a", "n", "uy"],
},
{
in: "tur ... pore",
out: ["t", "u", "r", "p", "o", "r", "e"],
},
{
in: "daar-Ul-iqaama",
out: ["d", "aa", "r", "-Ul-", "i", "q", "aa", "m", "a"],
},
];
phonemeSplits.forEach((s) => {
test(`${s.in} should split properly`, () => {
const result = splitFIntoPhonemes(s.in);
expect(result).toEqual(s.out);
});
});
const badPhonetics: Array<{
in: string,
problem: string,
}> = [
{
in: "acar",
problem: "c",
},
{
in: "a7am",
problem: "7",
},
];
test("bad phonetic characters should throw an error", () => {
badPhonetics.forEach((s) => {
expect(() => {
splitFIntoPhonemes(s.in);
}).toThrow(`illegal phonetic character: ${s.problem}`);
});
});
test("last should work", () => {
expect(last("this")).toBe("s");
});
test("addP should work", () => {
expect(addP("ت")({ pIn: "", pOut: "کر" })).toEqual({
pIn: "",
pOut: "کرت",
});
});
test("prev2Chars should work", () => {
expect(prev2Chars("تورن")).toBe("رن");
expect(prev2Chars("وست .. ")).toBe("ست");
expect(prev2Chars("دَ ... ")).toBe("دَ");
});