From f25a05fa2c6a491b0aa67c885006422dc5906fa5 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Mon, 27 Sep 2021 12:00:20 +0300 Subject: [PATCH] test: Maven versioning tests (#11826) --- lib/versioning/gradle/index.spec.ts | 2 +- lib/versioning/maven/compare.spec.ts | 210 ++++++++++ lib/versioning/maven/index.spec.ts | 587 ++++++++------------------- 3 files changed, 372 insertions(+), 427 deletions(-) create mode 100644 lib/versioning/maven/compare.spec.ts diff --git a/lib/versioning/gradle/index.spec.ts b/lib/versioning/gradle/index.spec.ts index 6a409b26d2..d67f436dac 100644 --- a/lib/versioning/gradle/index.spec.ts +++ b/lib/versioning/gradle/index.spec.ts @@ -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` diff --git a/lib/versioning/maven/compare.spec.ts b/lib/versioning/maven/compare.spec.ts new file mode 100644 index 0000000000..2e27a8fe73 --- /dev/null +++ b/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); + } + ); +}); diff --git a/lib/versioning/maven/index.spec.ts b/lib/versioning/maven/index.spec.ts index 4f2e0a0be7..0304e5c5ce 100644 --- a/lib/versioning/maven/index.spec.ts +++ b/lib/versioning/maven/index.spec.ts @@ -1,442 +1,177 @@ -import { - autoExtendMavenRange, - compare, - parseRange, - rangeToStr, -} from './compare'; import maven, { isValid as _isValid } from '.'; -const { - isValid, - isVersion, - isStable, - getMajor, - getMinor, - getPatch, - matches, - getNewValue, -} = maven; +const { isValid, isVersion, isStable, getMajor, getMinor, getPatch, matches } = + maven; describe('versioning/maven/index', () => { - it('returns equality', () => { - expect(compare('1.0.0', '1')).toEqual(0); - expect(compare('1-a1', '1-alpha-1')).toEqual(0); - expect(compare('1-b1', '1-beta-1')).toEqual(0); - expect(compare('1.0.0', '1.ga')).toEqual(0); - expect(compare('1-ga', '1.ga')).toEqual(0); - expect(compare('1-ga-1', '1-1')).toEqual(0); - expect(compare('1.final', '1.0')).toEqual(0); - expect(compare('1', '1.0')).toEqual(0); - expect(compare('1.', '1-')).toEqual(0); - expect(compare('1.0.0-0.0.0', '1-final')).toEqual(0); - expect(compare('1-1.foo-bar1baz-.1', '1-1.foo-bar-1-baz-0.1')).toEqual(0); - expect(compare('1.0ALPHA1', '1.0-a1')).toEqual(0); - expect(compare('1.0Alpha1', '1.0-a1')).toEqual(0); - expect(compare('1.0AlphA1', '1.0-a1')).toEqual(0); - expect(compare('1.0BETA1', '1.0-b1')).toEqual(0); - expect(compare('1.0MILESTONE1', '1.0-m1')).toEqual(0); - expect(compare('1.0RC1', '1.0-cr1')).toEqual(0); - expect(compare('1.0GA', '1.0')).toEqual(0); - expect(compare('1.0FINAL', '1.0')).toEqual(0); - expect(compare('1.0-SNAPSHOT', '1-snapshot')).toEqual(0); - expect(compare('1.0-SNAP', '1-snapshot')).toEqual(0); - expect(compare('1.0alpha1', '1.0-a1')).toEqual(0); - expect(compare('1.0alpha-1', '1.0-a1')).toEqual(0); - expect(compare('1.0beta1', '1.0-b1')).toEqual(0); - expect(compare('1.0beta-1', '1.0-b1')).toEqual(0); - expect(compare('1.0milestone1', '1.0-m1')).toEqual(0); - expect(compare('1.0milestone-1', '1.0-m1')).toEqual(0); - expect(compare('1.0rc1', '1.0-cr1')).toEqual(0); - expect(compare('1.0rc-1', '1.0-cr1')).toEqual(0); - expect(compare('1.0ga', '1.0')).toEqual(0); - expect(compare('1-0.ga', '1.0')).toEqual(0); - expect(compare('1.0-final', '1.0')).toEqual(0); - expect(compare('1-0-ga', '1.0')).toEqual(0); - expect(compare('1-0-final', '1-0')).toEqual(0); - expect(compare('1-0', '1.0')).toEqual(0); - expect(compare('v1.2.3', '1.2.3')).toEqual(0); - expect(compare('0.0-1552', '0.0-1552')).toEqual(0); - expect(compare('v0.0-1552', '0.0-1552')).toEqual(0); - expect(compare('v0.0.1', '0.0.1')).toEqual(0); - expect(compare('5.0.7', '5.0.7.RELEASE')).toEqual(0); - expect(compare('Hoxton.RELEASE', 'hoxton')).toEqual(0); - expect(compare('Hoxton.SR1', 'hoxton.sr-1')).toEqual(0); - }); - it('returns less than', () => { - expect(compare('1', '1.1')).toEqual(-1); - expect(compare('1', '2')).toEqual(-1); - expect(compare('1-snapshot', '1')).toEqual(-1); - expect(compare('1-snap', '1')).toEqual(-1); - expect(compare('1.2.3-snap1', '1.2.3-snap2')).toEqual(-1); - expect(compare('1', '1-sp')).toEqual(-1); - expect(compare('1-foo2', '1-foo10')).toEqual(-1); - expect(compare('1-m1', '1-milestone-2')).toEqual(-1); - expect(compare('1.foo', '1-foo')).toEqual(-1); - expect(compare('1-foo', '1-1')).toEqual(-1); - expect(compare('1-alpha.1', '1-beta.1')).toEqual(-1); - expect(compare('1-1', '1.1')).toEqual(-1); - expect(compare('1-ga', '1-ap')).toEqual(-1); - expect(compare('1-ga.1', '1-sp.1')).toEqual(-1); - expect(compare('1-sp-1', '1-ga-1')).toEqual(-1); - expect(compare('1-cr1', '1')).toEqual(-1); - expect(compare('0.0-1552', '1.10.520')).toEqual(-1); - expect(compare('0.0.1', '999')).toEqual(-1); - expect(compare('1.3-RC1-groovy-2.5', '1.3-groovy-2.5')).toEqual(-1); - expect(compare('1-abc', '1-xyz')).toEqual(-1); - expect(compare('Hoxton.RELEASE', 'Hoxton.SR1')).toEqual(-1); - }); - it('returns greater than', () => { - expect(compare('1.1', '1')).toEqual(1); - expect(compare('2', '1')).toEqual(1); - expect(compare('1', '1-snapshot')).toEqual(1); - expect(compare('1', '1-snap')).toEqual(1); - expect(compare('1.2.3-snap2', '1.2.3-snap1')).toEqual(1); - expect(compare('1-sp', '1')).toEqual(1); - expect(compare('1-foo10', '1-foo2')).toEqual(1); - expect(compare('1-milestone-2', '1-m1')).toEqual(1); - expect(compare('1-foo', '1.foo')).toEqual(1); - expect(compare('1-1', '1-foo')).toEqual(1); - expect(compare('1-beta.1', '1-alpha.1')).toEqual(1); - expect(compare('1.1', '1-1')).toEqual(1); - expect(compare('1-sp', '1-ga')).toEqual(1); - expect(compare('1-sp.1', '1-ga.1')).toEqual(1); - expect(compare('1-ga-1', '1-sp-1')).toEqual(1); - expect(compare('1', '1-cr1')).toEqual(1); - expect(compare('1.10.520', '0.0-1552')).toEqual(1); - expect(compare('999', '0.0.1')).toEqual(1); - expect(compare('1.3-groovy-2.5', '1.3-RC1-groovy-2.5')).toEqual(1); - expect(compare('1-xyz', '1-abc')).toEqual(1); - expect(compare('Hoxton.SR1', 'Hoxton.RELEASE')).toEqual(1); + it('uses same function module export and api object', () => { + expect(isValid).toBe(_isValid); }); - const invalidRanges = [ - '1.2.3-SNAPSHOT', // versions should be handled separately - '[]', - '[,]', - '(', - '[', - ',', - '[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]', - ]; - it('filters out incorrect ranges', () => { - invalidRanges.forEach((rangeStr) => { - const range = parseRange(rangeStr); - expect(range).toBeNull(); - expect(rangeToStr(range)).toBeNull(); - }); + test.each` + version | expected + ${'1.0.0'} | ${true} + ${'[1.12.6,1.18.6]'} | ${true} + ${undefined} | ${false} + `('isValid("$version") === $expected', ({ version, expected }) => { + expect(!!isValid(version)).toBe(expected); }); - it('parses version ranges and translates them back to string', () => { - const presetRanges = { - ...invalidRanges.reduce((acc, str) => ({ ...acc, [str]: null }), {}), - '[1.0]': [ - { - leftType: 'INCLUDING_POINT', - leftValue: '1.0', - leftBracket: '[', - rightType: 'INCLUDING_POINT', - rightValue: '1.0', - rightBracket: ']', - }, - ], - '(,1.0]': [ - { - leftType: 'EXCLUDING_POINT', - leftValue: null, - leftBracket: '(', - rightType: 'INCLUDING_POINT', - rightValue: '1.0', - rightBracket: ']', - }, - ], - '[1.2,1.3]': [ - { - leftType: 'INCLUDING_POINT', - leftValue: '1.2', - leftBracket: '[', - rightType: 'INCLUDING_POINT', - rightValue: '1.3', - rightBracket: ']', - }, - ], - '[1.0,2.0)': [ - { - leftType: 'INCLUDING_POINT', - leftValue: '1.0', - leftBracket: '[', - rightType: 'EXCLUDING_POINT', - rightValue: '2.0', - rightBracket: ')', - }, - ], - '[1.5,)': [ - { - leftType: 'INCLUDING_POINT', - leftValue: '1.5', - leftBracket: '[', - rightType: 'EXCLUDING_POINT', - rightValue: null, - rightBracket: ')', - }, - ], - '(,1.0],[1.2,)': [ - { - leftType: 'EXCLUDING_POINT', - leftValue: null, - leftBracket: '(', - rightType: 'INCLUDING_POINT', - rightValue: '1.0', - rightBracket: ']', - }, - { - leftType: 'INCLUDING_POINT', - leftValue: '1.2', - leftBracket: '[', - rightType: 'EXCLUDING_POINT', - rightValue: null, - rightBracket: ')', - }, - ], - '(,1.1),(1.1,)': [ - { - leftType: 'EXCLUDING_POINT', - leftValue: null, - leftBracket: '(', - rightType: 'EXCLUDING_POINT', - rightValue: '1.1', - rightBracket: ')', - }, - { - leftType: 'EXCLUDING_POINT', - leftValue: '1.1', - leftBracket: '(', - rightType: 'EXCLUDING_POINT', - rightValue: null, - rightBracket: ')', - }, - ], - }; - Object.keys(presetRanges).forEach((rangeStr) => { - const presetValue = presetRanges[rangeStr]; - const fullRange = parseRange(rangeStr); - expect(presetValue).toEqual(fullRange); - if (fullRange === null) { - // eslint-disable-next-line jest/no-conditional-expect - expect(presetValue).toBeNull(); - } else { - // eslint-disable-next-line jest/no-conditional-expect - expect(rangeToStr(fullRange)).toEqual(rangeStr); - } - }); + + test.each` + version | expected + ${''} | ${false} + ${'1.0.0'} | ${true} + ${'0'} | ${true} + ${'0.1-2-sp'} | ${true} + ${'1-final'} | ${true} + ${'1-foo'} | ${true} + ${'v1.0.0'} | ${true} + ${'x1.0.0'} | ${true} + ${'2.1.1.RELEASE'} | ${true} + ${'Greenwich.SR1'} | ${true} + ${'.1'} | ${false} + ${'1.'} | ${false} + ${'-1'} | ${false} + ${'1-'} | ${false} + ${'[1.12.6,1.18.6]'} | ${false} + ${'RELEASE'} | ${false} + ${'release'} | ${false} + ${'LATEST'} | ${false} + ${'latest'} | ${false} + ${'foobar'} | ${true} + `('isVersion("$version") === $expected', ({ version, expected }) => { + expect(!!isVersion(version)).toBe(expected); }); - it('extends ranges with new versions', () => { - const sample = [ - ['[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,]'], // invalid range - ['[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)'], + test.each` + version | expected + ${''} | ${false} + ${'foobar'} | ${true} + ${'final'} | ${true} + ${'1'} | ${true} + ${'1.2'} | ${true} + ${'1.2.3'} | ${true} + ${'1.2.3.4'} | ${true} + ${'v1.2.3.4'} | ${true} + ${'1-alpha-1'} | ${false} + ${'1-b1'} | ${false} + ${'1-foo'} | ${true} + ${'1-final-1.0.0'} | ${true} + ${'1-release'} | ${true} + ${'1.final'} | ${true} + ${'1.0milestone1'} | ${false} + ${'1-sp'} | ${true} + ${'1-ga-1'} | ${true} + ${'1.3-groovy-2.5'} | ${true} + ${'1.3-RC1-groovy-2.5'} | ${false} + ${'Hoxton.RELEASE'} | ${true} + ${'Hoxton.SR'} | ${true} + ${'Hoxton.SR1'} | ${true} + `('isStable("$version") === $expected', ({ version, expected }) => { + const res = !!isStable(version); + expect(res).toBe(expected); + }); - ['[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)'], + test.each` + input | major | minor | patch + ${''} | ${null} | ${null} | ${null} + ${'1'} | ${1} | ${0} | ${0} + ${'1.2'} | ${1} | ${2} | ${0} + ${'1.2.3'} | ${1} | ${2} | ${3} + ${'v1.2.3'} | ${1} | ${2} | ${3} + ${'v1.2.3'} | ${1} | ${2} | ${3} + ${'1rc42'} | ${1} | ${0} | ${0} + ${'1-rc42'} | ${1} | ${0} | ${0} + ${'1-rc42-1'} | ${1} | ${0} | ${0} + ${'1-rc10'} | ${1} | ${0} | ${0} + ${'1.2.3.4'} | ${1} | ${2} | ${3} + `( + '"$input" is represented as [$major, $minor, $patch]', + ({ input, major, minor, patch }) => { + expect(getMajor(input)).toBe(major); + expect(getMinor(input)).toBe(minor); + expect(getPatch(input)).toBe(patch); + } + ); - ['(,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]'], + test.each` + version | range | expected + ${'0'} | ${'[0,1]'} | ${true} + ${'1'} | ${'[0,1]'} | ${true} + ${'0'} | ${'(0,1)'} | ${false} + ${'1'} | ${'(0,1)'} | ${false} + ${'1'} | ${'(0,2)'} | ${true} + ${'1'} | ${'[0,2]'} | ${true} + ${'1'} | ${'(,1]'} | ${true} + ${'1'} | ${'(,1)'} | ${false} + ${'1'} | ${'[1,)'} | ${true} + ${'1'} | ${'(1,)'} | ${false} + ${'1'} | ${'(,1),(1,)'} | ${false} + ${'1'} | ${'(0,1),(1,2)'} | ${false} + ${'1.0.0.RC9.2'} | ${'(,1.0.0.RC9.2),(1.0.0.RC9.2,)'} | ${false} + ${'1.0.0-RC14'} | ${'(,1.0.0.RC9.2),(1.0.0.RC9.2,)'} | ${true} + ${'0'} | ${''} | ${false} + ${'1'} | ${'1'} | ${true} + ${'1'} | ${'(1'} | ${false} + `( + 'matches("$version", "$range") === $expected', + ({ version, range, expected }) => { + expect(matches(version, range)).toBe(expected); + } + ); - ['[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)'], - ]; - sample.forEach(([oldRepr, newValue, newRepr]) => { - expect(autoExtendMavenRange(oldRepr, newValue)).toEqual(newRepr); - }); + test.each` + a | b | expected + ${'1.1'} | ${'1'} | ${true} + `('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => { + expect(maven.isGreaterThan(a, b)).toBe(expected); }); - it('returns valid', () => { - expect(isValid('1.0.0')).toBe(true); - expect(isValid('[1.12.6,1.18.6]')).toBe(true); - expect(isValid(undefined)).toBe(false); - expect(isValid === _isValid).toBe(true); - }); - it('validates version string', () => { - expect(isVersion('')).toBe(false); - expect(isVersion('1.0.0')).toBe(true); - expect(isVersion('0')).toBe(true); - expect(isVersion('0.1-2-sp')).toBe(true); - expect(isVersion('1-final')).toBe(true); - expect(isVersion('1-foo')).toBe(true); - expect(isVersion('v1.0.0')).toBe(true); - expect(isVersion('x1.0.0')).toBe(true); - expect(isVersion('2.1.1.RELEASE')).toBe(true); - expect(isVersion('Greenwich.SR1')).toBe(true); - expect(isVersion('.1')).toBe(false); - expect(isVersion('1.')).toBe(false); - expect(isVersion('-1')).toBe(false); - expect(isVersion('1-')).toBe(false); - expect(isVersion('[1.12.6,1.18.6]')).toBe(false); - expect(isVersion('RELEASE')).toBe(false); - expect(isVersion('release')).toBe(false); - expect(isVersion('LATEST')).toBe(false); - expect(isVersion('latest')).toBe(false); - expect(isVersion('foobar')).toBe(true); - }); - it('checks if version is stable', () => { - expect(isStable('')).toBeNull(); - expect(isStable('foobar')).toBe(true); - expect(isStable('final')).toBe(true); - expect(isStable('1')).toBe(true); - expect(isStable('1.2')).toBe(true); - expect(isStable('1.2.3')).toBe(true); - expect(isStable('1.2.3.4')).toBe(true); - expect(isStable('v1.2.3.4')).toBe(true); - expect(isStable('1-alpha-1')).toBe(false); - expect(isStable('1-b1')).toBe(false); - expect(isStable('1-foo')).toBe(true); - expect(isStable('1-final-1.0.0')).toBe(true); - expect(isStable('1-release')).toBe(true); - expect(isStable('1.final')).toBe(true); - expect(isStable('1.0milestone1')).toBe(false); - expect(isStable('1-sp')).toBe(true); - expect(isStable('1-ga-1')).toBe(true); - expect(isStable('1.3-groovy-2.5')).toBe(true); - expect(isStable('1.3-RC1-groovy-2.5')).toBe(false); - expect(isStable('Hoxton.RELEASE')).toBe(true); - expect(isStable('Hoxton.SR')).toBe(true); - expect(isStable('Hoxton.SR1')).toBe(true); - }); - it('returns major version', () => { - expect(getMajor('')).toBeNull(); - expect(getMajor('1')).toEqual(1); - expect(getMajor('1.2')).toEqual(1); - expect(getMajor('1.2.3')).toEqual(1); - expect(getMajor('v1.2.3')).toEqual(1); - expect(getMajor('1rc42')).toEqual(1); - }); - it('returns minor version', () => { - expect(getMinor('')).toBeNull(); - expect(getMinor('1')).toEqual(0); - expect(getMinor('1.2')).toEqual(2); - expect(getMinor('1.2.3')).toEqual(2); - expect(getMinor('v1.2.3')).toEqual(2); - expect(getMinor('1.2.3.4')).toEqual(2); - expect(getMinor('1-rc42')).toEqual(0); - }); - it('returns patch version', () => { - expect(getPatch('')).toBeNull(); - expect(getPatch('1')).toEqual(0); - expect(getPatch('1.2')).toEqual(0); - expect(getPatch('1.2.3')).toEqual(3); - expect(getPatch('v1.2.3')).toEqual(3); - expect(getPatch('1.2.3.4')).toEqual(3); - expect(getPatch('1-rc10')).toEqual(0); - expect(getPatch('1-rc42-1')).toEqual(0); - }); - it('matches against maven ranges', () => { - expect(matches('0', '[0,1]')).toBe(true); - expect(matches('1', '[0,1]')).toBe(true); - expect(matches('0', '(0,1)')).toBe(false); - expect(matches('1', '(0,1)')).toBe(false); - expect(matches('1', '(0,2)')).toBe(true); - expect(matches('1', '[0,2]')).toBe(true); - expect(matches('1', '(,1]')).toBe(true); - expect(matches('1', '(,1)')).toBe(false); - expect(matches('1', '[1,)')).toBe(true); - expect(matches('1', '(1,)')).toBe(false); - expect(matches('1', '(,1),(1,)')).toBe(false); - expect(matches('1', '(0,1),(1,2)')).toBe(false); - expect(matches('1.0.0.RC9.2', '(,1.0.0.RC9.2),(1.0.0.RC9.2,)')).toBe(false); - expect(matches('1.0.0-RC14', '(,1.0.0.RC9.2),(1.0.0.RC9.2,)')).toBe(true); - expect(matches('0', '')).toBe(false); - expect(matches('1', '1')).toBe(true); - expect(matches('1', '(1')).toBe(false); - }); + test.each` + versions | range | expected + ${['1']} | ${'1'} | ${'1'} + `( + 'getSatisfyingVersion($versions, "$range") === $expected', + ({ versions, range, expected }) => { + expect(maven.getSatisfyingVersion(versions, range)).toBe(expected); + } + ); - it('api', () => { - expect(maven.isGreaterThan('1.1', '1')).toBe(true); - expect(maven.getSatisfyingVersion(['1'], '1')).toBe('1'); - expect( - maven.getNewValue({ - currentValue: '1', - rangeStrategy: null, - currentVersion: null, - newVersion: '1.1', - }) - ).toBe('1.1'); - expect( - maven.getNewValue({ - currentValue: '[1.2.3,]', - rangeStrategy: null, - currentVersion: null, - newVersion: '1.2.4', - }) - ).toBe('[1.2.3,]'); - }); - it('pins maven ranges', () => { - const sample = [ - ['[1.2.3]', '1.2.3', '1.2.4'], - ['[1.0.0,1.2.3]', '1.0.0', '1.2.4'], - ['[1.0.0,1.2.23]', '1.0.0', '1.2.23'], - ['(,1.0]', '0.0.1', '2.0'], - ['],1.0]', '0.0.1', '2.0'], - ['(,1.0)', '0.1', '2.0'], - ['],1.0[', '2.0', '],2.0['], - ['[1.0,1.2],[1.3,1.5)', '1.0', '1.2.4'], - ['[1.0,1.2],[1.3,1.5[', '1.0', '1.2.4'], - ['[1.2.3,)', '1.2.3', '1.2.4'], - ['[1.2.3,[', '1.2.3', '1.2.4'], - ]; - sample.forEach(([currentValue, currentVersion, newVersion]) => { - expect( - getNewValue({ - currentValue, - rangeStrategy: 'pin', - currentVersion, - newVersion, - }) - ).toEqual(newVersion); - }); - }); + test.each` + versions | range | expected + ${['1']} | ${'1'} | ${'1'} + `( + 'getSatisfyingVersion($versions, "$range") === $expected', + ({ versions, range, expected }) => { + expect(maven.getSatisfyingVersion(versions, range)).toBe(expected); + } + ); + + test.each` + currentValue | rangeStrategy | currentVersion | newVersion | expected + ${'1'} | ${null} | ${null} | ${'1.1'} | ${'1.1'} + ${'[1.2.3,]'} | ${null} | ${null} | ${'1.2.4'} | ${'[1.2.3,]'} + ${'[1.2.3]'} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'} + ${'[1.0.0,1.2.3]'} | ${'pin'} | ${'1.0.0'} | ${'1.2.4'} | ${'1.2.4'} + ${'[1.0.0,1.2.23]'} | ${'pin'} | ${'1.0.0'} | ${'1.2.23'} | ${'1.2.23'} + ${'(,1.0]'} | ${'pin'} | ${'0.0.1'} | ${'2.0'} | ${'2.0'} + ${'],1.0]'} | ${'pin'} | ${'0.0.1'} | ${'2.0'} | ${'2.0'} + ${'(,1.0)'} | ${'pin'} | ${'0.1'} | ${'2.0'} | ${'2.0'} + ${'],1.0['} | ${'pin'} | ${'2.0'} | ${'],2.0['} | ${'],2.0['} + ${'[1.0,1.2],[1.3,1.5)'} | ${'pin'} | ${'1.0'} | ${'1.2.4'} | ${'1.2.4'} + ${'[1.0,1.2],[1.3,1.5['} | ${'pin'} | ${'1.0'} | ${'1.2.4'} | ${'1.2.4'} + ${'[1.2.3,)'} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'} + ${'[1.2.3,['} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'} + `( + 'getNewValue($currentValue, $rangeStrategy, $currentVersion, $newVersion, $expected) === $expected', + ({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => { + const res = maven.getNewValue({ + currentValue, + rangeStrategy, + currentVersion, + newVersion, + }); + expect(res).toBe(expected); + } + ); }); -- GitLab