From dab26ee2f02c81c1b64da2cde1c279c99dec30ca Mon Sep 17 00:00:00 2001 From: Dave Weissman Date: Wed, 13 Feb 2019 14:29:14 -0500 Subject: [PATCH 1/2] - ensure tag contains the 'by' attribute for val/ref. - it was previously being passed in the attribute. - this is similar to how the 'io' attribute is handled. - this allows service programs procedures that use the VALUE keyword to work with node Signed-off-by: Dave Weissman --- lib/itoolkit.js | 6 ++---- lib/ixml.js | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/itoolkit.js b/lib/itoolkit.js index 594b2135..d78c9634 100644 --- a/lib/itoolkit.js +++ b/lib/itoolkit.js @@ -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 or 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) diff --git a/lib/ixml.js b/lib/ixml.js index 0a93a318..face22ff 100644 --- a/lib/ixml.js +++ b/lib/ixml.js @@ -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"; @@ -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; } From bc1a26d257ec1d93161e3930e557210f1036d1d4 Mon Sep 17 00:00:00 2001 From: Dave Weissman Date: Fri, 22 Feb 2019 08:40:44 -0500 Subject: [PATCH 2/2] - consolidated test into iPgmUnit Signed-off-by: Dave Weissman --- test/unit/iPgmUnit.js | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/unit/iPgmUnit.js b/test/unit/iPgmUnit.js index 81d534b6..15508a89 100644 --- a/test/unit/iPgmUnit.js +++ b/test/unit/iPgmUnit.js @@ -133,6 +133,58 @@ describe('iPgm Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); }); + + it('regular 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(//); + }); + + it('data structure 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(//); + }); + + it('regular 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(//); + expect(lookAtXML).to.match(//); + }); + + it('data structure 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(//); + expect(lookAtXML).to.match(//); + }); });