Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / utile / test / utile-test.js
1 /*
2  * utile-test.js: Tests for `utile` module.
3  *
4  * (C) 2011, Nodejitsu Inc.
5  * MIT LICENSE
6  *
7  */
8
9 var assert = require('assert'),
10     vows = require('vows'),
11     utile = require('../lib');
12
13 var obj1, obj2;
14
15 obj1 = {
16   foo: true,
17   bar: {
18     bar1: true,
19     bar2: 'bar2'
20   }
21 };
22
23 obj2 = {
24   baz: true,
25   buzz: 'buzz'
26 };
27
28 Object.defineProperties(obj2, {
29
30   'bazz': {
31     get: function() {
32       return 'bazz';
33     },
34
35     set: function() {
36       return 'bazz';
37     }
38   },
39
40   'wat': {
41     set: function() {
42       return 'wat';
43     }
44   }
45
46 });
47
48 vows.describe('utile').addBatch({
49   "When using utile": {
50     "it should have the same methods as the `util` module": function () {
51       Object.keys(require('util')).forEach(function (fn) {
52         assert.isFunction(utile[fn]);
53       });
54     },
55     "it should have the correct methods defined": function () {
56       assert.isFunction(utile.mixin);
57       assert.isFunction(utile.clone);
58       assert.isFunction(utile.rimraf);
59       assert.isFunction(utile.mkdirp);
60       assert.isFunction(utile.cpr);
61     },
62     "the mixin() method": function () {
63       var mixed = utile.mixin({}, obj1, obj2);
64       assert.isTrue(mixed.foo);
65       assert.isObject(mixed.bar);
66       assert.isTrue(mixed.baz);
67       assert.isString(mixed.buzz);
68       assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').get);
69       assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').set);
70       assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'wat').set);
71       assert.isString(mixed.bazz);
72     },
73     "the clone() method": function () {
74       var clone = utile.clone(obj1);
75       assert.isTrue(clone.foo);
76       assert.isObject(clone.bar);
77       assert.notStrictEqual(obj1, clone);
78     },
79     "the createPath() method": function () {
80       var x = {},
81           r = Math.random();
82
83       utile.createPath(x, ['a','b','c'], r)
84       assert.equal(x.a.b.c, r)
85     },
86     "the capitalize() method": function () {
87       assert.isFunction(utile.capitalize);
88       assert.equal(utile.capitalize('bullet'), 'Bullet');
89       assert.equal(utile.capitalize('bullet_train'), 'BulletTrain');
90     },
91     "the escapeRegExp() method": function () {
92       var ans = "\\/path\\/to\\/resource\\.html\\?search=query";
93       assert.isFunction(utile.escapeRegExp);
94       assert.equal(utile.escapeRegExp('/path/to/resource.html?search=query'), ans);
95     },
96     "the underscoreToCamel() method": function () {
97       var obj = utile.underscoreToCamel({
98         key_with_underscore: {
99           andNested: 'values',
100           several: [1, 2, 3],
101           nested_underscores: true
102         },
103         just_one: 'underscore'
104       });
105
106       assert.isObject(obj.keyWithUnderscore);
107       assert.isString(obj.justOne);
108       assert.isTrue(obj.keyWithUnderscore.nestedUnderscores);
109     },
110     "the camelToUnderscore() method": function () {
111       var obj = utile.camelToUnderscore({
112         keyWithCamel: {
113           andNested: 'values',
114           several: [1, 2, 3],
115           nestedCamel: true
116         },
117         justOne: 'camel'
118       });
119
120       assert.isObject(obj.key_with_camel);
121       assert.isString(obj.just_one);
122       assert.isTrue(obj.key_with_camel.nested_camel);
123     }
124   }
125 }).export(module);
126