test(cloudfunc) buildFromJSON

This commit is contained in:
coderaiser 2014-05-24 13:27:27 -04:00
parent eefdd2ffa1
commit 5e25df43a9
2 changed files with 28 additions and 17 deletions

View file

@ -4,19 +4,19 @@
<span class="size reduce-text">size</span>
<span class="owner reduce-text">owner</span>
<span class="mode reduce-text">mode</span>
</div><ul data-name="js-files" class="files"><li draggable="true" class="">
</div><ul data-name="js-files" class="files"><li draggable="true" data-name="js-file-.." class="">
<span class="mini-icon directory"></span>
<span class="name reduce-text"><a href="/fs/etc" title=".." draggable="true">..</a></span>
<span class="size reduce-text">&lt;dir&gt;</span>
<span class="owner reduce-text">.</span>
<span class="mode reduce-text">--- --- ---</span>
</li><li draggable="true" class="">
</li><li draggable="true" data-name="js-file-applnk" class="">
<span class="mini-icon directory"></span>
<span class="name reduce-text"><a href="/fs/etc/X11/applnk" title="applnk" draggable="true">applnk</a></span>
<span class="size reduce-text">&lt;dir&gt;</span>
<span class="owner reduce-text">root</span>
<span class="mode reduce-text">rwx r-x r-x</span>
</li><li draggable="true" class="">
</li><li draggable="true" data-name="js-file-prefdm" class="">
<span class="mini-icon text-file"></span>
<span class="name reduce-text"><a href="/fs/etc/X11/prefdm" title="prefdm" target="_blank" draggable="true">prefdm</a></span>
<span class="size reduce-text">1.30kb</span>

View file

@ -32,7 +32,6 @@
}]
},
Expect =
'<div data-name="js-path" class="reduce-text" title="/etc/X11/">' +
'<span data-name="js-clear-storage" class="path-icon clear-storage" ' +
@ -48,10 +47,9 @@
'</span>' +
'</div>';
exports.check = function() {
files.read(Files, 'utf-8', function(errors, files) {
var i, n, template, pathTemplate, linkTemplate, expect, result;
var isNotOk, i, template, pathTemplate, linkTemplate, expect, result;
if (errors)
Util.log(errors);
@ -63,23 +61,36 @@
linkTemplate = files[LINK_TEMPLATE_PATH];
expect = files[EXPECT_PATH];
result = CloudFunc.buildFromJSON(JSON_FILES, template, pathTemplate, linkTemplate);
result = CloudFunc.buildFromJSON({
data: JSON_FILES,
template: {
file: template,
path: pathTemplate,
link: linkTemplate
}
});
Expect += expect;
n = Expect.length;
for (i = 0; i < n; i++)
if (result[i] !== Expect[i]) {
Util.log('Error in char number: ' + i + '\n' +
'Expect: ' + Expect.substr(i) + '\n' +
'Result: ' + result.substr(i) );
break;
}
isNotOk = Util.slice(Expect).some(function(item, number) {
var ret = result[number] !== item;
if (i === n)
console.log('CloudFunc.buildFromJSON: OK');
if (ret)
i = number;
return ret;
});
Util.timeEnd('CloudFunc.buildFromJSON');
if (isNotOk) {
console.log('Error in char number: ' + i + '\n' +
'Expect: ' + Expect.substr(i) + '\n' +
'Result: ' + result.substr(i) );
throw('buildFromJSON: Not OK');
}
}
});
};