Skip to content

Commit

Permalink
Update unit tests to check ranges
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Barry Allan <[email protected]>
  • Loading branch information
worksofliam committed Aug 19, 2022
1 parent 6e3d5a2 commit 519240e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/suite/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ exports.test3 = async () => {
assert.strictEqual(cache.variables[0].position.line, 1, `Index of 1 expected`);
assert.strictEqual(cache.variables[1].position.line, 6, `Index of 6 expected`);
assert.strictEqual(cache.structs[0].position.line, 2, `Index of 2 expected`);

assert.deepStrictEqual(cache.structs[0].range, {
start: 2,
end: 5
});
}

/**
Expand All @@ -89,6 +94,7 @@ exports.test4 = async () => {

assert.strictEqual(cache.variables[0].position.line, 1, `Index of 1 expected`);
assert.strictEqual(cache.subroutines[0].range.start, 4, `Index of 4 expected`);
assert.strictEqual(cache.subroutines[0].range.end, 6);
}

/**
Expand Down Expand Up @@ -363,6 +369,11 @@ exports.test12 = async () => {

const theLocalProc = cache.find(`theLocalProc`);

assert.deepStrictEqual(theLocalProc.range, {
start: 16,
end: 23
});

// Has a parameter
assert.strictEqual(theLocalProc.subItems.length, 1, `Expect length of 1`);

Expand Down Expand Up @@ -437,4 +448,57 @@ exports.subds1 = async () => {

assert.strictEqual(DsChangingNodeRole.subItems.length, 13);
assert.strictEqual(DsChangingNodeRole.subItems[12].name, `Role`);

assert.deepStrictEqual(DsChangingNodeRole.range, {
start: 2,
end: 19
});
};

exports.dothingy = async () => {
const lines = [
`**FREE`,
`///`,
`// Get delimiters`,
`//`,
`// Returns a pointer to the used delimiters for parsing the JSON and XML data.`,
`// The pointer points to a data structure in the format <em>jx_DelimiterDS</em>.`,
`//`,
`// @return Pointer to the delimiters data structure (jx_DelimiterDS)`,
`//`,
`// @warning Do not deallocate the returned pointer!`,
`///`,
`Dcl-PR json_getDelims Pointer extproc(*CWIDEN : 'jx_GetDelimiters') End-PR;`,
``,
`///`,
`// Set delimiters`,
`//`,
`// Sets the delimiters used for parsing the JSON and XML data.`,
`// For the default delimiters see constant json_DELIMITERS.`,
`//`,
`// @param Delimiters`,
`///`,
`Dcl-PR json_setDelimiters extproc(*CWIDEN : 'jx_SetDelimiters');`,
` delimiters pointer value options(*string);`,
`End-PR;`,
``,
].join(`\n`);

const parser = new Parser();
const cache = await parser.getDocs(uri, lines);

assert.strictEqual(cache.procedures.length, 2);

const json_getDelims = cache.find(`json_getDelims`);
assert.deepStrictEqual(json_getDelims.range, {
start: 11,
end: 11
});

const json_getDelimiters = cache.find(`json_setDelimiters`);
assert.strictEqual(json_getDelimiters.subItems.length, 1);
assert.deepStrictEqual(json_getDelimiters.range, {
start: 21,
end: 23
});
};
54 changes: 54 additions & 0 deletions tests/suite/fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ exports.fixed10 = async () => {
assert.strictEqual(dataDs.name, `data`);
assert.strictEqual(dataDs.subItems.length, 4);

assert.strictEqual(dataDs.range.start, 0);
assert.strictEqual(dataDs.range.end, 4);

const rrn02 = cache.find(`rrn02`);
assert.strictEqual(rrn02.name, `rrn02`);
assert.strictEqual(rrn02.keywords.includes(`PACKED(7:2)`), true);
Expand Down Expand Up @@ -485,6 +488,8 @@ exports.fixedfree1 = async () => {

const Obj_List = cache.find(`Obj_List`);
assert.strictEqual(Obj_List.name, `Obj_List`);
assert.strictEqual(Obj_List.range.start, 6);
assert.strictEqual(Obj_List.range.end, 50);
assert.strictEqual(Obj_List.position.line, 6);
assert.strictEqual(Obj_List.keywords.includes(`EXPORT`), true);
assert.strictEqual(Obj_List.keyword[`EXPORT`], true);
Expand Down Expand Up @@ -518,6 +523,8 @@ exports.fixed11 = async () => {

const F4DATE = cache.find(`F4DATE`);
assert.strictEqual(F4DATE.subItems.length, 4);
assert.strictEqual(F4DATE.range.start, 0);
assert.strictEqual(F4DATE.range.end, 4);

const parm1 = F4DATE.subItems[0];
assert.strictEqual(parm1.keywords[0], `CHAR(1)`);
Expand All @@ -532,6 +539,11 @@ exports.fixed11 = async () => {
const parm4 = F4DATE.subItems[3];
assert.strictEqual(parm4.keywords[0], `CHAR(1)`);
assert.strictEqual(parm4.keywords[1], `OPTIONS(*NOPASS)`);

const F4DATEDS = cache.find(`F4DATEDS`);
assert.strictEqual(F4DATEDS.subItems.length, 4);
assert.strictEqual(F4DATEDS.range.start, 6);
assert.strictEqual(F4DATEDS.range.end, 10);
};

exports.columnFix = async () => {
Expand All @@ -556,6 +568,24 @@ exports.columnFix = async () => {
const cache = await parser.getDocs(uri, lines);

assert.strictEqual(cache.procedures.length, 3);

const abcd1 = cache.find(`abcd1`);
assert.deepStrictEqual(abcd1.range, {
start: 0,
end: 4
});

const abcd2 = cache.find(`abcd2`);
assert.deepStrictEqual(abcd2.range, {
start: 5,
end: 10
});

const abcd3 = cache.find(`abcd3`);
assert.deepStrictEqual(abcd3.range, {
start: 11,
end: 13
});
};

exports.comments1 = async () => {
Expand Down Expand Up @@ -602,19 +632,43 @@ exports.comments1 = async () => {

const SndMsgPgmQ = cache.find(`SndMsgPgmQ`);
assert.strictEqual(SndMsgPgmQ.subItems.length, 4);
assert.deepStrictEqual(SndMsgPgmQ.range, {
start: 2,
end: 7
});

const ClrMsgPgmQ = cache.find(`ClrMsgPgmQ`);
assert.strictEqual(ClrMsgPgmQ.subItems.length, 1);
assert.deepStrictEqual(ClrMsgPgmQ.range, {
start: 9,
end: 10
});

const SndEscMsg = cache.find(`SndEscMsg`);
assert.strictEqual(SndEscMsg.subItems.length, 1);
assert.deepStrictEqual(SndEscMsg.range, {
start: 13,
end: 14
});

const SndInfMsg = cache.find(`SndInfMsg`);
assert.strictEqual(SndInfMsg.subItems.length, 1);
assert.deepStrictEqual(SndInfMsg.range, {
start: 17,
end: 18
});

const JobLogMsg = cache.find(`JobLogMsg`);
assert.strictEqual(JobLogMsg.subItems.length, 1);
assert.deepStrictEqual(JobLogMsg.range, {
start: 21,
end: 22
});

const Show = cache.find(`Show`);
assert.strictEqual(Show.subItems.length, 3);
assert.deepStrictEqual(Show.range, {
start: 25,
end: 28
});
};

0 comments on commit 519240e

Please sign in to comment.