-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
155 lines (133 loc) · 5.36 KB
/
test.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
/* global it: false, describe: false */
var plural = require('./index')
, assert = require('assert')
describe('test monkey patching', function() {
describe('removing monkey patching (unmonkeyPatch)', function() {
it('should work as intended', function() {
plural.monkeyPatch()
assert.doesNotThrow(function() { String('test').plural() }, 'plural should be monkeypatched into String')
plural.unmonkeyPatch()
assert.throws(function() { String('test').plural() }, TypeError, 'plural should not be monkeypatched into String')
})
})
})
describe('plurals match', function() {
it('should match plurals', function() {
assert.equal(plural('test'), 'tests')
assert.equal(plural('hero'), 'heroes')
assert.equal(plural('embryo'), 'embryos')
assert.equal(plural('zero'), 'zeroes')
assert.equal(plural('cherry'), 'cherries')
assert.equal(plural('sky'), 'skies')
assert.equal(plural('seaway'), 'seaways')
assert.equal(plural('soliloquy'), 'soliloquies')
assert.equal(plural('monkey'), 'monkeys')
assert.equal(plural('day'), 'days')
assert.equal(plural('witch'), 'witches')
assert.equal(plural('box'), 'boxes')
assert.equal(plural('gallery'), 'galleries')
assert.equal(plural('stereo'), 'stereos')
assert.equal(plural('memo'), 'memos')
assert.equal(plural('hero'), 'heroes')
assert.equal(plural('omen'), 'omens')
assert.equal(plural('chilli'), 'chillies')
})
it('should match greek/latin plurals', function() {
assert.equal(plural('nucleus'), 'nuclei')
assert.equal(plural('syllabus'), 'syllabi')
assert.equal(plural('focus'), 'foci')
assert.equal(plural('fungus'), 'fungi')
assert.equal(plural('cactus'), 'cacti')
assert.equal(plural('thesis'), 'theses')
assert.equal(plural('crisis'), 'crises')
assert.equal(plural('appendix'), 'appendices')
assert.equal(plural('index'), 'indices')
assert.equal(plural('criterion'), 'criteria')
})
it('should convert f/fe ending words to "ves"', function() {
assert.equal(plural('knife'), 'knives')
assert.equal(plural('leaf'), 'leaves')
assert.equal(plural('hoof'), 'hooves')
assert.equal(plural('life'), 'lives')
assert.equal(plural('self'), 'selves')
assert.equal(plural('elf'), 'elves')
})
it('should handle man/woman/human', function() {
assert.equal(plural('man'), 'men')
assert.equal(plural('woman'), 'women')
assert.notEqual(plural('oman'), 'omen')
assert.equal(plural('human'), 'humans')
})
it('should handle words that are the same both singular/plural', function() {
assert.equal(plural('bison'), 'bison')
assert.equal(plural('cod'), 'cod')
assert.equal(plural('deer'), 'deer')
assert.equal(plural('fowl'), 'fowl')
assert.equal(plural('halibut'), 'halibut')
assert.equal(plural('moose'), 'moose')
assert.equal(plural('sheep'), 'sheep')
assert.equal(plural('kudos'), 'kudos')
assert.equal(plural('premises'), 'premises')
assert.equal(plural('shambles'), 'shambles')
})
it('should not flag anything that starts with those above words', function() {
assert.equal(plural('zipcode'), 'zipcodes')
assert.equal(plural('afowl'), 'afowls')
assert.equal(plural('moosed'), 'mooseds')
})
it('should handle some unique plurals', function() {
assert.equal(plural('die'), 'dice')
assert.equal(plural('goose'), 'geese')
assert.equal(plural('mouse'), 'mice')
assert.equal(plural('person'), 'people')
})
it('should handle plurals that are singular', function() {
var tools = ['goggle', 'scissor', 'plier', 'tong', 'tweezer']
var clothes = ['trouser', 'pant', 'pantie', 'clothe']
var games = ['billiard', 'bowl', 'card', 'dart', 'skittle', 'draught']
var illnesses = ['diabete', 'measle', 'mump', 'rabie', 'ricket', 'shingle']
var misc = ['kudo', 'premise', 'shamble', 'glasse', 'spectacle', 'jitter',
'alm', 'fece', 'bowel', 'sud', 'entrail', 'electronic', 'outskirt', 'odd', 'tropic',
'riche', 'surrounding', 'thank', 'heroic', 'remain', 'amend'
]
tools.concat(clothes, games, illnesses, misc).forEach(function(w) {
assert.equal(plural(w + 's'), w + 's')
})
})
it('should handle -ics ending words', function() {
var words = [
'mathematics', 'statistics', 'linguistics', 'classics', 'acoustics',
]
words.forEach(function(w) {
assert.equal(plural(w), w)
})
})
it('should make sure uncountable words aren\'t converted to plural form', function() {
var words = [
'tea', 'sugar', 'water', 'air', 'rice', 'knowledge', 'beauty',
'anger', 'fear', 'love', 'money', 'research', 'safety', 'evidence'
]
words.forEach(function(w) {
assert.equal(plural(w), w)
})
})
it('should make sure addRule works', function() {
assert.notEqual(plural('zzz'), 'roh')
plural.addRule('zzz', 'yyy')
assert.equal(plural('zzz'), 'yyy')
})
it('should be case insensitive', function() {
assert.equal(plural('test'), 'tests')
assert.equal(plural('Test'), 'Tests')
assert.equal(plural('TesT'), 'TesTs')
assert.equal(plural('pennY'), 'pennies')
assert.equal(plural('PeNnY'), 'PeNnies')
assert.equal(plural('KudoS'), 'KudoS')
})
})
describe('addRule should return plural construct', function() {
it('should be equal', function() {
assert.equal(plural.addRule(/garababble/i, function(w) { return w }), plural)
})
})