Skip to content

Commit

Permalink
test: Maven versioning tests (#11826)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Sep 27, 2021
1 parent 3ca6855 commit f25a05f
Show file tree
Hide file tree
Showing 3 changed files with 372 additions and 427 deletions.
2 changes: 1 addition & 1 deletion lib/versioning/gradle/index.spec.ts
Expand Up @@ -231,7 +231,7 @@ describe('versioning/gradle/index', () => {
a | b | expected
${'1.1'} | ${'1'} | ${true}
`('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(api.isGreaterThan('1.1', '1')).toBe(true);
expect(api.isGreaterThan(a, b)).toBe(expected);
});

test.each`
Expand Down
210 changes: 210 additions & 0 deletions lib/versioning/maven/compare.spec.ts
@@ -0,0 +1,210 @@
import {
autoExtendMavenRange,
compare,
parseRange,
rangeToStr,
} from './compare';

describe('versioning/maven/compare', () => {
test.each`
a | b | expected
${'1.0.0'} | ${'1'} | ${0}
${'1-a1'} | ${'1-alpha-1'} | ${0}
${'1-b1'} | ${'1-beta-1'} | ${0}
${'1.0.0'} | ${'1.ga'} | ${0}
${'1-ga'} | ${'1.ga'} | ${0}
${'1-ga-1'} | ${'1-1'} | ${0}
${'1.final'} | ${'1.0'} | ${0}
${'1'} | ${'1.0'} | ${0}
${'1.'} | ${'1-'} | ${0}
${'1.0.0-0.0.0'} | ${'1-final'} | ${0}
${'1-1.foo-bar1baz-.1'} | ${'1-1.foo-bar-1-baz-0.1'} | ${0}
${'1.0ALPHA1'} | ${'1.0-a1'} | ${0}
${'1.0Alpha1'} | ${'1.0-a1'} | ${0}
${'1.0AlphA1'} | ${'1.0-a1'} | ${0}
${'1.0BETA1'} | ${'1.0-b1'} | ${0}
${'1.0MILESTONE1'} | ${'1.0-m1'} | ${0}
${'1.0RC1'} | ${'1.0-cr1'} | ${0}
${'1.0GA'} | ${'1.0'} | ${0}
${'1.0FINAL'} | ${'1.0'} | ${0}
${'1.0-SNAPSHOT'} | ${'1-snapshot'} | ${0}
${'1.0-SNAP'} | ${'1-snapshot'} | ${0}
${'1.0alpha1'} | ${'1.0-a1'} | ${0}
${'1.0alpha-1'} | ${'1.0-a1'} | ${0}
${'1.0beta1'} | ${'1.0-b1'} | ${0}
${'1.0beta-1'} | ${'1.0-b1'} | ${0}
${'1.0milestone1'} | ${'1.0-m1'} | ${0}
${'1.0milestone-1'} | ${'1.0-m1'} | ${0}
${'1.0rc1'} | ${'1.0-cr1'} | ${0}
${'1.0rc-1'} | ${'1.0-cr1'} | ${0}
${'1.0ga'} | ${'1.0'} | ${0}
${'1-0.ga'} | ${'1.0'} | ${0}
${'1.0-final'} | ${'1.0'} | ${0}
${'1-0-ga'} | ${'1.0'} | ${0}
${'1-0-final'} | ${'1-0'} | ${0}
${'1-0'} | ${'1.0'} | ${0}
${'v1.2.3'} | ${'1.2.3'} | ${0}
${'0.0-1552'} | ${'0.0-1552'} | ${0}
${'v0.0-1552'} | ${'0.0-1552'} | ${0}
${'v0.0.1'} | ${'0.0.1'} | ${0}
${'5.0.7'} | ${'5.0.7.RELEASE'} | ${0}
${'Hoxton.RELEASE'} | ${'hoxton'} | ${0}
${'Hoxton.SR1'} | ${'hoxton.sr-1'} | ${0}
${'1'} | ${'1.1'} | ${-1}
${'1'} | ${'2'} | ${-1}
${'1-snapshot'} | ${'1'} | ${-1}
${'1-snap'} | ${'1'} | ${-1}
${'1.2.3-snap1'} | ${'1.2.3-snap2'} | ${-1}
${'1'} | ${'1-sp'} | ${-1}
${'1-foo2'} | ${'1-foo10'} | ${-1}
${'1-m1'} | ${'1-milestone-2'} | ${-1}
${'1.foo'} | ${'1-foo'} | ${-1}
${'1-foo'} | ${'1-1'} | ${-1}
${'1-alpha.1'} | ${'1-beta.1'} | ${-1}
${'1-1'} | ${'1.1'} | ${-1}
${'1-ga'} | ${'1-ap'} | ${-1}
${'1-ga.1'} | ${'1-sp.1'} | ${-1}
${'1-sp-1'} | ${'1-ga-1'} | ${-1}
${'1-cr1'} | ${'1'} | ${-1}
${'0.0-1552'} | ${'1.10.520'} | ${-1}
${'0.0.1'} | ${'999'} | ${-1}
${'1.3-RC1-groovy-2.5'} | ${'1.3-groovy-2.5'} | ${-1}
${'1-abc'} | ${'1-xyz'} | ${-1}
${'Hoxton.RELEASE'} | ${'Hoxton.SR1'} | ${-1}
${'1.1'} | ${'1'} | ${1}
${'2'} | ${'1'} | ${1}
${'1'} | ${'1-snapshot'} | ${1}
${'1'} | ${'1-snap'} | ${1}
${'1.2.3-snap2'} | ${'1.2.3-snap1'} | ${1}
${'1-sp'} | ${'1'} | ${1}
${'1-foo10'} | ${'1-foo2'} | ${1}
${'1-milestone-2'} | ${'1-m1'} | ${1}
${'1-foo'} | ${'1.foo'} | ${1}
${'1-1'} | ${'1-foo'} | ${1}
${'1-beta.1'} | ${'1-alpha.1'} | ${1}
${'1.1'} | ${'1-1'} | ${1}
${'1-sp'} | ${'1-ga'} | ${1}
${'1-sp.1'} | ${'1-ga.1'} | ${1}
${'1-ga-1'} | ${'1-sp-1'} | ${1}
${'1'} | ${'1-cr1'} | ${1}
${'1.10.520'} | ${'0.0-1552'} | ${1}
${'999'} | ${'0.0.1'} | ${1}
${'1.3-groovy-2.5'} | ${'1.3-RC1-groovy-2.5'} | ${1}
${'1-xyz'} | ${'1-abc'} | ${1}
${'Hoxton.SR1'} | ${'Hoxton.RELEASE'} | ${1}
`('compare("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(compare(a, b)).toEqual(expected);
});

test.each`
input
${'1.2.3-SNAPSHOT'}
${'[]'}
${'[,]'}
${'('}
${'['}
${','}
${'[1.0'}
${'1.0]'}
${'[1.0],'}
${',[1.0]'}
${'(,1.1),(1.0,)'}
${'(0,1.1),(1.0,2.0)'}
${'(0,1.1),(,2.0)'}
${'(,1.0],,[1.2,)'}
${'(,1.0],[1.2,),'}
${'[1.5,]'}
${'[2.0,1.0)'}
${'[1.2,1.3],1.4'}
${'[1.2,,1.3]'}
${'[1.3,1.2]'}
${'[1,[2,3],4]'}
${'[,1.0]'}
`('filters out incorrect range: $input', ({ input }) => {
const range = parseRange(input);
expect(range).toBeNull();
expect(rangeToStr(range)).toBeNull();
});

test.each`
input | leftType | leftValue | leftBracket | rightType | rightValue | rightBracket
${'[1.0]'} | ${'INCLUDING_POINT'} | ${'1.0'} | ${'['} | ${'INCLUDING_POINT'} | ${'1.0'} | ${']'}
${'(,1.0]'} | ${'EXCLUDING_POINT'} | ${null} | ${'('} | ${'INCLUDING_POINT'} | ${'1.0'} | ${']'}
${'[1.2,1.3]'} | ${'INCLUDING_POINT'} | ${'1.2'} | ${'['} | ${'INCLUDING_POINT'} | ${'1.3'} | ${']'}
${'[1.0,2.0)'} | ${'INCLUDING_POINT'} | ${'1.0'} | ${'['} | ${'EXCLUDING_POINT'} | ${'2.0'} | ${')'}
${'[1.5,)'} | ${'INCLUDING_POINT'} | ${'1.5'} | ${'['} | ${'EXCLUDING_POINT'} | ${null} | ${')'}
`(
'parseRange("$input")',
({
input,
leftType,
leftValue,
leftBracket,
rightType,
rightValue,
rightBracket,
}) => {
const parseResult = [
{
leftType,
leftValue,
leftBracket,
rightType,
rightValue,
rightBracket,
},
];
expect(parseRange(input)).toEqual(parseResult);
expect(rangeToStr(parseResult as never)).toEqual(input);
}
);

test.each`
range | version | expected
${'[1.2.3]'} | ${'1.2.3'} | ${'[1.2.3]'}
${'[1.2.3]'} | ${'1.2.4'} | ${'[1.2.4]'}
${'[1.0.0,1.2.3]'} | ${'0.0.1'} | ${'[1.0.0,1.2.3]'}
${'[1.0.0,1.2.3]'} | ${'1.2.4'} | ${'[1.0.0,1.2.4]'}
${'[1.0.0,1.2.23]'} | ${'1.1.0'} | ${'[1.0.0,1.2.23]'}
${'(,1.0]'} | ${'2.0'} | ${'(,2.0]'}
${'],1.0]'} | ${'2.0'} | ${'],2.0]'}
${'(,1.0)'} | ${'2.0'} | ${'(,3.0)'}
${'],1.0['} | ${'2.0'} | ${'],3.0['}
${'[1.0,1.2.3],[1.3,1.5)'} | ${'1.2.4'} | ${'[1.0,1.2.4],[1.3,1.5)'}
${'[1.0,1.2.3],[1.3,1.5['} | ${'1.2.4'} | ${'[1.0,1.2.4],[1.3,1.5['}
${'[1.2.3,)'} | ${'1.2.4'} | ${'[1.2.4,)'}
${'[1.2.3,['} | ${'1.2.4'} | ${'[1.2.4,['}
${'[1.2.3,]'} | ${'1.2.4'} | ${'[1.2.3,]'}
${'[0.21,0.22)'} | ${'0.20.21'} | ${'[0.21,0.22)'}
${'[0.21,0.22)'} | ${'0.21.1'} | ${'[0.21,0.22)'}
${'[0.21,0.22.0)'} | ${'0.22.1'} | ${'[0.21,0.22.2)'}
${'[0.21,0.22)'} | ${'0.23'} | ${'[0.23,0.24)'}
${'[1.8,1.9)'} | ${'1.9.0.1'} | ${'[1.9,1.10)'}
${'[1.8a,1.9)'} | ${'1.9.0.1'} | ${'[1.8a,1.10)'}
${'[1.8,1.9.0)'} | ${'1.9.0.1'} | ${'[1.8,1.10.0)'}
${'[1.8,1.9.0.0)'} | ${'1.9.0.1'} | ${'[1.8,1.9.0.2)'}
${'[1.8,1.9.0.0)'} | ${'1.10.1'} | ${'[1.8,1.10.2.0)'}
${'[1.8,1.9)'} | ${'1.9.1'} | ${'[1.9,1.10)'}
${'[1.8,1.9)'} | ${'1.10.0'} | ${'[1.10,1.11)'}
${'[1.8,1.9)'} | ${'1.10.1'} | ${'[1.10,1.11)'}
${'(,1.0.0]'} | ${'2.0.0'} | ${'(,2.0.0]'}
${'(,1.0]'} | ${'2.0.0'} | ${'(,2.0]'}
${'(,1]'} | ${'2.0.0'} | ${'(,2]'}
${'(,1.0.0-foobar]'} | ${'2.0.0'} | ${'(,2.0.0]'}
${'[1,2]'} | ${'2'} | ${'[1,2]'}
${'[1,2)'} | ${'2'} | ${'[2,3)'}
${'[0,2)'} | ${'2'} | ${'[0,3)'}
${'[1.2,1.3]'} | ${'1.3'} | ${'[1.2,1.3]'}
${'[1.2,1.3)'} | ${'1.3'} | ${'[1.3,1.4)'}
${'[1.1,1.3)'} | ${'1.3'} | ${'[1.1,1.4)'}
${'[1.2.3,1.2.4]'} | ${'1.2.4'} | ${'[1.2.3,1.2.4]'}
${'[1.2.3,1.2.4)'} | ${'1.2.4'} | ${'[1.2.4,1.2.5)'}
${'[1.2.1,1.2.4)'} | ${'1.2.4'} | ${'[1.2.1,1.2.5)'}
${'[1,1.2.3)'} | ${'1.2.3'} | ${'[1,1.2.4)'}
`(
'autoExtendMavenRange("$range", "$version") === $expected',
({ range, version, expected }) => {
expect(autoExtendMavenRange(range, version)).toEqual(expected);
}
);
});

0 comments on commit f25a05f

Please sign in to comment.