"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 ops_1 = require("../ops.cjs");
const mergeTreeDeltaCallback_1 = require("../mergeTreeDeltaCallback.cjs");
const constants_1 = require("../constants.cjs");
const textSegment_1 = require("../textSegment.cjs");
const mergeTree_1 = require("../mergeTree.cjs");
const testUtils_1 = require("./testUtils.cjs");
describe("MergeTree", () => {
    let mergeTree;
    const localClientId = 17;
    let currentSequenceNumber;
    beforeEach(() => {
        mergeTree = new mergeTree_1.MergeTree();
        (0, testUtils_1.insertSegments)({
            mergeTree,
            pos: 0,
            segments: [textSegment_1.TextSegment.make("hello world")],
            refSeq: constants_1.UniversalSequenceNumber,
            clientId: constants_1.LocalClientId,
            seq: constants_1.UniversalSequenceNumber,
            opArgs: undefined,
        });
        currentSequenceNumber = 0;
        mergeTree.startCollaboration(localClientId, 
        /* minSeq: */ currentSequenceNumber, 
        /* currentSeq: */ currentSequenceNumber);
    });
    describe("annotateRange", () => {
        it("Event on annotation", () => {
            const count = (0, testUtils_1.countOperations)(mergeTree);
            mergeTree.annotateRange(4, 6, {
                foo: "bar",
            }, currentSequenceNumber, localClientId, constants_1.UnassignedSequenceNumber, undefined);
            assert_1.strict.deepStrictEqual(count, {
                [ops_1.MergeTreeDeltaType.ANNOTATE]: 1,
                [mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.SPLIT]: 2,
            });
        });
        it("No event on annotation of empty range", () => {
            const count = (0, testUtils_1.countOperations)(mergeTree);
            mergeTree.annotateRange(3, 3, {
                foo: "bar",
            }, currentSequenceNumber, localClientId, ++currentSequenceNumber, undefined);
            assert_1.strict.deepStrictEqual(count, {
                [mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.SPLIT]: 1,
            });
        });
        it("Annotate over local insertion", () => {
            (0, testUtils_1.insertText)({
                mergeTree,
                pos: 4,
                refSeq: currentSequenceNumber,
                clientId: localClientId,
                seq: constants_1.UnassignedSequenceNumber,
                text: "a",
                props: undefined,
                opArgs: undefined,
            });
            const count = (0, testUtils_1.countOperations)(mergeTree);
            mergeTree.annotateRange(3, 8, {
                foo: "bar",
            }, currentSequenceNumber, localClientId, constants_1.UnassignedSequenceNumber, undefined);
            assert_1.strict.deepStrictEqual(count, {
                [ops_1.MergeTreeDeltaType.ANNOTATE]: 1,
                [mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.SPLIT]: 2,
            });
        });
        it("Annotate over remote insertion", () => {
            const remoteClientId = 35;
            let remoteSequenceNumber = currentSequenceNumber;
            (0, testUtils_1.insertText)({
                mergeTree,
                pos: 4,
                refSeq: remoteSequenceNumber,
                clientId: remoteClientId,
                seq: ++remoteSequenceNumber,
                text: "a",
                props: undefined,
                opArgs: undefined,
            });
            const count = (0, testUtils_1.countOperations)(mergeTree);
            mergeTree.annotateRange(3, 8, {
                foo: "bar",
            }, currentSequenceNumber, localClientId, constants_1.UnassignedSequenceNumber, undefined);
            assert_1.strict.deepStrictEqual(count, {
                [ops_1.MergeTreeDeltaType.ANNOTATE]: 1,
                [mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.SPLIT]: 2,
            });
        });
        it("Annotate over remote deletion", () => {
            const remoteClientId = 35;
            let remoteSequenceNumber = currentSequenceNumber;
            (0, testUtils_1.markRangeRemoved)({
                mergeTree,
                start: 4,
                end: 6,
                refSeq: remoteSequenceNumber,
                clientId: remoteClientId,
                seq: ++remoteSequenceNumber,
                overwrite: false,
                opArgs: undefined,
            });
            const count = (0, testUtils_1.countOperations)(mergeTree);
            mergeTree.annotateRange(3, 8, {
                foo: "bar",
            }, currentSequenceNumber, localClientId, constants_1.UnassignedSequenceNumber, undefined);
            assert_1.strict.deepStrictEqual(count, {
                [ops_1.MergeTreeDeltaType.ANNOTATE]: 1,
                [mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.SPLIT]: 2,
            });
        });
        it("Remote annotate within local deletion", () => {
            const remoteClientId = 35;
            let remoteSequenceNumber = currentSequenceNumber;
            (0, testUtils_1.markRangeRemoved)({
                mergeTree,
                start: 3,
                end: 8,
                refSeq: currentSequenceNumber,
                clientId: localClientId,
                seq: constants_1.UnassignedSequenceNumber,
                overwrite: false,
                opArgs: undefined,
            });
            const count = (0, testUtils_1.countOperations)(mergeTree);
            mergeTree.annotateRange(4, 6, {
                foo: "bar",
            }, remoteSequenceNumber, remoteClientId, ++remoteSequenceNumber, undefined);
            assert_1.strict.deepStrictEqual(count, {
                [ops_1.MergeTreeDeltaType.ANNOTATE]: 1,
                [mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.SPLIT]: 2,
            });
        });
    });
});
//# sourceMappingURL=mergeTree.annotate.deltaCallback.spec.cjs.map