(function(){ 'use strict'; var DIR = process.cwd() + '/', main = require(DIR + 'lib/server/main'), Util = main.util, CloudFunc = main.cloudfunc, HTMLDIR = main.HTMLDIR, files = main.files, TEMPLATEPATH = HTMLDIR + 'file.html', LINK_TEMPLATE_PATH = HTMLDIR + 'link.html', PATHTEMPLATE_PATH = HTMLDIR + 'path.html', EXPECT_PATH = DIR + 'test/expect.html', Files = [TEMPLATEPATH, PATHTEMPLATE_PATH, LINK_TEMPLATE_PATH, EXPECT_PATH], lJSON = { path : "/etc/X11/", files : [{ name: "applnk", size: "dir", uid : 0, mode: "40755" }, { name: "prefdm", size: 1328, uid : 0, mode: "100755" }] }, Expect = '
' + '' + '' + ''+ '' + '' + '/' + '' + 'etc' + '/X11/' + '' + '' + '
  • ' + '' + 'name' + 'size' + 'owner' + 'mode' + '
  • '; files.read(Files, 'utf-8', function(pErrors, pFiles){ if(pErrors) Util.log(pErrors); else{ console.time('CloudFunc.buildFromJSON'); var i, n, lTemplate = pFiles[TEMPLATEPATH], lPathTemplate = pFiles[PATHTEMPLATE_PATH], lLinkTemplate = pFiles[LINK_TEMPLATE_PATH], lExpect = pFiles[EXPECT_PATH], lResult = CloudFunc.buildFromJSON(lJSON, lTemplate, lPathTemplate, lLinkTemplate); Expect += lExpect; for (i = 0, n = Expect.length; i < n; i++) if (lResult[i] !== Expect[i]){ console.log('Error in char number: ' + i + '\n' + 'Expect: ' + Expect.substr(i) + '\n' + 'Result: ' + lResult.substr(i) ); break; } if (i === n) console.log('CloudFunc.buildFromJSON: OK'); console.timeEnd('CloudFunc.buildFromJSON'); } }); })();