Skip to content

Commit

Permalink
Merge pull request #144 from charlesLoder/struct-cache
Browse files Browse the repository at this point in the history
Struct cache
  • Loading branch information
charlesLoder authored Oct 31, 2023
2 parents 07c8ef6 + eeb23ff commit 28aed6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/syllable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class Syllable extends Node<Syllable> {
return this.#cachedStructureWithGemination;
}

if (this.#cachedStructure) {
if (!withGemination && this.#cachedStructure) {
return this.#cachedStructure;
}

Expand Down
23 changes: 23 additions & 0 deletions test/syllable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 28aed6f

Please sign in to comment.