This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
forked from raycmorgan/Mu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
64 lines (54 loc) · 1.54 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var sys = require('sys'),
fs = require('fs'),
assert = require('assert');
var Mu = require('./lib/mu');
Mu.templateRoot = "./examples";
[
'comments',
'complex',
'deep_partial',
'delimiters',
'error_not_found',
'escaped',
'hash_instead_of_array',
'inverted',
'partial',
'recursion_with_same_names',
'reuse_of_enumerables',
'simple',
'two_in_a_row',
'unescaped',
].forEach(function (name) {
try {
var js = fs.readFileSync('./examples/' + name + '.js');
var text = fs.readFileSync('./examples/' + name + '.txt');
js = eval('(' + js + ')');
Mu.compile(name + '.html', function (err, compiled) {
try {
var buffer = '';
compiled(js).addListener('data', function (c) { buffer += c; })
.addListener('end', function () {
assert.equal(buffer, text);
sys.puts(name + ' passed');
});
} catch (e) {
sys.puts("Error in template (render time): " + name);
sys.puts(e.stack);
}
});
} catch (e) {
sys.puts("Error in template (compile time): " + name);
sys.puts(e.stack);
}
});
(function () {
var buffer = '';
var tmpl = "Hello {{> part}}";
var partials = {part: "World"};
var compiled = Mu.compileText(tmpl, partials);
compiled({}).addListener('data', function (c) { buffer += c; })
.addListener('end', function () {
assert.equal(buffer, "Hello World");
sys.puts('compileText passed');
});
}());