From bc2e4b38ea7841643c32349ddda2f96d890aa301 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh <rahultesnik@gmail.com> Date: Wed, 8 May 2024 12:42:05 +0545 Subject: [PATCH] test(pep440): add tests (#28915) --- lib/modules/versioning/pep440/index.spec.ts | 8 +++++--- lib/util/package-rules/current-version.spec.ts | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/modules/versioning/pep440/index.spec.ts b/lib/modules/versioning/pep440/index.spec.ts index 8ba12022fb..c9c024ac25 100644 --- a/lib/modules/versioning/pep440/index.spec.ts +++ b/lib/modules/versioning/pep440/index.spec.ts @@ -8,6 +8,7 @@ describe('modules/versioning/pep440/index', () => { ${'1.9'} | ${true} ${'17.04.0'} | ${true} ${'==1.2.3'} | ${true} + ${'==1.2.3.0'} | ${true} ${'==1.2.3rc0'} | ${true} ${'~=1.2.3'} | ${true} ${'==1.2.*'} | ${true} @@ -38,9 +39,10 @@ describe('modules/versioning/pep440/index', () => { }); it.each` - a | b | expected - ${'1.0'} | ${'>=1.0.0'} | ${true} - ${'>=3.8'} | ${'>=3.9'} | ${false} + a | b | expected + ${'1.0'} | ${'>=1.0.0'} | ${true} + ${'1.6.2'} | ${'<2.2.1.0'} | ${true} + ${'>=3.8'} | ${'>=3.9'} | ${false} `('matches($a, $b) === $expected', ({ a, b, expected }) => { expect(pep440.matches(a, b)).toBe(expected); }); diff --git a/lib/util/package-rules/current-version.spec.ts b/lib/util/package-rules/current-version.spec.ts index d8b8ee034d..07a4ba1dfc 100644 --- a/lib/util/package-rules/current-version.spec.ts +++ b/lib/util/package-rules/current-version.spec.ts @@ -20,7 +20,7 @@ describe('util/package-rules/current-version', () => { }); it('return false on version exception', () => { - const spy = jest.spyOn(pep440, 'matches').mockImplementationOnce(() => { + const spy = jest.spyOn(pep440, 'isValid').mockImplementationOnce(() => { throw new Error(); }); const result = matcher.matches( @@ -36,6 +36,19 @@ describe('util/package-rules/current-version', () => { expect(spy.mock.calls).toHaveLength(1); }); + it('return true for a valid match', () => { + const result = matcher.matches( + { + versioning: 'pep440', + currentValue: '1.2.3', + }, + { + matchCurrentVersion: '<1.2.3.5', + }, + ); + expect(result).toBeTrue(); + }); + it('return false if no version could be found', () => { const result = matcher.matches( { -- GitLab