Skip to content

Commit 98b8b3e

Browse files
authored
Merge pull request #43 from jkdavew/passByValue
Pass by value see issue #35
2 parents 89be160 + bc1a26d commit 98b8b3e

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

lib/itoolkit.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,9 @@ class iPgm {
347347
opt = type;
348348
else
349349
opt = options;
350+
350351
if(!inDs) { // In recursive mode, if it is an element in DS, then no <parm> or </parm> needed.
351-
if(opt && opt.io)
352-
this.xml += i_xml.iXmlNodeParmOpen(opt.io);
353-
else
354-
this.xml += i_xml.iXmlNodeParmOpen();
352+
this.xml += i_xml.iXmlNodeParmOpen(opt);
355353
}
356354
if(__getClass(data) == "Array") { // If it is a struct parameter, recursivly parse its children.
357355
if(opt)

lib/ixml.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const I_XML_ATTR_KEY_DB = "db";
107107
const I_XML_ATTR_KEY_USERID = "uid";
108108
const I_XML_ATTR_KEY_PASSWORD = "pwd";
109109
const I_XML_ATTR_KEY_IO = "io";
110+
const I_XML_ATTR_KEY_BY = "by";
110111
const I_XML_ATTR_VALUE_IO = "both";
111112
const I_XML_ATTR_KEY_OFFSET = "offset";
112113
const I_XML_ATTR_KEY_TOP = "top";
@@ -173,9 +174,21 @@ const iXmlNodePgmClose = () => {
173174
return I_XML_NODE_PGM_CLOSE;
174175
}
175176

176-
const iXmlNodeParmOpen = (xio) => {
177+
const iXmlNodeParmOpen = (opt) => {
178+
if (!(opt && typeof opt==='object')){
179+
return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
180+
+ I_XML_NODE_CLOSE;
181+
}
182+
183+
let opt_io=(opt.io) ? iXmlAttrDefault(I_XML_ATTR_KEY_IO,opt.io,I_XML_ATTR_VALUE_OPTIONAL) : "";
184+
let opt_by=(opt.by) ? iXmlAttrDefault(I_XML_ATTR_KEY_BY,opt.by,I_XML_ATTR_VALUE_OPTIONAL) : "";
185+
186+
delete opt.by;
187+
delete opt.io;
188+
177189
return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
178-
+ iXmlAttrDefault(I_XML_ATTR_KEY_IO,xio,I_XML_ATTR_VALUE_OPTIONAL)
190+
+ opt_io
191+
+ opt_by
179192
+ I_XML_NODE_CLOSE;
180193
}
181194

test/unit/iPgmUnit.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,58 @@ describe('iPgm Class Unit Tests', () => {
133133

134134
expect(pgm.toXML()).to.equal(expectedXML);
135135
});
136+
137+
it('regular <parm> contains by=\'val\'', () => {
138+
const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
139+
140+
pgm.addParam("", "1A", {by:"val"});
141+
pgm.addReturn("", "2A", {name:"output"});
142+
143+
let lookAtXML=pgm.toXML();
144+
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
145+
});
146+
147+
it('data structure <parm> contains by=\'val\'', () => {
148+
const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
149+
150+
const p_inds=[
151+
[0, "3s0"],
152+
[0, "7s0", {name:"ds_fld2"}]
153+
];
154+
155+
pgm.addParam(p_inds, {name:"inds", by:"val"});
156+
pgm.addReturn("", "2A", {name:"output"});
157+
158+
let lookAtXML=pgm.toXML();
159+
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
160+
});
161+
162+
it('regular <parm> contains by=\'val\', with io=\'both\'', () => {
163+
const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
164+
165+
pgm.addParam("", "1A", {by:"val", io:"both"});
166+
pgm.addReturn("", "2A", {name:"output"});
167+
168+
let lookAtXML=pgm.toXML();
169+
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
170+
expect(lookAtXML).to.match(/<parm .*io='both'.*>/);
171+
});
172+
173+
it('data structure <parm> contains by=\'val\', with io=\'both\'', () => {
174+
const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
175+
176+
const p_inds=[
177+
[0, "3s0"],
178+
[0, "7s0", {name:"ds_fld2"}]
179+
];
180+
181+
pgm.addParam(p_inds, {name:"inds", by:"val", io:"both"});
182+
pgm.addReturn("", "2A", {name:"output"});
183+
184+
let lookAtXML=pgm.toXML();
185+
expect(lookAtXML).to.match(/<parm .*by='val'.*>/);
186+
expect(lookAtXML).to.match(/<parm .*io='both'.*>/);
187+
});
136188
});
137189

138190

0 commit comments

Comments
 (0)