// SPDX-License-Identifier: Apache-2.0
import { expect } from 'chai';
import { VersionRange } from '../../../../src/business/utils/version-range.js';
import { SemanticVersion } from '../../../../src/business/utils/semantic-version.js';
describe('VersionRange', () => {
    describe('constructor', () => {
        it('should create a valid VersionRange with numeric bounds', () => {
            const range = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            expect(range.begin.major).to.equal(1);
            expect(range.end.major).to.equal(5);
        });
        it('should create a valid VersionRange with SemanticVersion<string> bounds', () => {
            const begin = new SemanticVersion('1.0.0');
            const end = new SemanticVersion('2.0.0');
            const range = new VersionRange(begin, end);
            expect(range.begin.major).to.equal(begin.major);
            expect(range.end.major).to.equal(end.major);
        });
        it('should throw a RangeError if begin is greater than or equal to end', () => {
            expect(() => new VersionRange(new SemanticVersion(5), new SemanticVersion(1))).to.throw(RangeError, 'Invalid version range');
            expect(() => new VersionRange(new SemanticVersion(5), new SemanticVersion(5))).to.throw(RangeError, 'Invalid version range');
        });
    });
    describe('fromIntegerBounds', () => {
        it('should create a VersionRange from integer bounds', () => {
            const range = VersionRange.fromIntegerBounds(1, 5);
            expect(range.begin.major).to.equal(1);
            expect(range.end.major).to.equal(5);
        });
        it('should throw a RangeError for invalid bounds', () => {
            expect(() => VersionRange.fromIntegerBounds(5, 1)).to.throw(RangeError, 'Invalid version range');
        });
    });
    describe('fromIntegerVersion', () => {
        it('should create a VersionRange for a single integer version', () => {
            const range = VersionRange.fromIntegerVersion(3);
            expect(range.begin.major).to.equal(3);
            expect(range.end.major).to.equal(4);
        });
    });
    describe('fromSemanticVersion<string>Bounds', () => {
        it('should create a VersionRange from SemanticVersion<string> bounds', () => {
            const begin = new SemanticVersion('1.0.0');
            const end = new SemanticVersion('2.0.0');
            const range = VersionRange.fromSemanticVersionBounds(begin, end);
            expect(range.begin.toString()).to.equal(begin.toString());
            expect(range.end.toString()).to.equal(end.toString());
        });
        it('should throw a RangeError for invalid SemanticVersion<string> bounds', () => {
            const begin = new SemanticVersion('2.0.0');
            const end = new SemanticVersion('1.0.0');
            expect(() => VersionRange.fromSemanticVersionBounds(begin, end)).to.throw(RangeError, 'Invalid version range');
        });
    });
    describe('patchVersionBounds', () => {
        it('should create a VersionRange for all patch releases of a SemanticVersion<string>', () => {
            const version = new SemanticVersion('1.0.0');
            const range = VersionRange.patchVersionBounds(version);
            expect(range.begin.toString()).to.equal(version.toString());
            expect(range.end.toString()).to.equal('1.1.0');
        });
    });
    describe('minorVersionBounds', () => {
        it('should create a VersionRange for all minor and patch releases of a SemanticVersion<string>', () => {
            const version = new SemanticVersion('1.0.0');
            const range = VersionRange.minorVersionBounds(version);
            expect(range.begin.toString()).to.equal(version.toString());
            expect(range.end.toString()).to.equal('2.0.0');
        });
    });
    describe('equals', () => {
        it('should return true for equal VersionRanges', () => {
            const range1 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            const range2 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            expect(range1.equals(range2)).to.be.true;
        });
        it('should return false for different VersionRanges', () => {
            const range1 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            const range2 = new VersionRange(new SemanticVersion(2), new SemanticVersion(6));
            expect(range1.equals(range2)).to.be.false;
        });
    });
    describe('compare', () => {
        it('should return 0 for equal VersionRanges', () => {
            const range1 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            const range2 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            expect(range1.compare(range2)).to.equal(0);
        });
        it('should return -1 when the first range is less than the second', () => {
            const range1 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            const range2 = new VersionRange(new SemanticVersion(2), new SemanticVersion(6));
            expect(range1.compare(range2)).to.equal(-1);
        });
        it('should return 1 when the first range is greater than the second', () => {
            const range1 = new VersionRange(new SemanticVersion(2), new SemanticVersion(6));
            const range2 = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            expect(range1.compare(range2)).to.equal(1);
        });
    });
    describe('contains', () => {
        it('should return true if a version is within the range', () => {
            const range = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            const version = new SemanticVersion(3);
            expect(range.contains(version)).to.be.true;
        });
        it('should return false if a version is outside the range', () => {
            const range = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            const version = new SemanticVersion(6);
            expect(range.contains(version)).to.be.false;
        });
    });
    describe('toString', () => {
        it('should return the string representation of the range', () => {
            const range = new VersionRange(new SemanticVersion(1), new SemanticVersion(5));
            expect(range.toString()).to.equal('[1, 5)');
        });
    });
});
//# sourceMappingURL=version-range.test.js.map