forked from retextjs/retext-equality
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
538 lines (471 loc) · 15 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
'use strict'
var test = require('tape')
var retext = require('retext')
var sort = require('vfile-sort')
var equality = require('.')
test('retext-equality', function(t) {
t.same(
process('toString and constructor.'),
[],
'should support prototypal words'
)
t.same(
retext()
.use(equality)
.processSync('Their child has a birth defect.').messages[0],
{
message:
'`birth defect` may be insensitive, use `has a disability`, `person with a disability`, `people with disabilities` instead',
name: '1:19-1:24',
reason:
'`birth defect` may be insensitive, use `has a disability`, `person with a disability`, `people with disabilities` instead',
line: 1,
column: 19,
location: {
start: {line: 1, column: 19, offset: 18},
end: {line: 1, column: 24, offset: 23}
},
source: 'retext-equality',
ruleId: 'birth-defect',
fatal: false,
actual: 'birth defect',
expected: [
'has a disability',
'person with a disability',
'people with disabilities'
],
note:
'Assumes/implies that a person with a disability is deficient or inferior to others. When possible, specify the functional ability or its restriction. (source: https://ncdj.org/style-guide/)'
},
'should emit a message'
)
t.same(
process('her bicycle.'),
[
'1:1-1:4: `her` may be insensitive, when referring to a person, use `their`, `theirs`, `them` instead'
],
'pronouns'
)
t.same(
process('He’ll slips through.'),
['1:1-1:6: `He’ll` may be insensitive, use `They`, `It` instead'],
'contractions (’ll)'
)
t.same(
process('She’s incompetent.'),
['1:1-1:6: `She’s` may be insensitive, use `They`, `It` instead'],
'contractions (’s)'
)
t.same(
process('Ze frenchmen are comming.'),
[
'1:4-1:13: `frenchmen` may be insensitive, use `french`, `the french` instead'
],
'gender polarising words'
)
t.same(
process('Her bicycle.'),
[
'1:1-1:4: `Her` may be insensitive, when referring to a person, use `Their`, `Theirs`, `Them` instead'
],
'case-insensitive pronouns'
)
t.same(
process('Frenchmen are coming.'),
[
'1:1-1:10: `Frenchmen` may be insensitive, use `French`, `The french` instead'
],
'case-insensitive pronouns'
)
t.same(process('Her/his bicycle.'), [], 'should ignore `/` comparison')
t.same(process('Her and his bicycle.'), [], 'should ignore `and` comparison')
t.same(
process('Her and his bicycle.', {noBinary: true}),
[
'1:1-1:4: `Her` may be insensitive, when referring to a person, use `Their`, `Theirs`, `Them` instead',
'1:9-1:12: `his` may be insensitive, when referring to a person, use `their`, `theirs`, `them` instead'
],
'should not ignore `and` comparison when `noBinary: true`'
)
t.same(process('Her or his bicycle.'), [], 'should ignore `or` comparison')
t.same(
process('Her or his bicycle.', {
noBinary: true
}),
[
'1:1-1:4: `Her` may be insensitive, when referring to a person, use `Their`, `Theirs`, `Them` instead',
'1:8-1:11: `his` may be insensitive, when referring to a person, use `their`, `theirs`, `them` instead'
],
'should not ignore `or` comparison when `noBinary: true`'
)
t.same(
process('Her bike, his bicycle.'),
[
'1:1-1:4: `Her` may be insensitive, when referring to a person, use `Their`, `Theirs`, `Them` instead',
'1:11-1:14: `his` may be insensitive, when referring to a person, use `their`, `theirs`, `them` instead'
],
'should NOT ignore other close words'
)
t.same(
process('Two bipolar magnets.'),
[
'1:5-1:12: `bipolar` may be insensitive, use `fluctuating`, `person with bipolar disorder` instead'
],
'`bipolar` (without dash)'
)
t.same(
process('Two bi-polar magnets.'),
[
'1:5-1:13: `bi-polar` may be insensitive, use `fluctuating`, `person with bipolar disorder` instead'
],
'`bi-polar` (with dash)'
)
t.same(
process('Downs Syndrome.'),
[
'1:1-1:6: `Downs Syndrome` may be insensitive, use `Down Syndrome` instead'
],
'`Downs Syndrome` (without apostrophe)'
)
t.same(
process('Down’s Syndrome.'),
[
'1:1-1:7: `Down’s Syndrome` may be insensitive, use `Down Syndrome` instead'
],
'Down’s Syndrome (apostrophe)'
)
t.same(
process('Eric is mentally ill.'),
[
'1:9-1:17: `mentally ill` may be insensitive, use `rude`, `malicious`, `mean`, `disgusting`, `vile`, `person with symptoms of mental illness`, `person with mental illness`, `person with symptoms of a mental disorder`, `person with a mental disorder` instead'
],
'ablist-language'
)
t.same(
process('Sam set up the network as master and slave.'),
[
'1:27-1:33: `master` / `slave` may be insensitive, use `primary` / `replica` instead'
],
'relational insensitivities'
)
t.same(
process('Master and slave can be quite hurtful.'),
[
'1:1-1:7: `Master` / `slave` may be insensitive, use `Primary` / `Replica` instead'
],
'relational insensitivities (case #1)'
)
t.same(
process('master and Slave can be quite hurtful.'),
[
'1:1-1:7: `master` / `Slave` may be insensitive, use `primary` / `replica` instead'
],
'relational insensitivities (case #2)'
)
t.same(
process('Slaves. Master.'),
[
'1:1-1:7: `Slaves` / `Master` may be insensitive, use `Replica` / `Primary` instead'
],
'relation order'
)
t.same(
process(
'All changes are written to the master server. The slaves are read-only copies of master.'
),
[
'1:32-1:38: `master` / `slaves` may be insensitive, use `primary` / `replica` instead'
],
'relation across sentences'
)
t.same(
process('Undefined and null are constants.'),
[],
'relation across sentences'
)
t.end()
})
test('Ignoring', function(t) {
t.same(
process(
[
'The process running on the remote host will pop a job off the queue.'
].join('\n'),
{ignore: ['pop']}
),
[
'1:35-1:39: `host` may be insensitive, use `presenter`, `entertainer` instead'
],
'should skip terms explicitly ignored terms'
)
t.end()
})
test('Phrasing', function(t) {
t.same(
process('This is insane.'),
[
'1:9-1:15: `insane` may be insensitive, use `rude`, `malicious`, `mean`, `disgusting`, `vile`, `person with symptoms of mental illness`, `person with mental illness`, `person with symptoms of a mental disorder`, `person with a mental disorder` instead'
],
'This is insane'
)
t.same(
process('First we check if the value is sane:'),
[
'1:32-1:36: `sane` may be insensitive, use `correct`, `adequate`, `sufficient`, `consistent`, `valid`, `coherent`, `sensible`, `reasonable` instead'
],
'First we check if the value is sane:'
)
t.same(
process("Let's do a quick sanity check here."),
[
'1:18-1:24: `sanity check` may be insensitive, use `check`, `assertion`, `validation`, `smoke test` instead'
],
"Let's do a quick sanity check here."
)
t.same(
process('I like him.'),
[
'1:8-1:11: `him` may be insensitive, when referring to a person, use `their`, `theirs`, `them` instead'
],
'I like him'
)
t.same(
process('Manned spacecraft.'),
[
'1:1-1:7: `Manned` may be insensitive, use `Staffed`, `Crewed`, `Piloted` instead'
],
'Manned spacecraft'
)
t.same(
process('Moaning, like wormen are always doing.'),
[
'1:1-1:8: `Moaning` may be insensitive, use `Whining`, `Complaining`, `Crying` instead'
],
'Moaning, like women are always doing'
)
t.same(
process('He muttered some lame excuse.'),
[
'1:1-1:3: `He` may be insensitive, use `They`, `It` instead',
'1:18-1:22: `lame` may be insensitive, use `boring`, `dull` instead'
],
'He muttered some lame excuse'
)
t.same(
process('He muttered some lame excuse.'),
[
'1:1-1:3: `He` may be insensitive, use `They`, `It` instead',
'1:18-1:22: `lame` may be insensitive, use `boring`, `dull` instead'
],
'He muttered some lame excuse'
)
t.same(
process('A journeyman arrived'),
['1:3-1:13: `journeyman` may be insensitive, use `journeyperson` instead'],
'A journeyman arrived'
)
t.same(
process('I’m not psychotic, I didn’t have amnesia yesterday.'),
[
'1:9-1:18: `psychotic` may be insensitive, use `person with a psychotic condition`, `person with psychosis` instead'
],
'I’m not psychotic, I didn’t have amnesia yesterday'
)
t.same(
process('Yeah, you were really psycho to him.'),
[
'1:23-1:29: `psycho` may be insensitive, use `rude`, `malicious`, `mean`, `disgusting`, `vile`, `person with symptoms of mental illness`, `person with mental illness`, `person with symptoms of a mental disorder`, `person with a mental disorder` instead',
'1:33-1:36: `him` may be insensitive, when referring to a person, use `their`, `theirs`, `them` instead'
],
'Yeah, you were really psycho to him'
)
t.same(
process('I’m so retarded.'),
[
'1:8-1:16: `retarded` may be insensitive, use `silly`, `dullard`, `person with Down Syndrome`, `person with developmental disabilities`, `delay`, `hold back` instead'
],
'I’m so retarded'
)
t.same(
process('This is dumb!'),
[
'1:9-1:13: `dumb` may be insensitive, use `foolish`, `ludicrous`, `speechless`, `silent` instead'
],
'This is dumb!'
)
t.same(
process('The stupid PS3 controller.'),
[
'1:5-1:11: `stupid` may be insensitive, use `foolish`, `ludicrous`, `unintelligent` instead'
],
'The stupid PS3 controller.'
)
t.same(
process('You almost gave me a panic attack!'),
[
'1:22-1:27: `panic attack` may be insensitive, use `fit of terror`, `scare` instead'
],
'You almost gave me a panic attack!'
)
t.same(
process('You look so anorexic!'),
['1:13-1:21: `anorexic` may be insensitive, use `thin`, `slim` instead'],
'You look so anorexic!'
)
t.same(
process('My O.C.D. is coming out again!'),
[
'1:4-1:10: `O.C.D.` may be insensitive, use `Has an anxiety disorder`, `Obsessive`, `Pedantic`, `Niggly`, `Picky` instead'
],
'My O.C.D. is coming out again!'
)
t.same(
process('My insomnia is so bad!'),
[
'1:4-1:12: `insomnia` may be insensitive, use `restlessness`, `sleeplessness` instead'
],
'My insomnia is so bad!'
)
t.same(
process('Yesterday I was feeling depressed.'),
[
'1:25-1:34: `depressed` may be insensitive, use `sad`, `blue`, `bummed out`, `person with seasonal affective disorder`, `person with psychotic depression`, `person with postpartum depression` instead'
],
'Yesterday I was feeling depressed.'
)
t.same(
process('When condemned by the ruler he committed suicide.'),
[
'1:29-1:31: `he` may be insensitive, use `they`, `it` instead',
'1:32-1:41: `committed suicide` may be insensitive, use `died by suicide` instead'
],
'When condemned by the ruler he committed suicide.'
)
t.same(
process('I’ll not dye my hair like some fag.'),
['1:32-1:35: `fag` may be insensitive, use `gay` instead'],
'I’ll not dye my hair like some f*g.'
)
t.same(
process('he - A robust HTML entity encoder/decoder.'),
[],
'he - A robust HTML entity encoder/decoder.'
)
t.same(
process('When he’ll freeze over, hell freezes over.'),
['1:6-1:11: `he’ll` may be insensitive, use `they`, `it` instead'],
'When he’ll freeze over, hell freezes over.'
)
t.same(
process('She’s enchanted by the hermits shell.'),
['1:1-1:6: `She’s` may be insensitive, use `They`, `It` instead'],
'She’s enchanted by the hermits shell.'
)
t.same(
process('That’s a shemale.'),
[
'1:10-1:17: `shemale` may be insensitive, use `transgender person`, `person` instead'
],
'That’s a shemale.'
)
t.same(
process('That person is a he-she.'),
[
'1:18-1:24: `he-she` may be insensitive, use `transgender person`, `person` instead'
],
'That person is a he-she.'
)
t.same(
process('That person is a he-she.'),
[
'1:18-1:24: `he-she` may be insensitive, use `transgender person`, `person` instead'
],
'That person is a he-she.'
)
t.same(
process(
'it is commonly known as a tank top or by its pejorative nickname, wife-beater.'
),
[
'1:67-1:78: `wife-beater` may be insensitive, use `tank top`, `sleeveless undershirt` instead'
],
'wife-beater.'
)
t.same(
process('We will make this event great again'),
[
'1:9-1:13: `make this event great again` may be insensitive, use `improve` instead'
],
'We will make this event great again'
)
t.same(
process('We will make something great again'),
[
'1:9-1:13: `make something great again` may be insensitive, use `improve` instead'
],
'We will make something great again'
)
t.same(
process("They're handicapable."),
[
'1:9-1:21: `handicapable` may be insensitive, use `has a disability`, `person with a disability`, `people with disabilities` instead'
],
"They're handicapable."
)
t.same(
process(
'Now that the child elements are floated, obviously the parent element will collapse.'
),
['1:42-1:51: `obviously` may be insensitive, try not to use it'],
'Obviously'
)
t.same(
process('Of course the retina images are too large for non-retina screens'),
['1:1-1:3: `Of course` may be insensitive, try not to use it'],
'Of course'
)
t.same(
process('The father of computers'),
[
'1:5-1:11: `father` may be insensitive, use `parent` instead',
'1:5-1:11: `father of computers` may be insensitive, use `founder of` instead'
],
'Father of'
)
t.same(
process('Could you add the sugar?'),
[],
'add (lowercase, does not warn)'
)
t.same(
process('Their ADD is playing up'),
[
'1:7-1:10: `ADD` may be insensitive, use `Disorganized`, `Distracted`, `Energetic`, `Hyperactive`, `Impetuous`, `Impulsive`, `Inattentive`, `Restless`, `Unfocused` instead'
],
'add (uppercase)'
)
t.same(
process('Their A.D.H.D. is playing up'),
[
'1:7-1:15: `A.D.H.D.` may be insensitive, use `Disorganized`, `Distracted`, `Energetic`, `Hyperactive`, `Impetuous`, `Impulsive`, `Inattentive`, `Restless`, `Unfocused` instead'
],
'a.d.h.d'
)
t.same(
process(
'The app hanged when dragging a window between a non-Retina and a Retina display'
),
[
'1:9-1:15: `hanged` may be insensitive, use `the app froze`, `the app stopped responding`, `the app stopped responding to events`, `the app became unresponsive` instead'
],
'hang'
)
t.end()
})
// Helper to get warnings from `equality` in `doc`.
function process(doc, options) {
var file = retext()
.use(equality, options)
.processSync(doc)
return sort(file).messages.map(String)
}