mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 09:06:25 +00:00
0c06a23a3f
Co-authored-by: proton <25139420+proton-ab@users.noreply.github.com>
210 lines
5.8 KiB
TypeScript
210 lines
5.8 KiB
TypeScript
import { api as hexScheme } from '.';
|
|
|
|
describe('lib/versioning/hex', () => {
|
|
describe('hexScheme.matches()', () => {
|
|
it('handles tilde greater than', () => {
|
|
expect(hexScheme.matches('4.2.0', '~> 4.0')).toBe(true);
|
|
expect(hexScheme.matches('2.1.0', '~> 2.0.0')).toBe(false);
|
|
expect(hexScheme.matches('2.0.0', '>= 2.0.0 and < 2.1.0')).toBe(true);
|
|
expect(hexScheme.matches('2.1.0', '== 2.0.0 or < 2.1.0')).toBe(false);
|
|
expect(hexScheme.matches('1.9.4', '== 1.9.4')).toBe(true);
|
|
expect(hexScheme.matches('1.9.5', '== 1.9.4')).toBe(false);
|
|
});
|
|
});
|
|
it('handles tilde greater than', () => {
|
|
expect(
|
|
hexScheme.maxSatisfyingVersion(
|
|
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
|
|
'~> 4.0'
|
|
)
|
|
).toBe('4.2.0');
|
|
expect(
|
|
hexScheme.maxSatisfyingVersion(
|
|
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
|
|
'~> 4.0.0'
|
|
)
|
|
).toBe('4.0.0');
|
|
});
|
|
describe('hexScheme.isValid()', () => {
|
|
it('handles and', () => {
|
|
expect(hexScheme.isValid('>= 1.0.0 and <= 2.0.0')).toBeTruthy();
|
|
});
|
|
it('handles or', () => {
|
|
expect(hexScheme.isValid('>= 1.0.0 or <= 2.0.0')).toBeTruthy();
|
|
});
|
|
it('handles !=', () => {
|
|
expect(hexScheme.isValid('!= 1.0.0')).toBeTruthy();
|
|
});
|
|
it('handles ==', () => {
|
|
expect(hexScheme.isValid('== 1.0.0')).toBeTruthy();
|
|
});
|
|
});
|
|
describe('hexScheme.isLessThanRange()', () => {
|
|
it('handles and', () => {
|
|
expect(hexScheme.isLessThanRange('0.1.0', '>= 1.0.0 and <= 2.0.0')).toBe(
|
|
true
|
|
);
|
|
expect(hexScheme.isLessThanRange('1.9.0', '>= 1.0.0 and <= 2.0.0')).toBe(
|
|
false
|
|
);
|
|
});
|
|
it('handles or', () => {
|
|
expect(hexScheme.isLessThanRange('0.9.0', '>= 1.0.0 or >= 2.0.0')).toBe(
|
|
true
|
|
);
|
|
expect(hexScheme.isLessThanRange('1.9.0', '>= 1.0.0 or >= 2.0.0')).toBe(
|
|
false
|
|
);
|
|
});
|
|
});
|
|
describe('hexScheme.minSatisfyingVersion()', () => {
|
|
it('handles tilde greater than', () => {
|
|
expect(
|
|
hexScheme.minSatisfyingVersion(
|
|
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
|
|
'~> 4.0'
|
|
)
|
|
).toBe('4.2.0');
|
|
expect(
|
|
hexScheme.minSatisfyingVersion(
|
|
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
|
|
'~> 4.0.0'
|
|
)
|
|
).toBeNull();
|
|
});
|
|
});
|
|
describe('hexScheme.getNewValue()', () => {
|
|
it('handles exact pin', () => {
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '== 1.2.3',
|
|
rangeStrategy: 'pin',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('== 2.0.7');
|
|
});
|
|
it('handles exact bump', () => {
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '== 3.6.1',
|
|
rangeStrategy: 'bump',
|
|
fromVersion: '3.6.1',
|
|
toVersion: '3.6.2',
|
|
})
|
|
).toEqual('== 3.6.2');
|
|
});
|
|
it('handles exact replace', () => {
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '== 3.6.1',
|
|
rangeStrategy: 'replace',
|
|
fromVersion: '3.6.1',
|
|
toVersion: '3.6.2',
|
|
})
|
|
).toEqual('== 3.6.2');
|
|
});
|
|
it('handles tilde greater than', () => {
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '~> 1.2',
|
|
rangeStrategy: 'replace',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('~> 2.0');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '~> 1.2',
|
|
rangeStrategy: 'pin',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('== 2.0.7');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '~> 1.2',
|
|
rangeStrategy: 'bump',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('~> 2');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '~> 1.2.0',
|
|
rangeStrategy: 'replace',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('~> 2.0.0');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '~> 1.2.0',
|
|
rangeStrategy: 'pin',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('== 2.0.7');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '~> 1.2.0',
|
|
rangeStrategy: 'bump',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('~> 2.0.7');
|
|
});
|
|
});
|
|
it('handles and', () => {
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '>= 1.0.0 and <= 2.0.0',
|
|
rangeStrategy: 'widen',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('>= 1.0.0 and <= 2.0.7');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '>= 1.0.0 and <= 2.0.0',
|
|
rangeStrategy: 'replace',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('<= 2.0.7');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '>= 1.0.0 and <= 2.0.0',
|
|
rangeStrategy: 'pin',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('== 2.0.7');
|
|
});
|
|
it('handles or', () => {
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '>= 1.0.0 or <= 2.0.0',
|
|
rangeStrategy: 'widen',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('>= 1.0.0 or <= 2.0.7');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '>= 1.0.0 or <= 2.0.0',
|
|
rangeStrategy: 'replace',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('<= 2.0.7');
|
|
expect(
|
|
hexScheme.getNewValue({
|
|
currentValue: '>= 1.0.0 or <= 2.0.0',
|
|
rangeStrategy: 'pin',
|
|
fromVersion: '1.2.3',
|
|
toVersion: '2.0.7',
|
|
})
|
|
).toEqual('== 2.0.7');
|
|
});
|
|
});
|