Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / utile / test / function-args-test.js
1 /*
2  * function-args-test.js: Tests for `args` method
3  *
4  * (C) 2012, Nodejitsu Inc.
5  * MIT LICENSE
6  *
7  */
8
9 var assert = require('assert'),
10     path = require('path'),
11     vows = require('vows'),
12     macros = require('./helpers/macros'),
13     utile = require('../');
14
15 vows.describe('utile/args').addBatch({
16   'When using utile': {
17     'the `args` function': {
18       topic: utile,
19       'should be a function': function (_utile) {
20         assert.isFunction(_utile.args);
21       },
22     }
23   },
24   'utile.rargs()': {
25     'with no arguments': {
26       topic: utile.rargs(),
27       'should return an empty object': function (result) {
28         assert.isArray(result);
29         assert.lengthOf(result, 0);
30       }
31     },
32     'with simple arguments': {
33       topic: function () {
34         return (function () {
35           return utile.rargs(arguments);
36         })('a', 'b', 'c');
37       },
38       'should return an array with three items': function (result) {
39         assert.isArray(result);
40         assert.equal(3, result.length);
41         assert.equal(result[0], 'a');
42         assert.equal(result[1], 'b');
43         assert.equal(result[2], 'c');
44       }
45     },
46     'with a simple slice': {
47       topic: function () {
48         return (function () {
49           return utile.rargs(arguments, 1);
50         })('a', 'b', 'c');
51       },
52       'should return an array with three items': function (result) {
53         assert.isArray(result);
54         assert.equal(2, result.length);
55         assert.equal(result[0], 'b');
56         assert.equal(result[1], 'c');
57       }
58     }
59   },
60   'utile.args()': {
61     'with no arguments': {
62       topic: utile.args(),
63       'should return an empty Array': function (result) {
64         assert.isUndefined(result.callback);
65         assert.isArray(result);
66         assert.lengthOf(result, 0);
67       }
68     },
69     'with simple arguments': {
70       topic: function () {
71         return (function () {
72           return utile.args(arguments);
73         })('a', 'b', 'c', function () {
74           return 'ok';
75         });
76       },
77       'should return an array with three items': function (result) {
78         assert.isArray(result);
79         assert.equal(3, result.length);
80         assert.equal(result[0], 'a');
81         assert.equal(result[1], 'b');
82         assert.equal(result[2], 'c');
83
84         //
85         // Ensure that the Array returned
86         // by `utile.args()` enumerates correctly
87         //
88         var length = 0;
89         result.forEach(function (item) {
90           length++;
91         });
92
93         assert.equal(length, 3);
94       },
95       'should return lookup helpers': function (result) {
96         assert.isArray(result);
97         assert.equal(result.first, 'a');
98         assert.equal(result.last, 'c');
99         assert.isFunction(result.callback);
100         assert.isFunction(result.cb);
101       }
102     }
103   }
104 }).export(module);