forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (49 loc) · 1.37 KB
/
Copy pathindex.js
File metadata and controls
54 lines (49 loc) · 1.37 KB
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
var test = require('../util/test')(__filename);
var template = require('../../packages/string-template');
test('variables replaced by simple data', function(t) {
t.plan(1);
var data = {a: 3, b: 4};
var result = template('this is {{a}} and this is {{b}}', data);
t.equal(result, 'this is 3 and this is 4');
t.end();
});
test('variable used more than once', function(t) {
t.plan(1);
var data = {a: 3, b: 4};
var result = template(
'this is {{a}} and so is {{a}} and this is {{b}}',
data
);
t.equal(result, 'this is 3 and so is 3 and this is 4');
t.end();
});
test('using nested variables', function(t) {
t.plan(1);
var data = {
a: {
aa: {
aaa: 'apple',
bbb: 'pear',
},
bb: 'orange',
},
b: 'plum',
};
var str =
'2 {{a.aa.aaa}}s, a {{a.aa.bbb}}, 3 {{a.bb}}s and a {{b}}. Yes 1 {{a.aa.bbb}}.';
var result = '2 apples, a pear, 3 oranges and a plum. Yes 1 pear.';
t.equal(template(str, data), result);
t.end();
});
test('overlapping variables resolve', function(t) {
var str = 'the answer is {{a{{b}}hmmm}}';
var data = {a: 3, 'a{{b': 4};
t.equal(template(str, data), 'the answer is 4hmmm}}');
t.end();
});
test('unresolved variables return empty strings', function(t) {
var str = 'a {{a}}, b {{b}}, c {{c}}';
var data = {a: 3, c: 4};
t.equal(template(str, data), 'a 3, b , c 4');
t.end();
});