Skip to content
Snippets Groups Projects
Unverified Commit 7178da30 authored by george-wilson-rea's avatar george-wilson-rea Committed by GitHub
Browse files

refactor: Tidy Scala version normalization code (#29642)

parent 7743c77d
No related branches found
No related tags found
No related merge requests found
...@@ -201,16 +201,12 @@ function depHandler(ctx: Ctx): Ctx { ...@@ -201,16 +201,12 @@ function depHandler(ctx: Ctx): Ctx {
delete ctx.variableName; delete ctx.variableName;
const depName = `${groupId!}:${artifactId!}`; const depName = `${groupId!}:${artifactId!}`;
const isScala3 = scalaVersion?.[0] === '3';
const scalaVersionForPackageName = isScala3 ? '3' : scalaVersion;
const dep: PackageDependency = { const dep: PackageDependency = {
datasource: SbtPackageDatasource.id, datasource: SbtPackageDatasource.id,
depName, depName,
packageName: packageName:
scalaVersionForPackageName && useScalaVersion scalaVersion && useScalaVersion ? `${depName}_${scalaVersion}` : depName,
? `${depName}_${scalaVersionForPackageName}`
: depName,
currentValue, currentValue,
}; };
......
import { sortPackageFiles } from './util'; import { normalizeScalaVersion, sortPackageFiles } from './util';
describe('modules/manager/sbt/util', () => { describe('modules/manager/sbt/util', () => {
describe('sortPackageFiles()', () => { describe('sortPackageFiles()', () => {
...@@ -15,4 +15,41 @@ describe('modules/manager/sbt/util', () => { ...@@ -15,4 +15,41 @@ describe('modules/manager/sbt/util', () => {
]); ]);
}); });
}); });
describe('normalizeScalaVersion()', () => {
it('does not normalize prior to 2.10', () => {
const version = '2.9.3';
expect(normalizeScalaVersion(version)).toBe('2.9.3');
});
it('normalizes a Scala 2.10 version number', () => {
const version = '2.10.7';
expect(normalizeScalaVersion(version)).toBe('2.10');
});
it('normalizes a Scala 2.11 version number', () => {
const version = '2.11.12';
expect(normalizeScalaVersion(version)).toBe('2.11');
});
it('normalizes a Scala 2.12 version number', () => {
const version = '2.12.19';
expect(normalizeScalaVersion(version)).toBe('2.12');
});
it('normalizes a Scala 2.13 version number', () => {
const version = '2.13.14';
expect(normalizeScalaVersion(version)).toBe('2.13');
});
it('normalizes a Scala 3 LTS version number', () => {
const version = '3.3.3';
expect(normalizeScalaVersion(version)).toBe('3');
});
it('normalizes a Scala 3 current version number', () => {
const version = '3.4.2';
expect(normalizeScalaVersion(version)).toBe('3');
});
});
}); });
...@@ -21,9 +21,14 @@ export function normalizeScalaVersion(str: string): string { ...@@ -21,9 +21,14 @@ export function normalizeScalaVersion(str: string): string {
return str; return str;
} }
} }
const isScala3 = versioning.isGreaterThan(str, '3.0.0');
if (regEx(/^\d+\.\d+\.\d+$/).test(str)) { if (regEx(/^\d+\.\d+\.\d+$/).test(str)) {
if (isScala3) {
return str.replace(regEx(/^(\d+)\.(\d+)\.\d+$/), '$1');
} else {
return str.replace(regEx(/^(\d+)\.(\d+)\.\d+$/), '$1.$2'); return str.replace(regEx(/^(\d+)\.(\d+)\.\d+$/), '$1.$2');
} }
}
// istanbul ignore next // istanbul ignore next
return str; return str;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment