Skip to content

Commit 67c9183

Browse files
committed
Tests to prove references to template (#320)
Signed-off-by: worksofliam <[email protected]>
1 parent 6e99355 commit 67c9183

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

tests/suite/files.test.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ test("ds_extname", async () => {
9292
expect(structDef.subItems.length).toBe(14);
9393
});
9494

95-
test("ds_extname_no_alias", async () => {
95+
test("ds_extname", async () => {
9696
const lines = [
9797
`**free`,
9898
``,
99-
`Dcl-Ds dept ExtName('department') Qualified;`,
99+
`Dcl-Ds Employee ExtName('EMPLOYEE') Qualified;`,
100100
`end-ds;`,
101101
``,
102-
`Dsply dept.deptname;`,
102+
`Dsply Employee.empno;`,
103103
``,
104104
`return;`
105105
].join(`\n`);
@@ -109,11 +109,31 @@ test("ds_extname_no_alias", async () => {
109109
expect(cache.files.length).toBe(0);
110110
expect(cache.structs.length).toBe(1);
111111

112-
const dept = cache.find(`dept`);
113-
expect(dept.subItems.length).toBe(5);
112+
const structDef = cache.find(`employee`);
113+
expect(structDef.name).toBe(`Employee`);
114+
expect(structDef.subItems.length).toBe(14);
115+
});
114116

115-
expect(dept.subItems[0].name).toBe(`DEPTNO`);
116-
expect(dept.subItems[1].name).toBe(`DEPTNAME`);
117+
test("ds_extname_template", async () => {
118+
const lines = [
119+
`**free`,
120+
``,
121+
`Dcl-Ds dept ExtName('department') Qualified template end-ds;`,
122+
``,
123+
`Dcl-DS dsExample qualified inz;`,
124+
` Field1 like(tmpDS.Field1) inz;`,
125+
` Field2 like(tmpDS.Field2) inz;`,
126+
`END-DS`,
127+
``,
128+
`return;`
129+
].join(`\n`);
130+
131+
const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true});
132+
133+
expect(cache.structs.length).toBe(2);
134+
135+
const dept = cache.find(`dsExample`);
136+
expect(dept.subItems.length).toBe(2);
117137
});
118138

119139
test("ds_extname_alias", async () => {
@@ -187,4 +207,5 @@ test('file DS in a copy book', async () => {
187207
expect(someStruct.subItems.length).toBeGreaterThan(0);
188208

189209
expect(someStruct.subItems.map(s => ({name: s.name, keyword: s.keyword}))).toMatchObject(globalStruct.subItems.map(s => ({name: s.name, keyword: s.keyword})));
190-
})
210+
});
211+

tests/suite/linter.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,4 +3687,41 @@ test('allow special global subroutines', async () => {
36873687
}, cache);
36883688

36893689
expect(errors.length).toBe(2);
3690+
});
3691+
3692+
test("DS template references", async () => {
3693+
const lines = [
3694+
`**free`,
3695+
``,
3696+
`Dcl-Ds dept ExtName('department') Qualified template end-ds;`,
3697+
``,
3698+
`Dcl-DS dsExample qualified inz;`,
3699+
` Field1 like(dept.DEPTNO) inz;`,
3700+
` Field2 like(dept.DEPTNAME) inz;`,
3701+
`END-DS`,
3702+
``,
3703+
`return;`
3704+
].join(`\n`);
3705+
3706+
const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true, collectReferences: true});
3707+
const { errors } = Linter.getErrors({ uri, content: lines }, {
3708+
NoUnreferenced: true,
3709+
}, cache);
3710+
3711+
const dept = cache.find(`dept`);
3712+
const deptno = dept.subItems.find(s => s.name === `DEPTNO`);
3713+
const deptname = dept.subItems.find(s => s.name === `DEPTNAME`);
3714+
3715+
expect(deptno).toBeDefined();
3716+
expect(deptname).toBeDefined();
3717+
3718+
expect(deptno.references.length).toBe(1);
3719+
expect(deptname.references.length).toBe(1);
3720+
3721+
expect(errors.length).toBe(3);
3722+
3723+
for (const err of errors) {
3724+
expect(lines.substring(err.offset.start, err.offset.end)).toContain(`inz`);
3725+
}
3726+
36903727
});

0 commit comments

Comments
 (0)