Skip to content

Commit 5218b51

Browse files
authored
Merge pull request #127 from IBM/feature/long-file-name-tests
Fix edge cases for long names and fix handling of `.test` to still apply other rules
2 parents 4d4a8f1 + b609476 commit 5218b51

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
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, name is all uppercase, 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
}

cli/test/environment.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ describe(`Deterministic system name`, () => {
4747
test('Basic name with underscore', () => {
4848
expect(getSystemNameFromPath(`ab_cd`)).toBe(`AB_CD`);
4949
})
50-
test('Long form name', () => {
50+
test('Long form lowercase', () => {
51+
expect(getSystemNameFromPath(`thisisasuperlongname`)).toBe(`THISISASUP`);
52+
})
53+
test('Long form uppercase', () => {
54+
expect(getSystemNameFromPath(`THISISASUPERLONGNAME`)).toBe(`THISISASUP`);
55+
})
56+
test('Long form camel case', () => {
5157
expect(getSystemNameFromPath(`thisIsASuperLongName`)).toBe(`TIASLN`);
5258
})
5359
test('With capitals', () => {
@@ -56,6 +62,9 @@ describe(`Deterministic system name`, () => {
5662
test('With underscore', () => {
5763
expect(getSystemNameFromPath(`ua_fetchUserData`)).toBe(`UAFUD`);
5864
})
65+
test('With long underscore', () => {
66+
expect(getSystemNameFromPath(`abcdefhijkl_fetchUserData`)).toBe(`ABCDEFHIJK`);
67+
})
5968
test('Bob prefix name A', () => {
6069
expect(getSystemNameFromPath(`ART200-Work_with_article`)).toBe(`ART200`);
6170
})
@@ -64,6 +73,39 @@ describe(`Deterministic system name`, () => {
6473
})
6574
});
6675

76+
describe(`Deterministic test system name`, () => {
77+
test('Basic name', () => {
78+
expect(getSystemNameFromPath(`abcd.test`)).toBe(`TABCD`);
79+
})
80+
test('Basic name with underscore', () => {
81+
expect(getSystemNameFromPath(`ab_cd.test`)).toBe(`TAB_CD`);
82+
})
83+
test('Long form lowercase', () => {
84+
expect(getSystemNameFromPath(`thisisasuperlongname.test`)).toBe(`TTHISISASU`);
85+
})
86+
test('Long form uppercase', () => {
87+
expect(getSystemNameFromPath(`THISISASUPERLONGNAME.test`)).toBe(`TTHISISASU`);
88+
})
89+
test('Long form camel case', () => {
90+
expect(getSystemNameFromPath(`thisIsASuperLongName.test`)).toBe(`TTIASLN`);
91+
})
92+
test('With capitals', () => {
93+
expect(getSystemNameFromPath(`FetchUserData.test`)).toBe(`TFUD`);
94+
})
95+
test('With underscore', () => {
96+
expect(getSystemNameFromPath(`ua_fetchUserData.test`)).toBe(`TUAFUD`);
97+
})
98+
test('With long underscore', () => {
99+
expect(getSystemNameFromPath(`abcdefhijkl_fetchUserData.test`)).toBe(`TABCDEFHIJ`);
100+
})
101+
test('Bob prefix name A', () => {
102+
expect(getSystemNameFromPath(`ART200-Work_with_article.test`)).toBe(`TART200`);
103+
})
104+
test('Bob prefix name B', () => {
105+
expect(getSystemNameFromPath(`ART200D-Work_with_Article.test`)).toBe(`TART200D`);
106+
})
107+
});
108+
67109
describe(`CL parser`, () => {
68110
test('Basic command', () => {
69111
const cl = `CRTCLPGM PGM(MYLIB/MYCL) SRCFILE(MYLIB/QCLSRC) SRCMBR(MYCL)`;

docs/pages/general/rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Typically, the basename of the file is also the object name. But, Source Orbit w
6767
| `FetchUserData.cmd` | `FUD.CMD` | All capitals from file name |
6868
| `ua_fetchUserData.sqlrpgle` | `UAFUD.MODULE` | Prefix, followed by first post-prefix character plus following capitals |
6969
| `ART200D-Work_with_Article.DSPF` | `ART200D.FILE` | Support for ibmi-bob file name |
70+
| `empdet.test.rpgle` | `TEMPDET.MODULE` | Prefix object with `T` for names including `.test` in the extension |
7071

7172
Even if you use long file names, your source code still needs to reference the object name for object resolves (not including *include directives* of course.)
7273

0 commit comments

Comments
 (0)