Skip to content

Commit

Permalink
fix(hex): better handling of double equals (#6586)
Browse files Browse the repository at this point in the history
Co-authored-by: proton <25139420+proton-ab@users.noreply.github.com>
  • Loading branch information
rarkins and proton-ab committed Jun 25, 2020
1 parent b58b90d commit 0c06a23
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
43 changes: 39 additions & 4 deletions lib/versioning/hex/index.spec.ts
Expand Up @@ -7,6 +7,8 @@ describe('lib/versioning/hex', () => {
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);
});
});
it('handles tilde greater than', () => {
Expand All @@ -33,6 +35,9 @@ describe('lib/versioning/hex', () => {
it('handles !=', () => {
expect(hexScheme.isValid('!= 1.0.0')).toBeTruthy();
});
it('handles ==', () => {
expect(hexScheme.isValid('== 1.0.0')).toBeTruthy();
});
});
describe('hexScheme.isLessThanRange()', () => {
it('handles and', () => {
Expand Down Expand Up @@ -69,6 +74,36 @@ describe('lib/versioning/hex', () => {
});
});
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');
});
it('handles tilde greater than', () => {
expect(
hexScheme.getNewValue({
Expand All @@ -85,7 +120,7 @@ describe('lib/versioning/hex', () => {
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
).toEqual('2.0.7');
).toEqual('== 2.0.7');
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2',
Expand All @@ -109,7 +144,7 @@ describe('lib/versioning/hex', () => {
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
).toEqual('2.0.7');
).toEqual('== 2.0.7');
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2.0',
Expand Down Expand Up @@ -144,7 +179,7 @@ describe('lib/versioning/hex', () => {
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
).toEqual('2.0.7');
).toEqual('== 2.0.7');
});
it('handles or', () => {
expect(
Expand All @@ -170,6 +205,6 @@ describe('lib/versioning/hex', () => {
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
).toEqual('2.0.7');
).toEqual('== 2.0.7');
});
});
7 changes: 5 additions & 2 deletions lib/versioning/hex/index.ts
Expand Up @@ -13,7 +13,8 @@ function hex2npm(input: string): string {
.replace(/~>\s*(\d+\.\d+\.\d+)/, '~$1')
.replace(/==|and/, '')
.replace('or', '||')
.replace(/!=\s*(\d+\.\d+(\.\d+.*)?)/, '>$1 <$1');
.replace(/!=\s*(\d+\.\d+(\.\d+.*)?)/, '>$1 <$1')
.trim();
}

function npm2hex(input: string): string {
Expand Down Expand Up @@ -76,7 +77,9 @@ const getNewValue = ({
} else {
newSemver = newSemver.replace(/~\s*(\d+\.\d+\.\d)/, '~> $1');
}

if (npm.isVersion(newSemver)) {
newSemver = `== ${newSemver}`;
}
return newSemver;
};

Expand Down

0 comments on commit 0c06a23

Please sign in to comment.