Skip to content

Commit 9779722

Browse files
Rework handling of long names for tests and fix edge cases
Signed-off-by: Sanjula Ganepola <[email protected]>
1 parent b9ac050 commit 9779722

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

cli/src/utils.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ import { ReadFileSystem } from "./readFileSystem";
1111

1212
export function getSystemNameFromPath(inputName: string) {
1313
const isTest = inputName.toUpperCase().endsWith(`.TEST`);
14-
let baseName = inputName.includes(`-`) ? inputName.split(`-`)[0] : inputName;
15-
1614
if (isTest) {
1715
// Remove the .TEST part
18-
baseName = baseName.substring(0, baseName.length - 5);
16+
inputName = inputName.substring(0, inputName.length - 5);
1917
}
2018

21-
// If the name is of valid length, return it
22-
if (baseName.length <= 10 && !isTest) {
19+
const baseName = inputName.includes(`-`) ? inputName.split(`-`)[0] : inputName;
20+
21+
// Test -> If the name with test prefix T is of valid length, return it
22+
if (isTest && `T${baseName}`.length <= 10) {
23+
return `T${baseName}`.toUpperCase();
24+
}
25+
26+
// Non-test -> If the name is of valid length, return it
27+
if (!isTest && baseName.length <= 10) {
2328
return baseName.toUpperCase();
2429
}
2530

@@ -33,15 +38,10 @@ export function getSystemNameFromPath(inputName: string) {
3338
name = parts[1];
3439
}
3540

36-
if (isTest) {
37-
prefix = `T`;
38-
name = name.toUpperCase();
39-
}
40-
4141
// We start the system name with the suppliedPrefix
4242
let systemName = prefix;
4343

44-
for (let i = 0; i < name.length && systemName.length <= 10; i++) {
44+
for (let i = 0; i < name.length && systemName.length < 10; i++) {
4545
const char = name[i];
4646
if (char === char.toUpperCase() || i === 0) {
4747
systemName += char;
@@ -53,7 +53,13 @@ export function getSystemNameFromPath(inputName: string) {
5353
systemName = name.substring(0, 10);
5454
}
5555

56-
return systemName.toUpperCase();
56+
// If it is a test, we prefix it with T
57+
if (isTest) {
58+
systemName = `T${systemName}`;
59+
}
60+
61+
// System name could exceed 10 characters (ie. if prefix is long or because of T prefix) so substring one last time
62+
return systemName.substring(0, 10).toUpperCase();
5763
}
5864

5965
/**
@@ -172,7 +178,7 @@ export function getReferenceObjectsFrom(content: string) {
172178
return pseudoObjects;
173179
}
174180

175-
export function fromCl(cl: string): {command: string, parameters: CommandParameters} {
181+
export function fromCl(cl: string): { command: string, parameters: CommandParameters } {
176182
let gotCommandnName = false;
177183
let parmDepth = 0;
178184

@@ -253,7 +259,7 @@ export function toCl(command: string, parameters?: CommandParameters) {
253259
}
254260

255261
export function checkFileExists(file) {
256-
return fs.promises.access(file, fs.constants.F_OK)
262+
return fs.promises.access(file, fs.constants.F_OK)
257263
.then(() => true)
258264
.catch(() => false)
259265
}

0 commit comments

Comments
 (0)