"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = require("assert");
const textSegment_1 = require("../textSegment.cjs");
const testClient_1 = require("./testClient.cjs");
describe("client.getPosition", () => {
    const localUserLongId = "localUser";
    let client;
    let segment;
    const segPos = 4;
    beforeEach(() => {
        client = new testClient_1.TestClient();
        for (const c of "hello world") {
            client.insertTextLocal(client.getLength(), c);
        }
        client.startOrUpdateCollaboration(localUserLongId);
        const segOff = client.getContainingSegment(segPos);
        (0, assert_1.strict)(textSegment_1.TextSegment.is(segOff.segment));
        assert_1.strict.strictEqual(segOff.offset, 0);
        assert_1.strict.strictEqual(segOff.segment.text, "o");
        segment = segOff.segment;
    });
    it("Existing Segment", () => {
        const pos = client.getPosition(segment);
        assert_1.strict.strictEqual(pos, segPos);
    });
    it("Deleted Segment", () => {
        client.removeRangeLocal(segPos, segPos + 1);
        assert_1.strict.notStrictEqual(segment.removedSeq, undefined);
        const pos = client.getPosition(segment);
        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()));
        }
        assert_1.strict.notStrictEqual(segment.removedSeq, undefined);
        const pos = client.getPosition(segment);
        assert_1.strict.strictEqual(pos, -1);
    });
    it("Moved Segment", () => {
        client.removeRangeLocal(segPos - 1, segPos);
        const pos = client.getPosition(segment);
        assert_1.strict.strictEqual(pos, segPos - 1);
    });
});
//# sourceMappingURL=client.getPosition.spec.cjs.map