cloudcmd/test/test.js
2014-01-09 16:13:25 +00:00

90 lines
3.8 KiB
JavaScript

(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 =
'<div class=path title="/etc/X11/">' +
'<span class="path-icon clear-cache" ' +
'id=clear-cache title="clear cache (Ctrl+D)">' +
'</span>' +
'<span class="path-icon refresh-icon" title="refresh (Ctrl+R)">'+
'<a href="/fs/etc/X11"></a></span>' +
'<span class=links>' +
'<a href="/fs" title="/">/</a>' +
'<a href="/fs/etc" title="/etc">' +
'etc' +
'</a>/X11/' +
'</span>' +
'</li>' +
'<li class=fm-header>' +
'<span class=mini-icon></span>' +
'<span class=name>name</span>' +
'<span class=size>size</span>' +
'<span class=owner>owner</span>' +
'<span class=mode>mode</span>' +
'</li>';
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');
}
});
})();