-
Notifications
You must be signed in to change notification settings - Fork 15
/
string_test.js
88 lines (75 loc) · 1.43 KB
/
string_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
suite('string', function() {
var assert = require('assert');
var subject = require('./string');
function verify(title, input, output) {
test(title, function() {
var result = subject.apply(subject, input);
assert.equal(output, result);
});
}
verify('no token', ['woot', {}], 'woot');
verify(
'token no value',
['{{token}}', {}],
'{{token}}'
);
verify(
'one token',
['{{token}}', { token: 'v' }],
'v'
);
verify(
'nested token',
['{{foo.bar.baz}}', { foo: { bar: { baz: 'baz' } } }],
'baz'
);
verify(
'nested token no value',
['{{foo.bar}}', { foo: {} }],
'{{foo.bar}}'
);
verify(
'nested token false value',
['{{foo.bar}}', { foo: { bar: false} }],
'false'
);
verify(
'replace in the middle of string',
[
'foo bar {{baz}} qux',
{ baz: 'what?' }
],
'foo bar what? qux'
);
verify(
'multiple replacements',
[
'{{a}} {{woot}} bar baz {{yeah}}',
{ a: 'foo', yeah: true }
],
'foo {{woot}} bar baz true'
);
verify(
'object notation for non-object',
[
'{{a.b.c}} what',
{ a: { b: 'iam b' } }
],
'{{a.b.c}} what'
);
verify(
'dots as key names',
['{{woot.bar.baz}}', { 'woot.bar.baz': 'yup' }],
'yup'
);
verify(
'array view',
[
'do what {{fields.0}}',
{
fields: ['first']
}
],
'do what first'
);
});