Skip to content

Commit

Permalink
Merge pull request #43 from jkdavew/passByValue
Browse files Browse the repository at this point in the history
Pass by value see issue #35
  • Loading branch information
abmusse authored Mar 19, 2019
2 parents 89be160 + bc1a26d commit 98b8b3e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/itoolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,9 @@ class iPgm {
opt = type;
else
opt = options;

if(!inDs) { // In recursive mode, if it is an element in DS, then no <parm> or </parm> needed.
if(opt && opt.io)
this.xml += i_xml.iXmlNodeParmOpen(opt.io);
else
this.xml += i_xml.iXmlNodeParmOpen();
this.xml += i_xml.iXmlNodeParmOpen(opt);
}
if(__getClass(data) == "Array") { // If it is a struct parameter, recursivly parse its children.
if(opt)
Expand Down
17 changes: 15 additions & 2 deletions lib/ixml.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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 @@ -173,9 +174,21 @@ const iXmlNodePgmClose = () => {
return I_XML_NODE_PGM_CLOSE;
}

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

let opt_io=(opt.io) ? iXmlAttrDefault(I_XML_ATTR_KEY_IO,opt.io,I_XML_ATTR_VALUE_OPTIONAL) : "";
let opt_by=(opt.by) ? iXmlAttrDefault(I_XML_ATTR_KEY_BY,opt.by,I_XML_ATTR_VALUE_OPTIONAL) : "";

delete opt.by;
delete opt.io;

return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
+ iXmlAttrDefault(I_XML_ATTR_KEY_IO,xio,I_XML_ATTR_VALUE_OPTIONAL)
+ opt_io
+ opt_by
+ I_XML_NODE_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"});

let 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 p_inds=[
[0, "3s0"],
[0, "7s0", {name:"ds_fld2"}]
];

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

let 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"});

let 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 p_inds=[
[0, "3s0"],
[0, "7s0", {name:"ds_fld2"}]
];

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

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


Expand Down

0 comments on commit 98b8b3e

Please sign in to comment.