fix(versioning/loose): Fix suffix comparison (#13745)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
Sergei Zharinov 2022-01-24 17:24:17 +03:00 committed by GitHub
parent a9920ff8ec
commit d4bbfe2474
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View file

@ -37,6 +37,17 @@ describe('versioning/loose/index', () => {
expect(!!loose.isValid(version)).toBe(expected); expect(!!loose.isValid(version)).toBe(expected);
}); });
test.each`
a | b | expected
${'2.4'} | ${'2.4'} | ${true}
${'2.4.0'} | ${'2.4.0'} | ${true}
${'2.4.0'} | ${'2.4'} | ${false}
${'2.4.1'} | ${'2.4'} | ${false}
${'2.4.2'} | ${'2.4.1'} | ${false}
`('equals("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(loose.equals(a, b)).toBe(expected);
});
test.each` test.each`
a | b | expected a | b | expected
${'2.4.0'} | ${'2.4'} | ${true} ${'2.4.0'} | ${'2.4'} | ${true}
@ -44,6 +55,10 @@ describe('versioning/loose/index', () => {
${'2.4.beta'} | ${'2.4.alpha'} | ${true} ${'2.4.beta'} | ${'2.4.alpha'} | ${true}
${'1.9'} | ${'2'} | ${false} ${'1.9'} | ${'2'} | ${false}
${'1.9'} | ${'1.9.1'} | ${false} ${'1.9'} | ${'1.9.1'} | ${false}
${'2.4'} | ${'2.4.beta'} | ${true}
${'2.4.0'} | ${'2.4.beta'} | ${true}
${'2.4.beta'} | ${'2.4'} | ${false}
${'2.4.beta'} | ${'2.4.0'} | ${false}
`('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => { `('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(loose.isGreaterThan(a, b)).toBe(expected); expect(loose.isGreaterThan(a, b)).toBe(expected);
}); });

View file

@ -50,12 +50,21 @@ class LooseVersioningApi extends GenericVersioningApi {
return part1 - part2; return part1 - part2;
} }
} }
// istanbul ignore if
if (!(parsed1.suffix && parsed2.suffix)) { if (parsed1.suffix && parsed2.suffix) {
return parsed1.suffix.localeCompare(parsed2.suffix);
}
if (parsed1.suffix) {
return -1;
}
if (parsed2.suffix) {
return 1; return 1;
} }
// equals
return parsed1.suffix.localeCompare(parsed2.suffix); // istanbul ignore next
return 0;
} }
} }