"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const node_assert_1 = require("node:assert");
const zamboni_js_1 = require("../zamboni.js");
const testClient_js_1 = require("./testClient.js");
describe("Zamboni Logic", () => {
    let client;
    const localUserLongId = "localUser";
    beforeEach(() => {
        client = new testClient_js_1.TestClient();
        for (const c of "hello world") {
            client.insertTextLocal(client.getLength(), c);
        }
        client.startOrUpdateCollaboration(localUserLongId);
    });
    it("packParent with no children segments", () => {
        client.applyMsg(client.makeOpMessage(client.removeRangeLocal(0, client.getLength() - 1), 1));
        (0, zamboni_js_1.packParent)(client.mergeTree.root, client.mergeTree);
        node_assert_1.strict.equal(client.mergeTree.root.cachedLength, 1);
        client.applyMsg(client.makeOpMessage(client.removeRangeLocal(0, client.getLength()), client.getCurrentSeq(), client.getCurrentSeq(), undefined, client.getCurrentSeq()));
        node_assert_1.strict.equal(client.mergeTree.root.cachedLength ?? 0, 0);
        (0, zamboni_js_1.packParent)(client.mergeTree.root, client.mergeTree);
        node_assert_1.strict.equal(client.mergeTree.root.childCount, 0);
    });
    it("zamboni with no segments to scour", () => {
        const cachedLength = client.mergeTree.root.cachedLength;
        const childCount = client.mergeTree.root.childCount;
        (0, zamboni_js_1.zamboniSegments)(client.mergeTree);
        node_assert_1.strict.equal(cachedLength, client.mergeTree.root.cachedLength);
        node_assert_1.strict.equal(childCount, client.mergeTree.root.childCount);
    });
    it("zamboni with one segment to scour", () => {
        const initialChildCount = client.mergeTree.root.children[0].childCount;
        const initialCachedLength = client.mergeTree.root.cachedLength ?? 0;
        client.removeRangeLocal(0, 1);
        (0, zamboni_js_1.zamboniSegments)(client.mergeTree);
        node_assert_1.strict.equal(client.mergeTree.root.cachedLength, initialCachedLength - 1);
        node_assert_1.strict.equal(client.mergeTree.root.children[0].childCount, initialChildCount);
    });
    it("zamboni with many segments to scour", () => {
        client.removeRangeLocal(0, 6);
        node_assert_1.strict.equal(client.mergeTree.root.children[0].cachedLength, 0);
        (0, zamboni_js_1.zamboniSegments)(client.mergeTree);
        (0, zamboni_js_1.packParent)(client.mergeTree.root, client.mergeTree);
        node_assert_1.strict.equal(client.mergeTree.root.childCount, 1);
    });
});
//# sourceMappingURL=mergeTree.zamboni.spec.js.map