import { describe, expect, it } from "vitest"; import { countStructuredKeyTrieBranches, createStructuredKeyTrie, deleteStructuredKeyTrieEntry, getStructuredKeyTrieNode, } from "./structured-key-trie"; describe("structured key trie", () => { it("prunes empty branches and releases parent object keys", () => { const root = createStructuredKeyTrie(); const source = { id: "source" }; const first = getStructuredKeyTrieNode(root, [source, "first"], true)!; const second = getStructuredKeyTrieNode(root, [source, "second"], true)!; first.entry = "first-entry"; second.entry = "second-entry"; expect(countStructuredKeyTrieBranches(root)).toBe(3); expect(deleteStructuredKeyTrieEntry(root, first, "first-entry")).toBe(true); expect(countStructuredKeyTrieBranches(root)).toBe(2); expect(first.parent).toBeUndefined(); expect(first.parentKey).toBeUndefined(); expect(deleteStructuredKeyTrieEntry(root, second, "second-entry")).toBe(true); expect(countStructuredKeyTrieBranches(root)).toBe(0); expect(root.children.size).toBe(0); expect(second.parent).toBeUndefined(); expect(second.parentKey).toBeUndefined(); }); });