Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/ProgramCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ class ProgramCall {
}

if (!inDs) { // In recursive mode, if it is an element in DS, then no <parm> or </parm> needed.
if (opt && opt.io) {
this.xml += iXml.iXmlNodeParmOpen(opt.io);
} else {
this.xml += iXml.iXmlNodeParmOpen();
}
this.xml += iXml.iXmlNodeParmOpen(opt);
}

if (Array.isArray(data)) { // If it is a struct parameter, recursivly parse its children.
Expand Down
18 changes: 15 additions & 3 deletions lib/ixml.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const I_XML_ATTR_KEY_DB = 'db';
const I_XML_ATTR_KEY_USERID = 'uid';
const I_XML_ATTR_KEY_PASSWORD = 'pwd';
const I_XML_ATTR_KEY_IO = 'io';
const I_XML_ATTR_KEY_BY = 'by';
const I_XML_ATTR_VALUE_IO = 'both';
const I_XML_ATTR_KEY_OFFSET = 'offset';
const I_XML_ATTR_KEY_TOP = 'top';
Expand Down Expand Up @@ -161,9 +162,20 @@ const iXmlNodePgmOpen = (xname, xlib, xfunc, xerror) => iXmlNodeOpen(I_XML_NODE_
+ I_XML_NODE_CLOSE;
const iXmlNodePgmClose = () => I_XML_NODE_PGM_CLOSE;

const iXmlNodeParmOpen = xio => iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
+ iXmlAttrDefault(I_XML_ATTR_KEY_IO, xio, I_XML_ATTR_VALUE_OPTIONAL)
+ I_XML_NODE_CLOSE;
const iXmlNodeParmOpen = (opt) => {
if (!(opt && typeof opt === 'object')) {
return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
+ I_XML_NODE_CLOSE;
}

const io = (opt.io) ? iXmlAttrDefault(I_XML_ATTR_KEY_IO, opt.io, I_XML_ATTR_VALUE_OPTIONAL) : '';
const by = (opt.by) ? iXmlAttrDefault(I_XML_ATTR_KEY_BY, opt.by, I_XML_ATTR_VALUE_OPTIONAL) : '';

return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
+ io
+ by
+ I_XML_NODE_CLOSE;
};

const iXmlNodeParmClose = () => I_XML_NODE_PARM_CLOSE;

Expand Down
52 changes: 52 additions & 0 deletions test/unit/iPgmUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,58 @@ describe('iPgm Class Unit Tests', () => {

expect(pgm.toXML()).to.equal(expectedXML);
});

it('regular <parm> contains by=\'val\'', () => {
const pgm = new iPgm('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' });

pgm.addParam('', '1A', { by: 'val' });
pgm.addReturn('', '2A', { name: 'output' });

const lookAtXML = pgm.toXML();
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
});

it('data structure <parm> contains by=\'val\'', () => {
const pgm = new iPgm('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' });

const params = [
[0, '3s0'],
[0, '7s0', { name: 'ds_fld2' }],
];

pgm.addParam(params, { name: 'inds', by: 'val' });
pgm.addReturn('', '2A', { name: 'output' });

const lookAtXML = pgm.toXML();
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
});

it('regular <parm> contains by=\'val\', with io=\'both\'', () => {
const pgm = new iPgm('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' });

pgm.addParam('', '1A', { by: 'val', io: 'both' });
pgm.addReturn('', '2A', { name: 'output' });

const lookAtXML = pgm.toXML();
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
expect(lookAtXML).to.match(/<parm .*io='both'.*>/);
});

it('data structure <parm> contains by=\'val\', with io=\'both\'', () => {
const pgm = new iPgm('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' });

const params = [
[0, '3s0'],
[0, '7s0', { name: 'ds_fld2' }],
];

pgm.addParam(params, { name: 'inds', by: 'val', io: 'both' });
pgm.addReturn('', '2A', { name: 'output' });

const lookAtXML = pgm.toXML();
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
expect(lookAtXML).to.match(/<parm .*io='both'.*>/);
});
});


Expand Down