-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenTemplateValues.js
166 lines (148 loc) · 3.86 KB
/
tokenTemplateValues.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
'use strict';
// Require mixin.
const tokenTemplateValues = require('../lib/plugins/transform/tokenTemplateValues');
// Require a super class.
const superClass = require('../lib/transform/schemePunkTransform');
// Create an implementing class using mixin and super.
const Implemented = class implementer extends tokenTemplateValues(superClass) {
transform(value) {
this.value = super.transform(value);
}
};
// Options for testing with template path and object with no tokens.
const options = {
origin: '../../../test/helpers/templateLiteralTestOne.tpl',
named: false,
json: false,
unescape: false
};
// Options for testing with tokens and value.
const options2 = {
origin: '../../../test/helpers/templateLiteralTestTwo.tpl',
named: true,
json: false,
unescape: false,
tokens: {
name: 'name',
test: 'testKey2'
}
};
// Test case value.
const value = {
name: 'testName',
testKey: 'item0',
testKey2: 'item1'
};
// Options for testing with tokens and value.
const options3 = {
origin: '../../../test/helpers/templateLiteralTestThree.tpl',
named: true,
json: false,
unescape: false,
tokens: {
test: 'testKey2'
}
};
// Options for testing with tokens and value.
const options4 = {
origin: '../../../test/helpers/templateJson.tpl',
json: true,
unescape: true,
named: false,
tokens: {
test: 'testKey2'
}
};
// Options for testing with tokens and value.
const options5 = {
origin: '../../../test/helpers/templateFour.tpl',
json: false,
unescape: true,
named: false,
tokens: {
test: 'testKey2'
}
};
const value2 = 'testBoogie';
const testClass = new Implemented(options, {});
const testClass2 = new Implemented(options2, {});
const testClass3 = new Implemented(options3, {monkey: 'toofer'});
const testClass4 = new Implemented(options4, {monkey: 'toofer'});
const testClass5 = new Implemented(options5, {monkey: 'toofer'});
const testClass6 = new Implemented(options, {});
module.exports = {
tokenOnlyValues: (test) => {
test.expect(1);
testClass.transform(value);
test.deepEqual(
testClass.value,
'Dust template one name is testName, testKey is item0.'
);
test.done();
},
tokenOnlyTokens: (test) => {
test.expect(1);
testClass2.options.origin = 'test/helpers/templateLiteralTestTwo.tpl';
testClass2.transform(value);
test.deepEqual(
testClass2.value,
'Dust template one name is: testName, test has the value of testKey2: item1.'
);
test.done();
},
getTraceIndex: (test) => {
test.expect(1);
test.deepEqual(
testClass.getTraceIndex(1),
0
);
test.done();
},
holdOversWithTokens: (test) => {
test.expect(1);
testClass3.options.origin = 'test/helpers/templateLiteralTestThree.tpl';
testClass3.transform(value);
test.deepEqual(
testClass3.value,
'Dust template one name is: toofer, test has the value of testKey2: item1.'
);
test.done();
},
holdOversWithTokensJson: (test) => {
test.expect(1);
testClass4.options.origin = 'test/helpers/templateJson.tpl';
testClass4.transform(value);
test.deepEqual(
testClass4.value,
{
test: 'testName',
item: 'item1',
thing: [
'one',
'two'
]
}
);
test.done();
},
holdOversWithTokensUnescape: (test) => {
test.expect(1);
testClass5.options.origin = 'test/helpers/templateFour.tpl';
testClass5.transform(value);
test.deepEqual(
testClass5.value,
'Dust template "one" name is: testName, test has the value of \"testKey2: item1.' // eslint-disable-line no-useless-escape
);
test.done();
},
tokenSimpleValue: (test) => {
test.expect(1);
testClass6.options.origin = 'test/helpers/templateFive.tpl';
testClass.transform(value2);
test.deepEqual(
testClass.value,
'this is a testBoogie'
);
test.done();
},
};