renovate/lib/versioning/hex/index.spec.ts

211 lines
5.8 KiB
TypeScript
Raw Normal View History

2020-03-05 20:57:24 +00:00
import { api as hexScheme } from '.';
2019-03-19 09:11:50 +00:00
describe('lib/versioning/hex', () => {
2019-10-04 07:13:14 +00:00
describe('hexScheme.matches()', () => {
2019-03-19 09:11:50 +00:00
it('handles tilde greater than', () => {
2019-10-04 07:13:14 +00:00
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);
2019-03-19 09:11:50 +00:00
});
});
it('handles tilde greater than', () => {
expect(
2019-10-04 07:13:14 +00:00
hexScheme.maxSatisfyingVersion(
2019-03-19 09:11:50 +00:00
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
'~> 4.0'
)
).toBe('4.2.0');
expect(
2019-10-04 07:13:14 +00:00
hexScheme.maxSatisfyingVersion(
2019-03-19 09:11:50 +00:00
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
'~> 4.0.0'
)
).toBe('4.0.0');
});
2019-10-04 07:13:14 +00:00
describe('hexScheme.isValid()', () => {
2019-03-19 09:11:50 +00:00
it('handles and', () => {
2019-10-04 07:13:14 +00:00
expect(hexScheme.isValid('>= 1.0.0 and <= 2.0.0')).toBeTruthy();
2019-03-19 09:11:50 +00:00
});
it('handles or', () => {
2019-10-04 07:13:14 +00:00
expect(hexScheme.isValid('>= 1.0.0 or <= 2.0.0')).toBeTruthy();
2019-03-19 09:11:50 +00:00
});
it('handles !=', () => {
2019-10-04 07:13:14 +00:00
expect(hexScheme.isValid('!= 1.0.0')).toBeTruthy();
2019-03-19 09:11:50 +00:00
});
it('handles ==', () => {
expect(hexScheme.isValid('== 1.0.0')).toBeTruthy();
});
2019-03-19 09:11:50 +00:00
});
2019-10-04 07:13:14 +00:00
describe('hexScheme.isLessThanRange()', () => {
2019-03-19 09:11:50 +00:00
it('handles and', () => {
2019-10-04 07:13:14 +00:00
expect(hexScheme.isLessThanRange('0.1.0', '>= 1.0.0 and <= 2.0.0')).toBe(
2019-03-19 09:11:50 +00:00
true
);
2019-10-04 07:13:14 +00:00
expect(hexScheme.isLessThanRange('1.9.0', '>= 1.0.0 and <= 2.0.0')).toBe(
2019-03-19 09:11:50 +00:00
false
);
});
it('handles or', () => {
2019-10-04 07:13:14 +00:00
expect(hexScheme.isLessThanRange('0.9.0', '>= 1.0.0 or >= 2.0.0')).toBe(
2019-03-19 09:11:50 +00:00
true
);
2019-10-04 07:13:14 +00:00
expect(hexScheme.isLessThanRange('1.9.0', '>= 1.0.0 or >= 2.0.0')).toBe(
2019-03-19 09:11:50 +00:00
false
);
});
});
2019-10-04 07:13:14 +00:00
describe('hexScheme.minSatisfyingVersion()', () => {
2019-03-19 09:11:50 +00:00
it('handles tilde greater than', () => {
expect(
2019-10-04 07:13:14 +00:00
hexScheme.minSatisfyingVersion(
2019-03-19 09:11:50 +00:00
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
'~> 4.0'
)
).toBe('4.2.0');
expect(
2019-10-04 07:13:14 +00:00
hexScheme.minSatisfyingVersion(
2019-03-19 09:11:50 +00:00
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
'~> 4.0.0'
)
).toBeNull();
2019-03-19 09:11:50 +00:00
});
});
2019-10-04 07:13:14 +00:00
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');
});
2019-03-19 09:11:50 +00:00
it('handles tilde greater than', () => {
2019-10-04 07:13:14 +00:00
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2',
rangeStrategy: 'replace',
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
2019-10-04 07:13:14 +00:00
).toEqual('~> 2.0');
2019-03-19 09:11:50 +00:00
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',
})
2019-03-19 09:11:50 +00:00
).toEqual('~> 2.0.0');
2019-10-04 07:13:14 +00:00
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2.0',
rangeStrategy: 'pin',
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
).toEqual('== 2.0.7');
2019-10-04 07:13:14 +00:00
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2.0',
rangeStrategy: 'bump',
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
2019-10-04 07:13:14 +00:00
).toEqual('~> 2.0.7');
2019-03-19 09:11:50 +00:00
});
});
it('handles and', () => {
expect(
hexScheme.getNewValue({
currentValue: '>= 1.0.0 and <= 2.0.0',
rangeStrategy: 'widen',
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
2019-03-19 09:11:50 +00:00
).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',
})
2019-03-19 09:11:50 +00:00
).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');
2019-03-19 09:11:50 +00:00
});
it('handles or', () => {
expect(
hexScheme.getNewValue({
currentValue: '>= 1.0.0 or <= 2.0.0',
rangeStrategy: 'widen',
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
2019-03-19 09:11:50 +00:00
).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',
})
2019-03-19 09:11:50 +00:00
).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');
2019-03-19 09:11:50 +00:00
});
});