"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = require("assert");
const zamboni_1 = require("../zamboni.cjs");
const testClient_1 = require("./testClient.cjs");
describe("Zamboni Logic", () => {
    let client;
    const localUserLongId = "localUser";
    beforeEach(() => {
        client = new testClient_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_1.packParent)(client.mergeTree.root, client.mergeTree);
        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()));
        assert_1.strict.equal(client.mergeTree.root.cachedLength ?? 0, 0);
        (0, zamboni_1.packParent)(client.mergeTree.root, client.mergeTree);
        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_1.zamboniSegments)(client.mergeTree);
        assert_1.strict.equal(cachedLength, client.mergeTree.root.cachedLength);
        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_1.zamboniSegments)(client.mergeTree);
        assert_1.strict.equal(client.mergeTree.root.cachedLength, initialCachedLength - 1);
        assert_1.strict.equal(client.mergeTree.root.children[0].childCount, initialChildCount);
    });
    it("zamboni with many segments to scour", () => {
        client.removeRangeLocal(0, 6);
        assert_1.strict.equal(client.mergeTree.root.children[0].cachedLength, 0);
        (0, zamboni_1.zamboniSegments)(client.mergeTree);
        (0, zamboni_1.packParent)(client.mergeTree.root, client.mergeTree);
        assert_1.strict.equal(client.mergeTree.root.childCount, 1);
    });
});
//# sourceMappingURL=mergeTree.zamboni.spec.cjs.map