react 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -13
- package/{lib → dsl}/chain.js +5 -3
- package/{lib → dsl}/fstr.js +17 -6
- package/{lib → dsl}/pcode.js +19 -8
- package/examples/chain-events1.js +3 -3
- package/examples/chain1.js +2 -2
- package/examples/default-events1.js +2 -2
- package/examples/fstr-events1.js +4 -3
- package/examples/fstr1.js +3 -2
- package/examples/pcode1.js +2 -2
- package/lib/base-task.js +1 -0
- package/lib/cb-task.js +14 -1
- package/lib/core.js +36 -12
- package/lib/dsl.js +16 -5
- package/lib/event-manager.js +16 -4
- package/lib/finalcb-first-task.js +9 -6
- package/lib/finalcb-task.js +9 -6
- package/lib/input-parser.js +7 -3
- package/lib/parse.js +6 -3
- package/lib/promise-task.js +89 -0
- package/lib/ret-task.js +1 -1
- package/lib/task.js +23 -19
- package/lib/validate.js +14 -5
- package/lib/vcon.js +8 -3
- package/lib/when-task.js +81 -0
- package/package.json +4 -2
- package/promise-resolve.js +35 -0
- package/react.js +0 -4
- package/test/core-deferred.test.js +134 -0
- package/test/core-promised.test.js +132 -0
- package/test/core-when.test.js +84 -0
- package/test/core.test.js +63 -4
- package/test/dsl.test.js +70 -5
- package/test/{chain.test.js → dsl/chain.test.js} +84 -1
- package/test/{fstr.test.js → dsl/fstr.test.js} +13 -1
- package/test/{pcode.test.js → dsl/pcode.test.js} +136 -1
- package/test/exec-options.test.js +2 -1
- package/test/finalcb-task.test.js +6 -5
- package/test/input-parser.test.js +10 -6
- package/test/module-use.test.js +2 -190
- package/test/promise-auto-resolve.test.js +51 -0
- package/test/validate.test.js +30 -1
- package/test/vcon.test.js +13 -0
- package/oldExamples/analyze.js +0 -29
- package/oldExamples/analyze2.js +0 -29
- package/oldExamples/example10-dsl.js +0 -63
- package/oldExamples/example11.js +0 -62
- package/oldExamples/example12.js +0 -63
- package/oldExamples/example13.js +0 -63
- package/oldExamples/example14.js +0 -63
- package/oldExamples/example15.js +0 -75
- package/oldExamples/example6-ast.js +0 -47
- package/oldExamples/example6-dsl.js +0 -49
- package/oldExamples/example8-ast.js +0 -55
- package/oldExamples/example8-dsl.js +0 -53
- package/oldExamples/example9-ast.js +0 -58
- package/oldExamples/example9-dsl.js +0 -57
- package/oldExamples/function-str-ex1.js +0 -33
- package/oldExamples/function-str-ex2.js +0 -67
- package/oldExamples/trait1.js +0 -41
- package/oldExamples/trait2.js +0 -44
|
@@ -20,7 +20,7 @@ test('execOptions as first param', function (t) {
|
|
|
20
20
|
|
|
21
21
|
var execOptions = {
|
|
22
22
|
reactExecOptions: true,
|
|
23
|
-
outputStyle: '
|
|
23
|
+
outputStyle: 'cb'
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
fn(execOptions, 2, 3, function (err, c) {
|
|
@@ -30,3 +30,4 @@ test('execOptions as first param', function (t) {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var test = require('tap').test;
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var tskutil = require('../lib/task.js');
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
test('undefined cb throws exception', function (t) {
|
|
8
9
|
var fn = function () {
|
|
9
|
-
var finalTask =
|
|
10
|
+
var finalTask = tskutil.createOutTask({}, undefined);
|
|
10
11
|
};
|
|
11
12
|
t.throws(fn, new Error('callback is not a function'));
|
|
12
13
|
t.end();
|
|
@@ -14,7 +15,7 @@ test('undefined cb throws exception', function (t) {
|
|
|
14
15
|
|
|
15
16
|
test('null cb throws exception', function (t) {
|
|
16
17
|
var fn = function () {
|
|
17
|
-
var finalTask =
|
|
18
|
+
var finalTask = tskutil.createOutTask({}, null);
|
|
18
19
|
};
|
|
19
20
|
t.throws(fn, new Error('callback is not a function'));
|
|
20
21
|
t.end();
|
|
@@ -22,7 +23,7 @@ test('null cb throws exception', function (t) {
|
|
|
22
23
|
|
|
23
24
|
test('cb needs to be a function or throws exception', function (t) {
|
|
24
25
|
var fn = function () {
|
|
25
|
-
var finalTask =
|
|
26
|
+
var finalTask = tskutil.createOutTask({}, 'foo');
|
|
26
27
|
};
|
|
27
28
|
t.throws(fn, new Error('callback is not a function'));
|
|
28
29
|
t.end();
|
|
@@ -30,7 +31,7 @@ test('cb needs to be a function or throws exception', function (t) {
|
|
|
30
31
|
|
|
31
32
|
test('valid fn creates outTask', function (t) {
|
|
32
33
|
function foo() { }
|
|
33
|
-
var finalTask =
|
|
34
|
+
var finalTask = tskutil.createOutTask({ a: ['bar', 'baz']}, foo);
|
|
34
35
|
t.equal(finalTask.f, foo);
|
|
35
36
|
t.deepEqual(finalTask.a, ['bar', 'baz']);
|
|
36
37
|
t.end();
|
|
@@ -5,8 +5,9 @@ var test = require('tap').test;
|
|
|
5
5
|
var inputParser = require('../lib/input-parser.js');
|
|
6
6
|
|
|
7
7
|
test('parser parses input args', function (t) {
|
|
8
|
+
function myCb() { }
|
|
8
9
|
var ast = { inParams: ['a', 'b'] };
|
|
9
|
-
var parsedInput = inputParser([10, 20], ast);
|
|
10
|
+
var parsedInput = inputParser([10, 20, myCb], ast);
|
|
10
11
|
t.deepEqual(parsedInput.args, [10, 20]);
|
|
11
12
|
t.deepEqual(parsedInput.options, inputParser.defaultExecOptions);
|
|
12
13
|
t.end();
|
|
@@ -43,20 +44,23 @@ test('parser parses input args with extra args', function (t) {
|
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
test('parser pulls react exec option off arg list', function (t) {
|
|
47
|
+
function myCb() { }
|
|
46
48
|
var ast = { inParams: ['a', 'b'] };
|
|
47
49
|
var execOptions = { reactExecOptions: true, foo: 10 };
|
|
48
|
-
var parsedInput = inputParser([execOptions, 10, 20], ast);
|
|
50
|
+
var parsedInput = inputParser([execOptions, 10, 20, myCb], ast);
|
|
49
51
|
t.deepEqual(parsedInput.args, [10, 20]);
|
|
50
|
-
t.deepEqual(parsedInput.options, { reactExecOptions: true, outputStyle: '
|
|
52
|
+
t.deepEqual(parsedInput.options, { reactExecOptions: true, outputStyle: 'cb', foo: 10 });
|
|
51
53
|
t.end();
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
test('parser pulls react exec options off arg list and merges from left to right', function (t) {
|
|
57
|
+
function myCb() { }
|
|
55
58
|
var ast = { inParams: ['a', 'b'] };
|
|
56
59
|
var execOptions = { reactExecOptions: true, foo: 12, bar: 24 };
|
|
57
60
|
var execOptions2 = { reactExecOptions: true, bar: 36, baz: 'hello' };
|
|
58
|
-
var parsedInput = inputParser([execOptions, execOptions2, 10, 20], ast);
|
|
61
|
+
var parsedInput = inputParser([execOptions, execOptions2, 10, 20, myCb], ast);
|
|
59
62
|
t.deepEqual(parsedInput.args, [10, 20]);
|
|
60
|
-
t.deepEqual(parsedInput.options, { reactExecOptions: true, outputStyle: '
|
|
63
|
+
t.deepEqual(parsedInput.options, { reactExecOptions: true, outputStyle: 'cb', foo: 12, bar: 36, baz: 'hello' });
|
|
61
64
|
t.end();
|
|
62
|
-
});
|
|
65
|
+
});
|
|
66
|
+
|
package/test/module-use.test.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var test = require('tap').test;
|
|
4
4
|
var BaseTask = require('../lib/base-task.js');
|
|
5
5
|
|
|
6
|
-
var react = require('../react');
|
|
6
|
+
var react = require('../'); // require('react');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
@example
|
|
@@ -35,9 +35,7 @@ var react = require('../react');
|
|
|
35
35
|
test('module exports an function object with properties', function (t) {
|
|
36
36
|
t.type(react, 'function', 'is a core constructor and default dsl function');
|
|
37
37
|
t.type(react.options, 'object', 'has property for global react options');
|
|
38
|
-
t.type(react.
|
|
39
|
-
t.type(react.pcodeDefine, 'function', 'has fn property for using pcode dsl');
|
|
40
|
-
t.type(react.chainDefine, 'function', 'has fn property for chain define');
|
|
38
|
+
t.type(react.events, 'object', 'has global react event manager');
|
|
41
39
|
t.end();
|
|
42
40
|
});
|
|
43
41
|
|
|
@@ -125,193 +123,7 @@ test('use react.selectFirst() default DSL with events', function (t) {
|
|
|
125
123
|
});
|
|
126
124
|
|
|
127
125
|
|
|
128
|
-
test('use pcodeDefine from module', function (t) {
|
|
129
|
-
t.plan(3);
|
|
130
|
-
function multiply(a, b, cb) { cb(null, a * b); }
|
|
131
|
-
function add(a, b, cb) { cb(null, a + b); }
|
|
132
|
-
var locals = { multiply: multiply, add: add };
|
|
133
|
-
var fn = react.pcodeDefine('a, b, cb', [
|
|
134
|
-
'm := multiply(a, b)',
|
|
135
|
-
's := add(m, a)',
|
|
136
|
-
'cb(err, m, s)'
|
|
137
|
-
], locals);
|
|
138
|
-
|
|
139
|
-
fn(2, 3, function (err, m, s) {
|
|
140
|
-
t.deepEqual(err, null, 'should not be any error');
|
|
141
|
-
t.equal(m, 6);
|
|
142
|
-
t.equal(s, 8);
|
|
143
|
-
t.end();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('use pcodeDefine with events', function (t) {
|
|
148
|
-
t.plan(8);
|
|
149
|
-
function multiply(a, b, cb) { cb(null, a * b); }
|
|
150
|
-
function add(a, b, cb) { cb(null, a + b); }
|
|
151
|
-
|
|
152
|
-
var events = [];
|
|
153
|
-
function accumEvents(task) {
|
|
154
|
-
events.push(task);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
var locals = { multiply: multiply, add: add };
|
|
158
|
-
var fn = react.pcodeDefine('a, b, cb', [
|
|
159
|
-
'm := multiply(a, b)',
|
|
160
|
-
's := add(m, a)',
|
|
161
|
-
'cb(err, m, s)'
|
|
162
|
-
], locals);
|
|
163
|
-
|
|
164
|
-
fn.events.on('task.complete', accumEvents);
|
|
165
|
-
|
|
166
|
-
fn(2, 3, function (err, m, s) {
|
|
167
|
-
t.deepEqual(err, null, 'should not be any error');
|
|
168
|
-
t.equal(m, 6);
|
|
169
|
-
t.equal(s, 8);
|
|
170
|
-
t.equal(events.length, 2, 'should have seen two task compl events');
|
|
171
|
-
t.equal(events[0].name, 'multiply', 'name matches');
|
|
172
|
-
t.deepEqual(events[0].results, [6], 'results match');
|
|
173
|
-
t.equal(events[1].name, 'add', 'name matches');
|
|
174
|
-
t.deepEqual(events[1].results, [8], 'results match');
|
|
175
|
-
t.end();
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test('use pcodeDefine.selectFirst with events', function (t) {
|
|
180
|
-
t.plan(7);
|
|
181
|
-
function noSuccess(a, b, cb) {
|
|
182
|
-
setTimeout(function () { cb(null); }, 100); // returns undefined result
|
|
183
|
-
}
|
|
184
|
-
function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
|
|
185
|
-
function add(a, b, cb) { cb(null, a + b); }
|
|
186
|
-
|
|
187
|
-
var events = [];
|
|
188
|
-
function accumEvents(task) {
|
|
189
|
-
events.push(task);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var locals = { noSuccess: noSuccess, noSuccessNull: noSuccessNull, add: add };
|
|
193
|
-
var fn = react.pcodeDefine.selectFirst('a, b, cb', [
|
|
194
|
-
'c := noSuccess(a, b)',
|
|
195
|
-
'c := noSuccessNull(a, b)',
|
|
196
|
-
'c := add(a, b)',
|
|
197
|
-
'c := noSuccess(a, b)',
|
|
198
|
-
'cb(err, c)'
|
|
199
|
-
], locals);
|
|
200
|
-
|
|
201
|
-
fn.events.on('task.complete', accumEvents);
|
|
202
|
-
|
|
203
|
-
fn(2, 3, function (err, c) {
|
|
204
|
-
t.deepEqual(err, null, 'should not be any error');
|
|
205
|
-
t.equal(c, 5);
|
|
206
|
-
t.equal(events.length, 3, 'should have seen two task compl events');
|
|
207
|
-
t.equal(events[0].name, 'noSuccess', 'name matches');
|
|
208
|
-
t.equal(events[1].name, 'noSuccessNull', 'name matches');
|
|
209
|
-
t.equal(events[2].name, 'add', 'name matches');
|
|
210
|
-
t.deepEqual(events[2].results, [5], 'results match');
|
|
211
|
-
t.end();
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test('use pcodeDefine events emit to global emitter', function (t) {
|
|
216
|
-
t.plan(8);
|
|
217
|
-
function multiply(a, b, cb) { cb(null, a * b); }
|
|
218
|
-
function add(a, b, cb) { cb(null, a + b); }
|
|
219
126
|
|
|
220
|
-
var events = [];
|
|
221
|
-
function accumEvents(task) {
|
|
222
|
-
events.push(task);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
var locals = { multiply: multiply, add: add };
|
|
226
|
-
var fn = react.pcodeDefine('a, b, cb', [
|
|
227
|
-
'm := multiply(a, b)',
|
|
228
|
-
's := add(m, a)',
|
|
229
|
-
'cb(err, m, s)'
|
|
230
|
-
], locals);
|
|
231
|
-
|
|
232
|
-
react.events.on('task.complete', accumEvents); // the global react emitter
|
|
233
|
-
|
|
234
|
-
fn(2, 3, function (err, m, s) {
|
|
235
|
-
t.deepEqual(err, null, 'should not be any error');
|
|
236
|
-
t.equal(m, 6);
|
|
237
|
-
t.equal(s, 8);
|
|
238
|
-
t.equal(events.length, 2, 'should have seen two task compl events');
|
|
239
|
-
t.equal(events[0].name, 'multiply', 'name matches');
|
|
240
|
-
t.deepEqual(events[0].results, [6], 'results match');
|
|
241
|
-
t.equal(events[1].name, 'add', 'name matches');
|
|
242
|
-
t.deepEqual(events[1].results, [8], 'results match');
|
|
243
|
-
t.end();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
test('chainDefine use', function (t) {
|
|
250
|
-
t.plan(8);
|
|
251
|
-
function multiply(a, b, cb) { cb(null, a * b); }
|
|
252
|
-
function add(a, b, cb) { cb(null, a + b); }
|
|
253
|
-
|
|
254
|
-
var events = [];
|
|
255
|
-
function accumEvents(task) {
|
|
256
|
-
events.push(task);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
var fn = react.chainDefine()
|
|
260
|
-
.in('a', 'b', 'cb')
|
|
261
|
-
.out('err', 'm', 's')
|
|
262
|
-
.async(multiply).in('a', 'b', 'cb').out('err', 'm')
|
|
263
|
-
.async(add).in('m', 'a', 'cb').out('err', 's')
|
|
264
|
-
.end();
|
|
265
|
-
|
|
266
|
-
fn.events.on('task.complete', accumEvents);
|
|
267
|
-
|
|
268
|
-
fn(2, 3, function (err, m, s) {
|
|
269
|
-
t.deepEqual(err, null, 'should not be any error');
|
|
270
|
-
t.equal(m, 6);
|
|
271
|
-
t.equal(s, 8);
|
|
272
|
-
t.equal(events.length, 2, 'should have seen two task compl events');
|
|
273
|
-
t.equal(events[0].name, 'multiply', 'name matches');
|
|
274
|
-
t.deepEqual(events[0].results, [6], 'results match');
|
|
275
|
-
t.equal(events[1].name, 'add', 'name matches');
|
|
276
|
-
t.deepEqual(events[1].results, [8], 'results match');
|
|
277
|
-
t.end();
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
127
|
|
|
281
|
-
test('use chainDefine selectFirst with events', function (t) {
|
|
282
|
-
t.plan(7);
|
|
283
|
-
function noSuccess(a, b, cb) {
|
|
284
|
-
setTimeout(function () { cb(null); }, 100); // returns undefined result
|
|
285
|
-
}
|
|
286
|
-
function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
|
|
287
|
-
function add(a, b, cb) { cb(null, a + b); }
|
|
288
|
-
|
|
289
|
-
var events = [];
|
|
290
|
-
function accumEvents(task) {
|
|
291
|
-
events.push(task);
|
|
292
|
-
}
|
|
293
128
|
|
|
294
|
-
var fn = react.chainDefine()
|
|
295
|
-
.selectFirst()
|
|
296
|
-
.in('a', 'b', 'cb')
|
|
297
|
-
.out('err', 'c')
|
|
298
|
-
.async(noSuccess).in('a', 'b', 'cb').out('err', 'c')
|
|
299
|
-
.async(noSuccessNull).in('a', 'b', 'cb').out('err', 'c')
|
|
300
|
-
.async(add).in('a', 'b', 'cb').out('err', 'c')
|
|
301
|
-
.async(noSuccess).in('a', 'b', 'cb').out('err', 'c')
|
|
302
|
-
.end();
|
|
303
|
-
|
|
304
|
-
fn.events.on('task.complete', accumEvents);
|
|
305
|
-
|
|
306
|
-
fn(2, 3, function (err, c) {
|
|
307
|
-
t.deepEqual(err, null, 'should not be any error');
|
|
308
|
-
t.equal(c, 5);
|
|
309
|
-
t.equal(events.length, 3, 'should have seen two task compl events');
|
|
310
|
-
t.equal(events[0].name, 'noSuccess', 'name matches');
|
|
311
|
-
t.equal(events[1].name, 'noSuccessNull', 'name matches');
|
|
312
|
-
t.equal(events[2].name, 'add', 'name matches');
|
|
313
|
-
t.deepEqual(events[2].results, [5], 'results match');
|
|
314
|
-
t.end();
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
129
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Test that arguments which are promises are automatically resolved
|
|
5
|
+
before calling react functions
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
var test = require('tap').test;
|
|
9
|
+
var Deferred = require('promised-io/promise').Deferred;
|
|
10
|
+
|
|
11
|
+
var react = require('../promise-resolve'); // require('react/promise-resolve');
|
|
12
|
+
|
|
13
|
+
function multiply(x, y, cb) { cb(null, x * y); }
|
|
14
|
+
function add(x, y, cb) { cb(null, x + y); }
|
|
15
|
+
// function badF2(a, b, cb) { cb('my-error'); }
|
|
16
|
+
|
|
17
|
+
test('auto resolve promises passed as args', function (t) {
|
|
18
|
+
t.plan(4);
|
|
19
|
+
var fn = react();
|
|
20
|
+
var errors = fn.setAndValidateAST({
|
|
21
|
+
inParams: ['a', 'b'],
|
|
22
|
+
tasks: [
|
|
23
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] },
|
|
24
|
+
{ f: add, a: ['c', 'b'], out: ['d'] }
|
|
25
|
+
],
|
|
26
|
+
outTask: { a: ['c', 'd'] }
|
|
27
|
+
});
|
|
28
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
29
|
+
|
|
30
|
+
function retAP() {
|
|
31
|
+
var deferred = new Deferred();
|
|
32
|
+
setTimeout(function () { deferred.resolve(2); }, 10);
|
|
33
|
+
return deferred.promise;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function retBP() {
|
|
37
|
+
var deferred = new Deferred();
|
|
38
|
+
setTimeout(function () { deferred.resolve(3); }, 10);
|
|
39
|
+
return deferred.promise;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var ap = retAP();
|
|
43
|
+
var bp = retBP();
|
|
44
|
+
|
|
45
|
+
fn(ap, bp, function (err, c, d) {
|
|
46
|
+
t.equal(err, null);
|
|
47
|
+
t.equal(c, 6);
|
|
48
|
+
t.equal(d, 9);
|
|
49
|
+
t.end();
|
|
50
|
+
});
|
|
51
|
+
});
|
package/test/validate.test.js
CHANGED
|
@@ -263,4 +263,33 @@ test('missing or mispelled final output variables', function (t) {
|
|
|
263
263
|
];
|
|
264
264
|
t.deepEqual(validate(ast), messages);
|
|
265
265
|
t.end();
|
|
266
|
-
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('missing or mispelled validation ignores properties', function (t) {
|
|
269
|
+
var ast = {
|
|
270
|
+
inParams: ['obj'],
|
|
271
|
+
tasks: [
|
|
272
|
+
{ f: foo, a: ['obj.foo'], out: [] },
|
|
273
|
+
{ f: bar, a: ['obj.bar'], out: [] }
|
|
274
|
+
],
|
|
275
|
+
outTask: { a: ['obj.cat'] }
|
|
276
|
+
};
|
|
277
|
+
t.deepEqual(validate(ast), []);
|
|
278
|
+
t.end();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('missing or mispelled validation ignores literals', function (t) {
|
|
282
|
+
var ast = {
|
|
283
|
+
inParams: [],
|
|
284
|
+
tasks: [
|
|
285
|
+
{ f: foo, a: ['true', 'false', '123', '123.1', 'null'], out: [] },
|
|
286
|
+
{ f: bar, a: ['-123', '-123.4', '"wow"', "'hey'"], out: [] },
|
|
287
|
+
{ f: foo, a: ['"two-words"', "'also-two'", '"two.words"', "'also.two'"], out: [] },
|
|
288
|
+
{ f: foo, a: ['this'], out: [] }
|
|
289
|
+
],
|
|
290
|
+
outTask: { a: [] }
|
|
291
|
+
};
|
|
292
|
+
t.deepEqual(validate(ast), []);
|
|
293
|
+
t.end();
|
|
294
|
+
});
|
|
295
|
+
|
package/test/vcon.test.js
CHANGED
|
@@ -67,12 +67,25 @@ test('simple getVar returns existing value', function (t) {
|
|
|
67
67
|
test('getVar on literals returns the literal', function (t) {
|
|
68
68
|
t.equal(VContext.create([], []).getVar(true), true);
|
|
69
69
|
t.equal(VContext.create([], []).getVar(false), false);
|
|
70
|
+
t.equal(VContext.create([], []).getVar(null), null);
|
|
71
|
+
t.equal(VContext.create([], []).getVar('true'), true);
|
|
72
|
+
t.equal(VContext.create([], []).getVar('false'), false);
|
|
73
|
+
t.equal(VContext.create([], []).getVar('null'), null);
|
|
70
74
|
t.equal(VContext.create([], []).getVar(-100), -100);
|
|
71
75
|
t.equal(VContext.create([], []).getVar(100), 100);
|
|
72
76
|
t.equal(VContext.create([], []).getVar(123.4), 123.4);
|
|
73
77
|
t.equal(VContext.create([], []).getVar(-987.6), -987.6);
|
|
78
|
+
t.equal(VContext.create([], []).getVar('-100'), -100);
|
|
79
|
+
t.equal(VContext.create([], []).getVar('100'), 100);
|
|
80
|
+
t.equal(VContext.create([], []).getVar('123.4'), 123.4);
|
|
81
|
+
t.equal(VContext.create([], []).getVar('-987.6'), -987.6);
|
|
74
82
|
t.equal(VContext.create([], []).getVar('"foo"'), 'foo');
|
|
75
83
|
t.equal(VContext.create([], []).getVar("'foo'"), 'foo');
|
|
84
|
+
t.equal(VContext.create([], []).getVar("'foo.bar'"), 'foo.bar');
|
|
85
|
+
t.equal(VContext.create([], []).getVar("'foo-bar'"), 'foo-bar');
|
|
86
|
+
t.equal(VContext.create([], []).getVar("'foo-bar.json'"), 'foo-bar.json');
|
|
87
|
+
t.equal(VContext.create([], []).getVar('"foo-bar.json"'), 'foo-bar.json');
|
|
88
|
+
t.deepEqual(VContext.create([], [], null, { a: 1}).getVar('this'), { a: 1});
|
|
76
89
|
t.end();
|
|
77
90
|
});
|
|
78
91
|
|
package/oldExamples/analyze.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function loadUser(uid, cb) { setTimeout(cb, 100, null, "User" + uid); }
|
|
4
|
-
function loadFile(filename, cb) { setTimeout(cb, 100, null, 'Filedata' + filename); }
|
|
5
|
-
function markdown(filedata) { return 'html' + filedata; }
|
|
6
|
-
function prepareDirectory(outDirname, cb) { setTimeout(cb, 200, null, 'dircreated-' + outDirname); }
|
|
7
|
-
function writeOutput(html, user, cb) { setTimeout(cb, 300, null, html + '_bytesWritten'); }
|
|
8
|
-
function loadEmailTemplate(cb) { setTimeout(cb, 50, null, 'emailmd'); }
|
|
9
|
-
function customizeEmail(user, emailHtml, cb) { return 'cust-' + user + emailHtml; }
|
|
10
|
-
function deliverEmail(custEmailHtml, cb) { setTimeout(cb, 100, null, 'delivered-' + custEmailHtml); }
|
|
11
|
-
|
|
12
|
-
function analyze(fn) {
|
|
13
|
-
console.log(fn.toString());
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var fn = analyze(function loadAndSend(filename, uid, outDirname, cb,
|
|
17
|
-
R, filedata, outDirName, dircreated, emailmd, emailHtml,
|
|
18
|
-
custEmailHtml, deliveredEmail, err, user, html, bytesWritten) {
|
|
19
|
-
R.async(loadUser, uid).cb(err, user)
|
|
20
|
-
.async(loadFile, filename).cb(err, filedata)
|
|
21
|
-
.sync(markdown, filedata).returns(filedata)
|
|
22
|
-
.async(prepareDirectory, outDirName).cb(dircreated)
|
|
23
|
-
.async(writeOutput, html, user).cb(err, bytesWritten).after(prepareDirectory)
|
|
24
|
-
.async(loadEmailTemplate).cb(err, emailmd)
|
|
25
|
-
.sync(markdown, emailmd).returns(emailHtml)
|
|
26
|
-
.sync(customizeEmail, user, emailHtml).returns(custEmailHtml)
|
|
27
|
-
.sync(deliverEmail, custEmailHtml).returns(deliveredEmail).after(writeOutput)
|
|
28
|
-
.finalCb(err, html, user, bytesWritten);
|
|
29
|
-
});
|