Skip to content

Commit 5d2c304

Browse files
authored
Merge pull request #375 from codefori/worksofliam/issue373
Add test case for fixed-format extender functionality
2 parents b0bf206 + 58273e3 commit 5d2c304

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

language/models/fixed.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ function calculateToken(lineNumber, startingPos, value, type) {
1414
return;
1515
}
1616

17-
if (type === `special-ind`) {
17+
switch (type) {
18+
case `special-ind`:
1819
type = `special`;
1920
resultValue = `*IN` + resultValue;
21+
break;
22+
23+
case `opcode`:
24+
// Remove extender from opcode
25+
if (resultValue.includes(`(`) && resultValue.includes(`)`)) {
26+
resultValue = resultValue.substring(0, resultValue.indexOf(`(`));
27+
}
28+
break;
2029
}
2130

2231
const frontSpaces = value.length - value.trimStart().length;

tests/suite/basics.test.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,4 +1356,122 @@ test('header file parse', async () => {
13561356
expect(cache.procedures.length).toBe(1);
13571357

13581358
expect(cache.procedures[0].name).toBe(`APIVAL01S_iws_validate`);
1359+
});
1360+
1361+
test('fixed-format c spec', async () => {
1362+
const lines = [
1363+
` Farticle1 UF E K DISK`,
1364+
``,
1365+
` d UpdArt pr`,
1366+
` d qty 5 0 value`,
1367+
` d id like(new.ODARID)`,
1368+
``,
1369+
` D PARM1 DS`,
1370+
` * Physical file name`,
1371+
` D FNAME 10`,
1372+
` * Physical file library`,
1373+
` D LNAME 10`,
1374+
` * Member name`,
1375+
` D MNAME 10`,
1376+
` * Trigger event 1=Ins, 2=Del, 3=Upd`,
1377+
` D TEVEN 1`,
1378+
` * Trigger time 1=After, 2=Before`,
1379+
` D TTIME 1`,
1380+
` * Commit lock level`,
1381+
` D CMTLCK 1`,
1382+
` * Reserved`,
1383+
` D 3`,
1384+
` * CCSID`,
1385+
` D CCSID 10i 0`,
1386+
` * Reserved`,
1387+
` D 8`,
1388+
` * Offset to the original record`,
1389+
` D OLDOFF 10i 0`,
1390+
` * length of the original record`,
1391+
` D OLDLEN 10i 0`,
1392+
` * Offset to the original record null byte map`,
1393+
` D ONOFF 10i 0`,
1394+
` * length of the null byte map`,
1395+
` D ONLEN 10i 0`,
1396+
` * Offset to the new record`,
1397+
` D NEWOFF 10i 0`,
1398+
` * length of the new record`,
1399+
` D NEWLEN 10i 0`,
1400+
` * Offset to the new record null byte map`,
1401+
` D NNOFF 10i 0`,
1402+
` * length of the null byte map`,
1403+
` D NNLEN 10i 0`,
1404+
``,
1405+
` * Trigger Buffer Length`,
1406+
` D parm2 s 10i 0`,
1407+
``,
1408+
` * Record to be inserted or new values`,
1409+
` D NEW E DS EXTNAME(detord)`,
1410+
` D qualified`,
1411+
` D based(pn)`,
1412+
``,
1413+
` * Record to be deleted or old values`,
1414+
` D OLD E DS EXTNAME(detord)`,
1415+
` D qualified`,
1416+
` D based(po)`,
1417+
` * SET UP THE ENTRY PARAMETER LIST.`,
1418+
``,
1419+
` C *ENTRY PLIST`,
1420+
` C PARM PARM1`,
1421+
` C PARM PARM2`,
1422+
` C if %parms = 0`,
1423+
` C seton lr`,
1424+
` C return`,
1425+
` C ENDIF`,
1426+
` C select`,
1427+
` c when teven = '1'`,
1428+
` c eval pn = %addr(parm1) + newoff`,
1429+
` c callp UpdArt(new.odqty:new.odarid)`,
1430+
` c when teven = '2'`,
1431+
` c eval po = %addr(parm1) + oldoff`,
1432+
` c callp(e) addlogEntry('ORD700:Order Line deleted ' +`,
1433+
` c %char(Old.odorid) + ' ' + %char(Old.odline)`,
1434+
` c + ' article : ' + old.odarid`,
1435+
` c + ' quantity : ' + %char(old.odqty))`,
1436+
` c callp UpdArt(-Old.odqty + Old.odqtyliv:old.odarid)`,
1437+
` c when teven = '3'`,
1438+
` c eval pn = %addr(parm1) + newoff`,
1439+
` c eval po = %addr(parm1) + oldoff`,
1440+
` c if new.odarid = Old.odarid`,
1441+
` c callp UpdArt((New.odqty - Old.odqty)`,
1442+
` c - (New.odqtyLiv - Old.odqtyLiv)`,
1443+
` c :new.odarid)`,
1444+
` c else`,
1445+
` c callp UpdArt(new.odqty- new.odqtyliv:new.odarid)`,
1446+
` c callp UpdArt(-Old.odqty + Old.odqtyliv:old.odarid)`,
1447+
` c endif`,
1448+
` c endsl`,
1449+
` c return`,
1450+
``,
1451+
` P UpdArt b`,
1452+
` d UpdArt pi`,
1453+
` d qty 5 0 value`,
1454+
` d id like(new.ODARID)`,
1455+
` c if qty = 0`,
1456+
` c return`,
1457+
` c ENDIF`,
1458+
` c id chain article1`,
1459+
` c if not %found`,
1460+
` c return`,
1461+
` c ENDIF`,
1462+
` c eval ARCUSQTY += qty`,
1463+
` c update farti`,
1464+
` P UpdArt e`,
1465+
].join(`\n`);
1466+
1467+
const cache = await parser.getDocs(uri, lines, { ignoreCache: true, withIncludes: false });
1468+
expect(cache.constants.length).toBe(0);
1469+
expect(cache.procedures.length).toBe(1);
1470+
expect(cache.procedures[0].name).toBe(`UpdArt`);
1471+
expect(cache.procedures[0].subItems.length).toBe(2);
1472+
1473+
console.log(cache.variables);
1474+
expect(cache.structs.length).toBe(3);
1475+
expect(cache.variables.length).toBe(1);
1476+
13591477
});

0 commit comments

Comments
 (0)