-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathinflector.js
101 lines (100 loc) · 2.51 KB
/
inflector.js
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
describe('inflector', function() {
/**
* Test macro for pluralize & singularize tests
*/
function example(method, from, to) {
it(method + 's "' + from + '" to "' + to + '"', function() {
expect(_[method](from)).to.equal(to);
});
}
describe('plurals', function() {
[
['rose', 'roses'],
['axis', 'axes'],
['virus', 'viri'],
['alias', 'aliases'],
['bus', 'buses'],
['tomato', 'tomatoes'],
['datum', 'data'],
['analysis', 'analyses'],
['life', 'lives'],
['leaf', 'leaves'],
['loaf', 'loaves'],
['thief', 'thieves'],
['hive', 'hives'],
['boss', 'bosses'],
['soliloquy', 'soliloquies'],
['wish', 'wishes'],
['vertex', 'vertices'],
['mouse', 'mice'],
['ox', 'oxen'],
['quiz', 'quizzes']
].forEach(function(word) {
example('pluralize', word[0], word[1]);
});
});
describe('singulars', function() {
[
['roses', 'rose'],
['news', 'news'],
['data', 'datum'],
['analyses', 'analysis'],
['hives', 'hive'],
['soliloquies', 'soliloquy'],
['series', 'series'],
['movies', 'movie'],
['wishes', 'wish'],
['mice', 'mouse'],
['buses', 'bus'],
['shoes', 'shoe'],
['bosses', 'boss'],
['boss', 'boss'],
['crises', 'crisis'],
['viri', 'virus'],
['statuses', 'status'],
['oxen', 'ox'],
['vertices', 'vertex'],
['quizzes', 'quiz'],
['databases', 'database']
].forEach(function(word) {
example('singularize', word[0], word[1]);
});
});
describe('irregulars', function() {
[
['person', 'people'],
['man', 'men'],
['child', 'children'],
['sex', 'sexes'],
['move', 'moves'],
['cow', 'kine']
].forEach(function(word) {
example('pluralize', word[0], word[1]);
example('singularize', word[1], word[0]);
});
});
describe('uncountables', function() {
[
'equipment',
'information',
'rice',
'money',
'species',
'series',
'fish',
'sheep',
'jeans'
].forEach(function(word) {
example('pluralize', word, word);
example('singularize', word, word);
});
});
describe('#resetInflections', function() {
it('resets the default inflections', function() {
_.plural('haxor', 'hax0rs!');
expect(_.pluralize('haxor')).to.equal('hax0rs!');
_.resetInflections();
expect(_.pluralize('haxor')).to.equal('haxors');
});
});
});