UNPKG

2.19 kBJavaScriptView Raw
1'use strict'
2// A list of all the synonyms of assert methods.
3// In addition to these, multi-word camelCase are also synonymized to
4// all lowercase and snake_case
5
6const multiword = obj =>
7 Object.keys(obj).reduce((s, i) =>
8 (s[i] = [ multiword_(i) ]
9 .concat(obj[i].map(multiword_))
10 .reduce((s, i) => (s.push.apply(s, i), s), []), s), obj)
11
12const multiword_ = str =>
13 str.match(/[A-Z]/) ? [
14 str,
15 str.toLowerCase(),
16 str.replace(/[A-Z]/g, $0 => '_' + $0.toLowerCase())
17 ] : [str]
18
19module.exports = multiword({
20 ok: ['true', 'assert'],
21 notOk: ['false', 'assertNot'],
22
23 error: ['ifError', 'ifErr'],
24 throws: ['throw'],
25 doesNotThrow: ['notThrow'],
26
27 // exactly the same. ===
28 equal: [
29 'equals', 'isEqual', 'is', 'strictEqual', 'strictEquals', 'strictIs',
30 'isStrict', 'isStrictly', 'identical'
31 ],
32
33 // not equal. !==
34 not: [
35 'inequal', 'notEqual', 'notEquals', 'notStrictEqual', 'notStrictEquals',
36 'isNotEqual', 'isNot', 'doesNotEqual', 'isInequal'
37 ],
38
39 // deep equivalence. == for scalars
40 same: [
41 'equivalent', 'looseEqual', 'looseEquals', 'deepEqual',
42 'deepEquals', 'isLoose', 'looseIs', 'isEquivalent'
43 ],
44
45 // deep inequivalence. != for scalars
46 notSame: [
47 'inequivalent', 'looseInequal', 'notDeep', 'deepInequal',
48 'notLoose', 'looseNot', 'notEquivalent', 'isNotDeepEqual',
49 'isNotDeeply', 'notDeepEqual', 'isInequivalent',
50 'isNotEquivalent'
51 ],
52
53 // deep equivalence, === for scalars
54 strictSame: [
55 'strictEquivalent', 'strictDeepEqual', 'sameStrict', 'deepIs',
56 'isDeeply', 'isDeep', 'strictDeepEquals'
57 ],
58
59 // deep inequivalence, !== for scalars
60 strictNotSame: [
61 'strictInequivalent', 'strictDeepInequal', 'notSameStrict', 'deepNot',
62 'notDeeply', 'strictDeepInequals', 'notStrictSame'
63 ],
64
65 // found has the fields in wanted, string matches regexp
66 match: [
67 'has', 'hasFields', 'matches', 'similar', 'like', 'isLike',
68 'includes', 'include', 'isSimilar', 'contains'
69 ],
70
71 notMatch: [
72 'dissimilar', 'unsimilar', 'notSimilar', 'unlike', 'isUnlike',
73 'notLike', 'isNotLike', 'doesNotHave', 'isNotSimilar', 'isDissimilar'
74 ],
75
76 type: [
77 'isa', 'isA'
78 ]
79})