"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const node_assert_1 = require("node:assert");
const mergeTreeNodes_js_1 = require("../mergeTreeNodes.js");
const textSegment_js_1 = require("../textSegment.js");
const testClient_js_1 = require("./testClient.js");
describe("client.getPosition", () => {
    const localUserLongId = "localUser";
    let client;
    let segment;
    const segPos = 4;
    beforeEach(() => {
        client = new testClient_js_1.TestClient();
        for (const c of "hello world") {
            client.insertTextLocal(client.getLength(), c);
        }
        client.startOrUpdateCollaboration(localUserLongId);
        const segOff = client.getContainingSegment(segPos);
        (0, node_assert_1.strict)(textSegment_js_1.TextSegment.is(segOff.segment));
        node_assert_1.strict.strictEqual(segOff.offset, 0);
        node_assert_1.strict.strictEqual(segOff.segment.text, "o");
        segment = segOff.segment;
    });
    it("Existing Segment", () => {
        const pos = client.getPosition(segment);
        node_assert_1.strict.strictEqual(pos, segPos);
    });
    it("Deleted Segment", () => {
        client.removeRangeLocal(segPos, segPos + 1);
        node_assert_1.strict.strictEqual((0, mergeTreeNodes_js_1.segmentIsRemoved)(segment), true);
        const pos = client.getPosition(segment);
        node_assert_1.strict.strictEqual(pos, segPos);
    });
    it("Detached Segment", () => {
        client.applyMsg(client.makeOpMessage(client.removeRangeLocal(segPos, segPos + 1), 1));
        // do some work and move the client's min seq forward, so zamboni runs
        for (const c of "hello world") {
            client.applyMsg(client.makeOpMessage(client.insertTextLocal(client.getLength(), c), client.getCurrentSeq() + 1, client.getCurrentSeq(), undefined, client.getCurrentSeq()));
        }
        node_assert_1.strict.strictEqual((0, mergeTreeNodes_js_1.segmentIsRemoved)(segment), true);
        const pos = client.getPosition(segment);
        node_assert_1.strict.strictEqual(pos, -1);
    });
    it("Removed Segment", () => {
        client.removeRangeLocal(segPos - 1, segPos);
        const pos = client.getPosition(segment);
        node_assert_1.strict.strictEqual(pos, segPos - 1);
    });
});
//# sourceMappingURL=client.getPosition.spec.js.map