-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
136 lines (128 loc) · 3.62 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
suite('parameterize', function() {
var _ = require('lodash');
var debug = require('debug')('json-parameterization:test');
var assert = require('assert');
var parameterize = require('./');
test("Empty case", function() {
var input = {};
var params = {};
var output = {};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("String extraction", function() {
var input = {
key1: "{{'Hello World'}}",
key2: "{{ 'Hello World' }}",
key3: "{{\"Hello World\"}}",
key4: "{{ \"Hello World\" }}"
};
var params = {};
var output = {
key1: "Hello World",
key2: "Hello World",
key3: "Hello World",
key4: "Hello World"
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("Substitute strings in", function() {
var input = {
key1: "{{param1}}",
key2: "{{param2}}"
};
var params = {
param1: "PAR1",
param2: "PAR2",
};
var output = {
key1: "PAR1",
key2: "PAR2",
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("Substitute functions in", function() {
var input = {
key1: "{{param1}}",
key2: "{{param2}}"
};
var params = {
param1: function() { return "PAR1"; },
param2: function() { return "PAR" + (1 + 1); }
};
var output = {
key1: "PAR1",
key2: "PAR2",
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("Substitute objects in", function() {
var input = {
key1: "{{param1}}",
key2: "{{param2}}"
};
var params = {
param1: {my: "dictionary"},
param2: [1,2,3,4],
};
var output = {
key1: {my: "dictionary"},
key2: [1,2,3,4],
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("Substitute objects in key (doesn't work)", function() {
var input = {
'{{param1}}': "{{param2}}"
};
var params = {
param1: {my: "dictionary"},
param2: [1,2,3,4],
};
var output = {
"{{param1}}": [1,2,3,4],
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("Modify string", function() {
var input = {
key1: "{{'hello world' | to-upper}}",
key2: "{{ 'hello world' | to-upper | to-lower }}",
key3: "{{ hi-var | to-upper | to-lower }}",
};
var params = {
'to-upper': function(text) {
return text.toUpperCase();
},
'to-lower': function(text) {
return text.toLowerCase();
},
'hi-var': 'hello World'
};
var output = {
key1: "HELLO WORLD",
key2: "hello world",
key3: "hello world"
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
test("Substitute into a key", function() {
var input = {
"{{prefix}}Key": "Value"
};
var params = {
'prefix': 'Some'
};
var output = {
SomeKey: 'Value'
};
assert.deepEqual(parameterize(input, params), output,
"Predicted output wasn't matched!");
});
});