-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathincrementVar.js
More file actions
88 lines (76 loc) · 2.61 KB
/
Copy pathincrementVar.js
File metadata and controls
88 lines (76 loc) · 2.61 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
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
const Lab = require('lab'),
lab = exports.lab = Lab.script(),
describe = lab.experiment,
it = lab.it,
specHelpers = require('../spec-helpers'),
testRunner = specHelpers.testRunner,
renderString = specHelpers.renderString;
describe('incrementVar helper', function() {
const context = {
value1: 12
};
const runTestCases = testRunner({context});
it('should throw an exception if the incrementVar key is not a string', function (done) {
renderString('{{incrementVar 1}}').catch(e => {
done();
});
});
it('should correctly increment', function(done) {
runTestCases([
{
input: "{{incrementVar 'data1'}}{{getVar 'data1'}} {{incrementVar 'data1'}}{{getVar 'data1'}} {{incrementVar 'data1'}}{{getVar 'data1'}}",
output: '00 11 22',
},
], done);
});
it('should correctly increment an existing variable', function(done) {
runTestCases([
{
input: "{{assignVar 'data1' value1}}{{getVar 'data1'}} {{incrementVar 'data1'}}",
output: '12 13',
},
{
input: "{{assignVar 'data1' 12}}{{getVar 'data1'}} {{incrementVar 'data1'}}",
output: '12 13',
},
{
input: "{{assignVar 'data1' -12}}{{getVar 'data1'}} {{incrementVar 'data1'}}",
output: '-12 -11',
},
], done);
});
it('should correctly overwrite an existing non-integer variable', function(done) {
runTestCases([
{
input: "{{assignVar 'data1' 'a'}}{{getVar 'data1'}} {{incrementVar 'data1'}}",
output: 'a 0',
},
], done);
});
it('should correctly return data accession object proto/constructor', function(done) {
runTestCases([
{
input: "{{incrementVar '__proto__'}}",
output: '0',
},
{
input: "{{incrementVar 'constructor'}}",
output: '0',
},
], done);
});
it('should throw error when max keys exceeded', function(done) {
const template = `{{#for 1 51}}{{incrementVar (multiConcat 'data' this.$index)}}{{/for}}`;
renderString(template).catch(_ => {
done();
});
});
it('should return undefined for non-existent key after clearing', function(done) {
runTestCases([
{
input: '{{incrementVar "newkey"}}',
output: '0',
},
], done);
});
});