diff --git a/index.js b/index.js index c0adedb..4f6fc9b 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,26 @@ var object = {}; + +// Regroupe les fonctions liées aux chemins +object.paths = {}; + +/** + * Initialise les chemins d'un module R&D + * @param {Object} paths Liste des chemins sous forme d'objet JSON (clé => valeur) + * @param {String} root Racine du module + * @return {Object} L'objet contenant les chemins initialisés + */ +object.paths.init = function(paths, root) { + var result = {}; + for (var k in paths) { + if (paths.hasOwnProperty(k) && typeof paths[k] !== 'function') { + result[k] = path.join(root, paths[k]); + } + } + return result; +}; + // Regroupe les fonctions liées aux fichiers dans la chaine LoadIstex object.files = {}; @@ -174,6 +194,6 @@ result += keys[i] + '=' + encodeURIComponent(parameters[keys[i]]) + ((i < keys.length - 1) ? '&' : ''); } return url + result; -} +}; module.exports = object; \ No newline at end of file diff --git a/test/dataset/in/test.paths.json b/test/dataset/in/test.paths.json new file mode 100644 index 0000000..3b7f5ac --- /dev/null +++ b/test/dataset/in/test.paths.json @@ -0,0 +1,14 @@ +{ + "init": [{ + "label": "Devrait créer le chemin suivant : /root/my/absolute/path/", + "arguments": { + "paths": { + "test": "./my/absolute/path/" + }, + "root": "/root/" + }, + "result": { + "equal": "/root/my/absolute/path/" + } + }] +} \ No newline at end of file diff --git a/test/run.js b/test/run.js index f7de884..0154d51 100644 --- a/test/run.js +++ b/test/run.js @@ -10,14 +10,18 @@ // Données de test var docObject = require('./dataset/in/docObject.sample.json'), dataset = { - "files": require('./dataset/in/test.files.json'), - "directories": require('./dataset/in/test.directories.json'), - "XML": require('./dataset/in/test.XML.json'), - "URL": require('./dataset/in/test.URL.json') -}; + "paths": require('./dataset/in/test.paths.json'), + "files": require('./dataset/in/test.files.json'), + "directories": require('./dataset/in/test.directories.json'), + "XML": require('./dataset/in/test.XML.json'), + "URL": require('./dataset/in/test.URL.json') + }; // Mapping indiquant quelle fonction de test et quelles données utiliser pour chaque fonction var wrapper = { + "paths": { + "init": testOf_pathsInit + }, "files": { "selectAll": testOf_fileRepresentation, "select": testOf_fileRepresentation, @@ -28,15 +32,18 @@ }, "XML": { "load": testOf_xmlLoad, - "select": testOf_xmlSelection + "select": testOf_xmlSelect }, "URL": { - "addParameters": testOf_addParameters + "addParameters": testOf_urlAddParameters } }; /** * Test de chaques fonctions de : + * - myObject.paths. + * - init() + * * - myObject.files. * - selectAll() * - select() @@ -46,6 +53,9 @@ * - myObject.XML. * - load() * - select() + * + * - myObject.URL. + * - addParameters() */ TU.start({ description: pkg.name + '/index.js', @@ -57,6 +67,15 @@ /** * Fonction de test à appliquée pour : + * - myObject.paths.init() + */ +function testOf_pathsInit(fn, item, cb) { + var result = fn(item.arguments.paths, item.arguments.root); + return cb(result.test); +} + +/** + * Fonction de test à appliquée pour : * - myObject.XML.load() */ function testOf_xmlLoad(fn, item, cb) { @@ -79,7 +98,7 @@ * Fonction de test à appliquée pour : * - myObject.XML.select() */ -function testOf_xmlSelection(fn, item, cb) { +function testOf_xmlSelect(fn, item, cb) { var xmlStr = fs.readFileSync(path.join(__dirname, item.path), 'utf-8'); var jsonObject = myObject.XML.load(xmlStr); return cb(fn(item.arguments.selector, jsonObject)[0]); @@ -89,7 +108,7 @@ * Fonction de test à appliquée pour : * - myObject.URL.addParameters() */ -function testOf_addParameters(fn, item, cb) { +function testOf_urlAddParameters(fn, item, cb) { return cb(fn(item.arguments.url, item.arguments.parameters)); }