Skip to content

Commit

Permalink
fix(versioning/loose): Fix suffix comparison (#13745)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
zharinov and rarkins committed Jan 24, 2022
1 parent a9920ff commit d4bbfe2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
15 changes: 15 additions & 0 deletions lib/versioning/loose/index.spec.ts
Expand Up @@ -37,13 +37,28 @@ describe('versioning/loose/index', () => {
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`
a | b | expected
${'2.4.0'} | ${'2.4'} | ${true}
${'2.4.2'} | ${'2.4.1'} | ${true}
${'2.4.beta'} | ${'2.4.alpha'} | ${true}
${'1.9'} | ${'2'} | ${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 }) => {
expect(loose.isGreaterThan(a, b)).toBe(expected);
});
Expand Down
17 changes: 13 additions & 4 deletions lib/versioning/loose/index.ts
Expand Up @@ -50,12 +50,21 @@ class LooseVersioningApi extends GenericVersioningApi {
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;
}
// equals
return parsed1.suffix.localeCompare(parsed2.suffix);

// istanbul ignore next
return 0;
}
}

Expand Down

0 comments on commit d4bbfe2

Please sign in to comment.