fix(ruby): isValid for complex ranges

This commit is contained in:
Rhys Arkins 2019-01-13 10:00:31 +01:00
parent c02323ca5a
commit ac63a5097c
2 changed files with 14 additions and 6 deletions

View file

@ -32,13 +32,17 @@ const isSingleVersion = range => {
const isStable = version => const isStable = version =>
parseVersion(version).prerelease ? false : isVersion(version); parseVersion(version).prerelease ? false : isVersion(version);
const isValid = range => { const isValid = input =>
const { version, operator } = parseRange(range); input
.split(',')
.map(piece => piece.trim())
.every(range => {
const { version, operator } = parseRange(range);
return operator return operator
? isVersion(version) && isValidOperator(operator) ? isVersion(version) && isValidOperator(operator)
: isVersion(version); : isVersion(version);
}; });
const matches = (version, range) => satisfies(version, range); const matches = (version, range) => satisfies(version, range);
const maxSatisfyingVersion = (versions, range) => const maxSatisfyingVersion = (versions, range) =>

View file

@ -297,6 +297,10 @@ describe('semverRuby', () => {
expect(semverRuby.isValid('~> 1.2.0-alpha.1')).toBeTruthy(); expect(semverRuby.isValid('~> 1.2.0-alpha.1')).toBeTruthy();
}); });
it('returns true when range is valid', () => {
expect(semverRuby.isValid('>= 3.0.5, < 3.2')).toBeTruthy();
});
it('returns false when version is invalid', () => { it('returns false when version is invalid', () => {
expect(semverRuby.isVersion()).toBeFalsy(); expect(semverRuby.isVersion()).toBeFalsy();
expect(semverRuby.isVersion('')).toBeFalsy(); expect(semverRuby.isVersion('')).toBeFalsy();