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

100 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-03-09 12:39:13 +00:00
/**
* Copyright (c) 2021 lingdocs.com
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { makePsString } from "./accent-and-ps-utils";
2021-03-09 12:39:13 +00:00
import {
accentOnFront,
accentPastParticiple,
accentFSylsOnNFromEnd,
accentOnNFromEnd,
splitUpSyllables,
2021-09-03 11:27:02 +00:00
hasAccents,
2021-10-18 01:26:49 +00:00
countSyllables,
2021-03-09 12:39:13 +00:00
} from "./accent-helpers";
const toAccentFront = [
{
input: makePsString("پرېښودل", "prexodúl"),
output: makePsString("پرېښودل", "préxodul"),
},
{
input: {
long: makePsString("وګرځېد", "oogurdzed"),
short: makePsString("وګرځ", "oogurdz"),
},
output: {
long: makePsString("وګرځېد", "óogurdzed"),
short: makePsString("وګرځ", "óogurdz"),
},
},
];
test(`accentOnFront should work`, () => {
toAccentFront.forEach((item) => {
expect(accentOnFront(item.input)).toEqual(item.output);
});
});
const toAccentPastParticiple = [
{
input: makePsString("پرېښی", "prexey"),
output: makePsString("پرېښی", "préxey"),
},
{
input: makePsString("ازمویلی", "azmoyuley"),
output: makePsString("ازمویلی", "azmóyuley"),
},
];
test(`accentPastParticiple should work`, () => {
toAccentPastParticiple.forEach((item) => {
expect(accentPastParticiple(item.input)).toEqual(item.output);
});
});
test(`splitUpSyllables should work`, () => {
expect(splitUpSyllables("akheestul")).toEqual(["akh", "eest", "ul"]);
});
2021-10-18 01:26:49 +00:00
test("countSyllables", () => {
expect(countSyllables("saRéy")).toEqual(2);
expect(countSyllables("saRey")).toEqual(2);
expect(countSyllables("zRú")).toEqual(1);
expect(countSyllables("zRu")).toEqual(1);
expect(countSyllables("zRU")).toEqual(1);
expect(countSyllables("tbtkz")).toEqual(0);
expect(countSyllables({ p: "اونۍ", f: "onúy, ownúy" })).toEqual(2);
});
2021-03-09 12:39:13 +00:00
test(`accentOnFSylsOnNFromEnd should work`, () => {
expect(accentFSylsOnNFromEnd(["pu", "xtaa", "nu"], 0)).toBe("puxtaanú");
expect(accentFSylsOnNFromEnd(["leed", "ul", "ey"], 1)).toBe("leedúley");
});
test(`accentOnNFromEnd should work`, () => {
expect(accentOnNFromEnd({ p: "پښتانه", f: "puxtaanu" }, 0)).toEqual({
p: "پښتانه",
f: "puxtaanú",
});
expect(accentOnNFromEnd({ p: "لیدلی", f: "leedúley" }, 1)).toEqual({
p: "لیدلی",
f: "leedúley",
});
});
2021-09-03 11:27:02 +00:00
test(`has accents should work`, () => {
const accents = ["koRanúy", "wutáaq", "gÚta", "taté", "bít", "sóra", "kúcha"];
const noAccents = ["koRanuy", "wutaaq", "gUta", "tate", "bit", "sora", "kucha"];
accents.forEach((x) => {
expect(hasAccents(x)).toBe(true);
});
noAccents.forEach((x) => {
expect(hasAccents(x)).toBe(false);
});
})