"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 mergeTreeNodes_js_1 = require("../mergeTreeNodes.js");
const segmentGroupCollection_js_1 = require("../segmentGroupCollection.js");
const segmentInfos_js_1 = require("../segmentInfos.js");
const textSegment_js_1 = require("../textSegment.js");
describe("segmentGroupCollection", () => {
    let parent;
    let segment;
    let segmentGroups;
    beforeEach(() => {
        parent = new mergeTreeNodes_js_1.MergeBlock(1);
        const newSeg = (segment = (0, segmentInfos_js_1.overwriteInfo)(textSegment_js_1.TextSegment.make("abc"), {
            clientId: 0,
            seq: 1,
        }));
        (0, mergeTreeNodes_js_1.assignChild)(parent, newSeg, 0);
        segmentGroups = segment.segmentGroups = new segmentGroupCollection_js_1.SegmentGroupCollection(newSeg);
    });
    it(".empty", () => {
        (0, node_assert_1.strict)(segmentGroups.empty);
    });
    it(".size", () => {
        node_assert_1.strict.equal(segmentGroups.size, 0);
    });
    it(".enqueue", () => {
        const segmentGroup = { segments: [], localSeq: 1, refSeq: 0 };
        segmentGroups.enqueue(segmentGroup);
        (0, node_assert_1.strict)(!segmentGroups.empty);
        node_assert_1.strict.equal(segmentGroups.size, 1);
        node_assert_1.strict.equal(segmentGroup.segments.length, 1);
        node_assert_1.strict.equal(segmentGroup.segments[0], segment);
    });
    it(".dequeue", () => {
        const segmentGroup = { segments: [], localSeq: 1, refSeq: 0 };
        segmentGroups.enqueue(segmentGroup);
        const segmentGroupCount = 6;
        while (segmentGroups.size < segmentGroupCount) {
            segmentGroups.enqueue({ segments: [], localSeq: 1, refSeq: 0 });
        }
        const dequeuedSegmentGroup = segmentGroups.dequeue();
        node_assert_1.strict.equal(segmentGroups.size, segmentGroupCount - 1);
        node_assert_1.strict.equal(dequeuedSegmentGroup?.segments.length, 1);
        node_assert_1.strict.equal(dequeuedSegmentGroup.segments[0], segment);
        node_assert_1.strict.equal(dequeuedSegmentGroup, segmentGroup);
    });
    it(".copyTo", () => {
        const segmentGroupCount = 6;
        while (segmentGroups.size < segmentGroupCount) {
            segmentGroups.enqueue({ segments: [], localSeq: 1, refSeq: 0 });
        }
        const segmentCopy = (0, segmentInfos_js_1.overwriteInfo)(textSegment_js_1.TextSegment.make(""), {
            clientId: 0,
            seq: 1,
        });
        (0, mergeTreeNodes_js_1.assignChild)(parent, segmentCopy, parent.childCount++);
        const segmentGroupCopy = new segmentGroupCollection_js_1.SegmentGroupCollection(segmentCopy);
        segmentGroups.copyTo(segmentGroupCopy);
        node_assert_1.strict.equal(segmentGroups.size, segmentGroupCount);
        node_assert_1.strict.equal(segmentGroupCopy.size, segmentGroupCount);
        while (!segmentGroups.empty || !segmentGroupCopy.empty) {
            const segmentGroup = segmentGroups.dequeue();
            const copySegmentGroup = segmentGroupCopy.dequeue();
            node_assert_1.strict.equal(segmentGroup, copySegmentGroup);
            node_assert_1.strict.equal(segmentGroup?.segments.length, 2);
            node_assert_1.strict.equal(segmentGroup.segments[0], segment);
            node_assert_1.strict.equal(segmentGroup.segments[1], segmentCopy);
        }
    });
});
//# sourceMappingURL=segmentGroupCollection.spec.js.map