From 9289db73779efd917a2ded4f773980cff3fd722c Mon Sep 17 00:00:00 2001 From: Charles Loder Date: Mon, 30 Oct 2023 22:57:59 -0400 Subject: [PATCH 1/2] Add tests --- test/syllable.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/syllable.test.ts b/test/syllable.test.ts index 87823e9..c3c07b8 100644 --- a/test/syllable.test.ts +++ b/test/syllable.test.ts @@ -100,6 +100,29 @@ describe.each` }); }); +describe("structure cache", () => { + const str = "סַפִּ֖יר"; + test("without gemination", () => { + const heb = new Text(str); + const syllable = heb.syllables[0]; + // first call to structure() will cache the result + // but use the opposite of what is being tested + syllable.structure(true); + const [syllableOnset, syllableNucleus, syllableCoda] = ["ס", "ַ", ""]; + expect(syllable.structure()).toEqual([syllableOnset, syllableNucleus, syllableCoda]); + }); + + test("with gemination", () => { + const heb = new Text(str); + const syllable = heb.syllables[0]; + // first call to structure() will cache the result + // but use the opposite of what is being tested + syllable.structure(); + const [syllableOnset, syllableNucleus, syllableCoda] = ["ס", "ַ", "פּ"]; + expect(syllable.structure(true)).toEqual([syllableOnset, syllableNucleus, syllableCoda]); + }); +}); + describe.each` description | hebrew | syllableNum | vowel | allowNoNiqqud ${"syllable with patah"} | ${"הַֽ֭יְחָבְרְךָ"} | ${0} | ${"\u{05B7}"} | ${false} From eeb23ffb690cb02c0c9778c5d7d0ffff5eaa1825 Mon Sep 17 00:00:00 2001 From: Charles Loder Date: Mon, 30 Oct 2023 23:02:42 -0400 Subject: [PATCH 2/2] Add check for cache --- src/syllable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/syllable.ts b/src/syllable.ts index 991de4b..4e43646 100644 --- a/src/syllable.ts +++ b/src/syllable.ts @@ -317,7 +317,7 @@ export class Syllable extends Node { return this.#cachedStructureWithGemination; } - if (this.#cachedStructure) { + if (!withGemination && this.#cachedStructure) { return this.#cachedStructure; }