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
|
/*
* function-args-test.js: Tests for `args` method
*
* (C) 2011, Charlie Robbins & the Contributors
* MIT LICENSE
*
*/
var assert = require('assert'),
path = require('path'),
vows = require('vows'),
macros = require('./helpers/macros'),
utile = require('../');
vows.describe('utile/args').addBatch({
'When using utile': {
'the `args` function': {
topic: utile,
'should be a function': function (_utile) {
assert.isFunction(_utile.args);
},
}
},
'utile.rargs()': {
'with no arguments': {
topic: utile.rargs(),
'should return an empty object': function (result) {
assert.isArray(result);
assert.lengthOf(result, 0);
}
},
'with simple arguments': {
topic: function () {
return (function () {
return utile.rargs(arguments);
})('a', 'b', 'c');
},
'should return an array with three items': function (result) {
assert.isArray(result);
assert.equal(3, result.length);
assert.equal(result[0], 'a');
assert.equal(result[1], 'b');
assert.equal(result[2], 'c');
}
},
'with a simple slice': {
topic: function () {
return (function () {
return utile.rargs(arguments, 1);
})('a', 'b', 'c');
},
'should return an array with three items': function (result) {
assert.isArray(result);
assert.equal(2, result.length);
assert.equal(result[0], 'b');
assert.equal(result[1], 'c');
}
}
},
'utile.args()': {
'with no arguments': {
topic: utile.args(),
'should return an empty Array': function (result) {
assert.isUndefined(result.callback);
assert.isArray(result);
assert.lengthOf(result, 0);
}
},
'with simple arguments': {
topic: function () {
return (function () {
return utile.args(arguments);
})('a', 'b', 'c', function () {
return 'ok';
});
},
'should return an array with three items': function (result) {
assert.isArray(result);
assert.equal(3, result.length);
assert.equal(result[0], 'a');
assert.equal(result[1], 'b');
assert.equal(result[2], 'c');
//
// Ensure that the Array returned
// by `utile.args()` enumerates correctly
//
var length = 0;
result.forEach(function (item) {
length++;
});
assert.equal(length, 3);
},
'should return lookup helpers': function (result) {
assert.isArray(result);
assert.equal(result.first, 'a');
assert.equal(result.last, 'c');
assert.isFunction(result.callback);
assert.isFunction(result.cb);
}
}
}
}).export(module);
|