Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / i / test / inflector / methods-test.js
1 (function() {
2   var assert, cases, vows, util;
3
4   vows = require('vows');
5
6   assert = require('assert');
7
8   util = require('../../lib/util');
9
10   cases = require('./cases');
11
12   vows.describe('Module Inflector methods').addBatch({
13     'Test inflector method': {
14       topic: require('../../lib/methods'),
15       'camelize': {
16         'word': function(topic) {
17           var i, words, _i, _len, _ref, _results;
18           words = cases.CamelToUnderscore;
19           _ref = Object.keys(words);
20           _results = [];
21           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
22             i = _ref[_i];
23             _results.push(assert.equal(topic.camelize(words[i]), i));
24           }
25           return _results;
26         },
27         'word with first letter lower': function(topic) {
28           var i, words, _i, _len, _ref, _results;
29           words = cases.UnderscoreToLowerCamel;
30           _ref = Object.keys(words);
31           _results = [];
32           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
33             i = _ref[_i];
34             _results.push(assert.equal(topic.camelize(i, false), words[i]));
35           }
36           return _results;
37         },
38         'path': function(topic) {
39           var i, words, _i, _len, _ref, _results;
40           words = cases.CamelWithModuleToUnderscoreWithSlash;
41           _ref = Object.keys(words);
42           _results = [];
43           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
44             i = _ref[_i];
45             _results.push(assert.equal(topic.camelize(words[i]), i));
46           }
47           return _results;
48         },
49         'path with first letter lower': function(topic) {
50           return assert.equal(topic.camelize('bullet_record/errors', false), 'bulletRecord.Errors');
51         }
52       },
53       'underscore': {
54         'word': function(topic) {
55           var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
56           words = cases.CamelToUnderscore;
57           _ref = Object.keys(words);
58           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
59             i = _ref[_i];
60             assert.equal(topic.underscore(i), words[i]);
61           }
62           words = cases.CamelToUnderscoreWithoutReverse;
63           _ref2 = Object.keys(words);
64           _results = [];
65           for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
66             i = _ref2[_j];
67             _results.push(assert.equal(topic.underscore(i), words[i]));
68           }
69           return _results;
70         },
71         'path': function(topic) {
72           var i, words, _i, _len, _ref, _results;
73           words = cases.CamelWithModuleToUnderscoreWithSlash;
74           _ref = Object.keys(words);
75           _results = [];
76           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
77             i = _ref[_i];
78             _results.push(assert.equal(topic.underscore(i), words[i]));
79           }
80           return _results;
81         },
82         'from dasherize': function(topic) {
83           var i, words, _i, _len, _ref, _results;
84           words = cases.UnderscoresToDashes;
85           _ref = Object.keys(words);
86           _results = [];
87           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
88             i = _ref[_i];
89             _results.push(assert.equal(topic.underscore(topic.dasherize(i)), i));
90           }
91           return _results;
92         }
93       },
94       'dasherize': {
95         'underscored_word': function(topic) {
96           var i, words, _i, _len, _ref, _results;
97           words = cases.UnderscoresToDashes;
98           _ref = Object.keys(words);
99           _results = [];
100           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
101             i = _ref[_i];
102             _results.push(assert.equal(topic.dasherize(i), words[i]));
103           }
104           return _results;
105         }
106       },
107       'demodulize': {
108         'module name': function(topic) {
109           return assert.equal(topic.demodulize('BulletRecord.CoreExtensions.Inflections'), 'Inflections');
110         },
111         'isolated module name': function(topic) {
112           return assert.equal(topic.demodulize('Inflections'), 'Inflections');
113         }
114       },
115       'foreign_key': {
116         'normal': function(topic) {
117           var i, words, _i, _len, _ref, _results;
118           words = cases.ClassNameToForeignKeyWithoutUnderscore;
119           _ref = Object.keys(words);
120           _results = [];
121           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
122             i = _ref[_i];
123             _results.push(assert.equal(topic.foreign_key(i, false), words[i]));
124           }
125           return _results;
126         },
127         'with_underscore': function(topic) {
128           var i, words, _i, _len, _ref, _results;
129           words = cases.ClassNameToForeignKeyWithUnderscore;
130           _ref = Object.keys(words);
131           _results = [];
132           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
133             i = _ref[_i];
134             _results.push(assert.equal(topic.foreign_key(i), words[i]));
135           }
136           return _results;
137         }
138       },
139       'ordinalize': function(topic) {
140         var i, words, _i, _len, _ref, _results;
141         words = cases.OrdinalNumbers;
142         _ref = Object.keys(words);
143         _results = [];
144         for (_i = 0, _len = _ref.length; _i < _len; _i++) {
145           i = _ref[_i];
146           _results.push(assert.equal(topic.ordinalize(i), words[i]));
147         }
148         return _results;
149       }
150     }
151   }).addBatch({
152     'Test inflector inflection methods': {
153       topic: function() {
154         var Inflector;
155         Inflector = require('../../lib/methods');
156         Inflector.inflections["default"]();
157         return Inflector;
158       },
159       'pluralize': {
160         'empty': function(topic) {
161           return assert.equal(topic.pluralize(''), '');
162         },
163         'uncountable': function(topic) {
164           return assert.equal(topic.pluralize('money'), 'money');
165         },
166         'normal': function(topic) {
167           topic.inflections.irregular('octopus', 'octopi');
168           return assert.equal(topic.pluralize('octopus'), 'octopi');
169         },
170         'cases': function(topic) {
171           var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
172           words = cases.SingularToPlural;
173           _ref = Object.keys(words);
174           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
175             i = _ref[_i];
176             assert.equal(topic.pluralize(i), words[i]);
177           }
178           _ref2 = Object.keys(words);
179           _results = [];
180           for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
181             i = _ref2[_j];
182             _results.push(assert.equal(topic.pluralize(util.string.capitalize(i)), util.string.capitalize(words[i])));
183           }
184           return _results;
185         },
186         'cases plural': function(topic) {
187           var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
188           words = cases.SingularToPlural;
189           _ref = Object.keys(words);
190           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
191             i = _ref[_i];
192             assert.equal(topic.pluralize(words[i]), words[i]);
193           }
194           _ref2 = Object.keys(words);
195           _results = [];
196           for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
197             i = _ref2[_j];
198             _results.push(assert.equal(topic.pluralize(util.string.capitalize(words[i])), util.string.capitalize(words[i])));
199           }
200           return _results;
201         }
202       },
203       'singuralize': {
204         'empty': function(topic) {
205           return assert.equal(topic.singularize(''), '');
206         },
207         'uncountable': function(topic) {
208           return assert.equal(topic.singularize('money'), 'money');
209         },
210         'normal': function(topic) {
211           topic.inflections.irregular('octopus', 'octopi');
212           return assert.equal(topic.singularize('octopi'), 'octopus');
213         },
214         'cases': function(topic) {
215           var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
216           words = cases.SingularToPlural;
217           _ref = Object.keys(words);
218           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
219             i = _ref[_i];
220             assert.equal(topic.singularize(words[i]), i);
221           }
222           _ref2 = Object.keys(words);
223           _results = [];
224           for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
225             i = _ref2[_j];
226             _results.push(assert.equal(topic.singularize(util.string.capitalize(words[i])), util.string.capitalize(i)));
227           }
228           return _results;
229         }
230       },
231       'uncountablility': {
232         'normal': function(topic) {
233           var i, words, _i, _j, _k, _len, _len2, _len3, _results;
234           words = topic.inflections.uncountables;
235           for (_i = 0, _len = words.length; _i < _len; _i++) {
236             i = words[_i];
237             assert.equal(topic.singularize(i), i);
238           }
239           for (_j = 0, _len2 = words.length; _j < _len2; _j++) {
240             i = words[_j];
241             assert.equal(topic.pluralize(i), i);
242           }
243           _results = [];
244           for (_k = 0, _len3 = words.length; _k < _len3; _k++) {
245             i = words[_k];
246             _results.push(assert.equal(topic.singularize(i), topic.pluralize(i)));
247           }
248           return _results;
249         },
250         'greedy': function(topic) {
251           var countable_word, uncountable_word;
252           uncountable_word = "ors";
253           countable_word = "sponsor";
254           topic.inflections.uncountable(uncountable_word);
255           assert.equal(topic.singularize(uncountable_word), uncountable_word);
256           assert.equal(topic.pluralize(uncountable_word), uncountable_word);
257           assert.equal(topic.pluralize(uncountable_word), topic.singularize(uncountable_word));
258           assert.equal(topic.singularize(countable_word), 'sponsor');
259           assert.equal(topic.pluralize(countable_word), 'sponsors');
260           return assert.equal(topic.singularize(topic.pluralize(countable_word)), 'sponsor');
261         }
262       },
263       'humanize': {
264         'normal': function(topic) {
265           var i, words, _i, _len, _ref, _results;
266           words = cases.UnderscoreToHuman;
267           _ref = Object.keys(words);
268           _results = [];
269           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
270             i = _ref[_i];
271             _results.push(assert.equal(topic.humanize(i), words[i]));
272           }
273           return _results;
274         },
275         'with rule': function(topic) {
276           topic.inflections.human(/^(.*)_cnt$/i, '$1_count');
277           topic.inflections.human(/^prefix_(.*)$/i, '$1');
278           assert.equal(topic.humanize('jargon_cnt'), 'Jargon count');
279           return assert.equal(topic.humanize('prefix_request'), 'Request');
280         },
281         'with string': function(topic) {
282           topic.inflections.human('col_rpted_bugs', 'Reported bugs');
283           assert.equal(topic.humanize('col_rpted_bugs'), 'Reported bugs');
284           return assert.equal(topic.humanize('COL_rpted_bugs'), 'Col rpted bugs');
285         },
286         'with _id': function(topic) {
287           return assert.equal(topic.humanize('author_id'), 'Author');
288         }
289       },
290       'titleize': {
291         'normal': function(topic) {
292           var i, words, _i, _len, _ref, _results;
293           words = cases.MixtureToTitleCase;
294           _ref = Object.keys(words);
295           _results = [];
296           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
297             i = _ref[_i];
298             _results.push(assert.equal(topic.titleize(i), words[i]));
299           }
300           return _results;
301         },
302         'with hyphens': function(topic) {
303           return assert.equal(topic.titleize('x-men: the last stand'), 'X Men: The Last Stand');
304         },
305         'with ampersands': function(topic) {
306           return assert.equal(topic.titleize('garfunkel & oates'), 'Garfunkel & Oates');
307         }
308       },
309       'tableize': function(topic) {
310         var i, words, _i, _len, _ref, _results;
311         words = cases.ClassNameToTableName;
312         _ref = Object.keys(words);
313         _results = [];
314         for (_i = 0, _len = _ref.length; _i < _len; _i++) {
315           i = _ref[_i];
316           _results.push(assert.equal(topic.tableize(i), words[i]));
317         }
318         return _results;
319       },
320       'classify': {
321         'underscore': function(topic) {
322           var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
323           words = cases.ClassNameToTableName;
324           _ref = Object.keys(words);
325           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
326             i = _ref[_i];
327             assert.equal(topic.classify(words[i]), i);
328           }
329           _ref2 = Object.keys(words);
330           _results = [];
331           for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
332             i = _ref2[_j];
333             _results.push(assert.equal(topic.classify('table_prefix.' + words[i]), i));
334           }
335           return _results;
336         },
337         'normal': function(topic) {
338           topic.inflections.irregular('octopus', 'octopi');
339           return assert.equal(topic.classify('octopi'), 'Octopus');
340         }
341       }
342     }
343   })["export"](module);
344
345 }).call(this);