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
|
(function() {
'use strict';
var assert = chai.assert;
[{
filter: 'uc',
template: 'foo%{bar|uc}',
args: {
bar: 'foo',
},
expect: 'fooFOO',
}, {
filter: 'lc',
template: 'foo%{bar|lc}',
args: {
bar: 'FOO'
},
expect: 'foofoo',
}, {
filter: 'h',
template: '%{bar|h}',
args: {
bar: '<>&"\'',
},
expect: '<>&"'',
}, {
filter: 'u',
template: '%{bar|u}',
args: {
bar: 'asdf<>&"\' \u000f',
},
expect: 'asdf%3C%3E%26%22%27+%0F'
}, {
filter: 'json',
template: '%{bar|json}',
args: {
bar: {
true: true,
false: false,
null: null,
number: 5,
string: 'foo',
hash: { 'foo': 'bar' },
array: [0, 1],
},
},
expect: '{"true":true,"false":false,"null":null,"number":5,"string":"foo","hash":{"foo":"bar"},"array":[0,1]}',
}, {
filter: 'trim',
template: '%{bar|trim}',
args: { bar: ' \t\v\r\nfoo \t\v\r\n' },
expect: 'foo'
}, {
filter: 's',
template: 'one foo%{foo|s}, two bar%{bar|s}',
args: {
foo: 1,
bar: 2,
},
expect: 'one foo, two bars'
}, {
filter: 'length',
template: 'length of bar: %{bar|length}',
args: {
bar: [0, 1, 2],
},
expect: 'length of bar: 3'
}].forEach(function(row) {
it('default filter: ' + row.filter, function() {
assert.equal(Luigi.run(row.template, row.args), row.expect);
});
});
})();
|