fix(ruby): match precision for new ranges (#5035)

This commit is contained in:
Rhys Arkins 2019-12-21 10:59:07 +01:00 committed by GitHub
parent 7e9db42ce0
commit 118a3452e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -9,7 +9,15 @@ export default ({ to, range }: { range: string; to: string }): string => {
.split(',') .split(',')
.map(part => part.trim()) .map(part => part.trim())
.pop(); .pop();
const newLastPart = bump({ to, range: lastPart }); const lastPartPrecision = lastPart.split('.').length;
// TODO: match precision const toPrecision = to.split('.').length;
let massagedTo: string = to;
if (!lastPart.startsWith('<') && toPrecision > lastPartPrecision) {
massagedTo = to
.split('.')
.slice(0, lastPartPrecision)
.join('.');
}
const newLastPart = bump({ to: massagedTo, range: lastPart });
return range.replace(lastPart, newLastPart); return range.replace(lastPart, newLastPart);
}; };

View file

@ -423,12 +423,13 @@ describe('semverRuby', () => {
['~> 1.0.3', '~> 1.0.3', 'replace', '1.0.0', '1.0.4'], ['~> 1.0.3', '~> 1.0.3', 'replace', '1.0.0', '1.0.4'],
['~> 4.7, >= 4.7.4', '~> 4.7, >= 4.7.4', 'replace', '1.0.0', '4.7.9'], ['~> 4.7, >= 4.7.4', '~> 4.7, >= 4.7.4', 'replace', '1.0.0', '4.7.9'],
[ [
'>= 2.0.0, <= 2.20.0', '>= 2.0.0, <= 2.20.1',
'>= 2.0.0, <= 2.15', '>= 2.0.0, <= 2.15',
'replace', 'replace',
'2.15.0', '2.15.0',
'2.20.0', '2.20.1',
], ],
['~> 6.0.0', '~> 5.2.0', 'replace', '5.2.4.1', '6.0.2.1'],
].forEach(([expected, current, range, from, to]) => { ].forEach(([expected, current, range, from, to]) => {
expect(semverRuby.getNewValue(current, range as any, from, to)).toEqual( expect(semverRuby.getNewValue(current, range as any, from, to)).toEqual(
expected expected