From: himetani_cafe Date: Mon, 8 Feb 2016 01:13:05 +0000 (+0900) Subject: [Develop and Test] toExecArray() X-Git-Tag: v0.3.0p0040 X-Git-Url: http://git.osdn.net/view?p=eos%2Fzephyr.git;a=commitdiff_plain;h=98ad4dd37b1b954eee4e6dd377b29c77e3b5c169 [Develop and Test] toExecArray() modified: server/class/Eos.js modified: test/mocha/Eos.test.js --- diff --git a/server/class/Eos.js b/server/class/Eos.js index f1857d2..03519b2 100644 --- a/server/class/Eos.js +++ b/server/class/Eos.js @@ -235,6 +235,61 @@ function toExecString(command, options, workspaceId) { return execStr; } +/** + * toExecArray + * + * @param {fileId} + * @returns {string} + */ +function toExecArray(command, options, workspaceId) { + return new Promise(function(resolve, reject) { + var ocf = ocfReference[command]; // Array + var finalOptions = {}; + var ocfObj = {}; + ocf.forEach(function(o) { + ocfObj[o.option] = o; + }); + + // set default parameters + ocf.forEach(function(o) { + o.arg.forEach(function(arg) { + if(!(arg.initialValue === "") && arg.initialValue) { + if(!(finalOptions[o.option])) { + finalOptions[o.option] = []; + finalOptions[o.option].push(arg.initialValue); + } else { + finalOptions[o.option].push(arg.initialValue); + } + } + }); + }); + + getUUIDs(workspaceId) + .then(function(uuids) { + // set user setting parameters + options.forEach(function(o) { + var s = []; + var outRegExp = /out|append/; + o.arguments.forEach(function(arg, i) { + if(ocfObj[o.name].arg[i].formType === 'select') { + s.push(uuids[arg]); + } else { + s.push(arg); + } + }); + finalOptions[o.name] = s; + }); + var array = Object.keys(finalOptions).reduce(function(a,b) { + a.push(b); + finalOptions[b].forEach(function(v) { + a.push(v); + }); + return a; + },[]); + resolve(array); + }); + }); +} /** * execute @@ -299,7 +354,8 @@ var eos = { toExecString: toExecString, execute: execute, getFiles: getFiles, - getUUIDs: getUUIDs + getUUIDs: getUUIDs, + toExecArray: toExecArray } module.exports = { instance: eos }; diff --git a/test/mocha/Eos.test.js b/test/mocha/Eos.test.js index 16e2843..e189015 100644 --- a/test/mocha/Eos.test.js +++ b/test/mocha/Eos.test.js @@ -76,6 +76,17 @@ }); + var test2 = ` + /** + * 実行時文字列への変換 + * + * @param command + * @param options + * @returns {string} + * function toExecString(command, params) { + */ + `; + describe(test2, function() { it('should return true when all options is proper.', function() { var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ], "1f83f620-c1ed-11e5-9657-7942989daa00"); @@ -83,17 +94,33 @@ }); }); - var test2 = ` + var toExecArray = ` /** - * 実行時文字列への変換 + * 実行時配列への変換 * * @param command - * @param options * @returns {string} * function toExecString(command, params) { */ `; + describe(toExecArray, function() { + before(function() { + process.env.NODE_ENV = ''; + return db.init() + .then(function() { + return Promise.all([db.test1(), db.test2(), db.testRest()]) + }); + }); + + it('should be resolved with length 4', function() { + var command = testCommand.command; + var options = testCommand.options; + var workspace = testCommand.workspace; + return eos.toExecArray(command, options, '1f83f620-c1ed-11e5-9657-7942989daa00').should.be.eventually.length(16); + }); + + }); describe('execute', function() { before(function() {