@e22m4u/js-repository 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,54 +7,131 @@ const S = new OperatorClauseTool();
7
7
 
8
8
  describe('OperatorClauseTool', function () {
9
9
  describe('compare', function () {
10
- it('returns a negative number if a second value is greatest', function () {
11
- expect(S.compare(0, 5)).to.be.eq(-5);
12
- expect(S.compare(0, '5')).to.be.eq(-5);
13
- expect(S.compare(0, true)).to.be.eq(-1);
14
- expect(S.compare('0', 5)).to.be.eq(-5);
15
- expect(S.compare('a', 'b')).to.be.eq(-1);
16
- });
17
-
18
- it('returns a positive number if a second value is lowest', function () {
19
- expect(S.compare(5, 0)).to.be.eq(5);
20
- expect(S.compare(5, '0')).to.be.eq(5);
21
- expect(S.compare(5, false)).to.be.eq(5);
22
- expect(S.compare(5, true)).to.be.eq(4);
23
- expect(S.compare('5', 0)).to.be.eq(5);
24
- expect(S.compare('b', 'a')).to.be.eq(1);
25
- });
26
-
27
- it('returns zero if given values are equal', function () {
10
+ it('returns zero for equal values of the same type', function () {
28
11
  const obj = {};
12
+ const arr = [];
29
13
  expect(S.compare(0, 0)).to.be.eq(0);
30
- expect(S.compare(0, '0')).to.be.eq(0);
31
- expect(S.compare('0', 0)).to.be.eq(0);
32
14
  expect(S.compare('a', 'a')).to.be.eq(0);
15
+ expect(S.compare(true, true)).to.be.eq(0);
33
16
  expect(S.compare(obj, obj)).to.be.eq(0);
17
+ expect(S.compare(arr, arr)).to.be.eq(0);
34
18
  expect(S.compare(null, null)).to.be.eq(0);
35
19
  expect(S.compare(undefined, undefined)).to.be.eq(0);
36
20
  });
37
21
 
38
- it('returns NaN if we do not know how to compare', function () {
39
- expect(isNaN(S.compare(null, 'string'))).to.be.true;
40
- expect(isNaN(S.compare(null, 10))).to.be.true;
41
- expect(isNaN(S.compare([], 0))).to.be.true;
42
- expect(isNaN(S.compare([], []))).to.be.true;
43
- expect(isNaN(S.compare({}, {}))).to.be.true;
44
- expect(isNaN(S.compare(10, {}))).to.be.true;
45
- expect(isNaN(S.compare('string', Symbol()))).to.be.true;
22
+ it('returns a non-zero number for different numbers', function () {
23
+ expect(S.compare(5, 0)).to.be.eq(5);
24
+ expect(S.compare(0, 5)).to.be.eq(-5);
25
+ });
26
+
27
+ it('returns a non-zero number for different booleans', function () {
28
+ expect(S.compare(true, false)).to.be.eq(1);
29
+ expect(S.compare(false, true)).to.be.eq(-1);
30
+ });
31
+
32
+ it('returns a non-zero number for different strings', function () {
33
+ expect(S.compare('c', 'a')).to.be.eq(1);
34
+ expect(S.compare('b', 'a')).to.be.eq(1);
35
+ expect(S.compare('a', 'b')).to.be.eq(-1);
36
+ expect(S.compare('a', 'c')).to.be.eq(-1);
37
+ });
38
+
39
+ it('compares numbers and numeric strings as numbers', function () {
40
+ expect(S.compare(10, '10')).to.be.eq(0);
41
+ expect(S.compare('10', 10)).to.be.eq(0);
42
+ expect(S.compare(15, '10')).to.be.eq(5);
43
+ expect(S.compare('15', 10)).to.be.eq(5);
44
+ expect(S.compare(5, '10')).to.be.eq(-5);
45
+ expect(S.compare('5', 10)).to.be.eq(-5);
46
+ });
47
+
48
+ it('returns NaN when comparing null/undefined with other types', function () {
49
+ expect(S.compare(null, 'string')).to.be.NaN;
50
+ expect(S.compare(null, 10)).to.be.NaN;
51
+ expect(S.compare(null, 0)).to.be.NaN;
52
+ expect(S.compare(null, false)).to.be.NaN;
53
+ expect(S.compare(undefined, 'string')).to.be.NaN;
54
+ expect(S.compare(undefined, 10)).to.be.NaN;
55
+ expect(S.compare(undefined, 0)).to.be.NaN;
56
+ expect(S.compare(undefined, false)).to.be.NaN;
57
+ });
58
+
59
+ it('returns 0 for deeply equal objects', function () {
60
+ expect(S.compare({a: 1, b: {c: 2}}, {a: 1, b: {c: 2}})).to.be.eq(0);
61
+ });
62
+
63
+ it('returns NaN for different objects', function () {
64
+ expect(S.compare({a: 1}, {a: 2})).to.be.NaN;
65
+ expect(S.compare({a: 1}, {b: 1})).to.be.NaN;
66
+ });
67
+
68
+ it('returns 0 for deeply equal arrays', function () {
69
+ expect(S.compare([1, {a: 2}], [1, {a: 2}])).to.be.eq(0);
70
+ });
71
+
72
+ it('returns NaN for different arrays', function () {
73
+ expect(S.compare([1, 2], [1, 3])).to.be.NaN;
74
+ expect(S.compare([1, 2], [1, 2, 3])).to.be.NaN;
75
+ });
76
+
77
+ it('returns NaN for incomparable types', function () {
78
+ // строка (не число) и число
79
+ expect(S.compare('abc', 10)).to.be.NaN;
80
+ expect(S.compare(10, 'abc')).to.be.NaN;
81
+ // строка и булево
82
+ expect(S.compare('true', true)).to.be.NaN;
83
+ expect(S.compare(true, 'true')).to.be.NaN;
84
+ // число и объект
85
+ expect(S.compare(10, {})).to.be.NaN;
86
+ expect(S.compare({}, 10)).to.be.NaN;
87
+ // строка и символ
88
+ expect(S.compare('string', Symbol())).to.be.NaN;
89
+ // объект и массив
90
+ expect(S.compare({}, [])).to.be.NaN;
91
+ });
92
+
93
+ describe('with type conversion disabled (noTypeConversion = true)', function () {
94
+ it('returns 0 only for strictly equal primitives', function () {
95
+ expect(S.compare(10, 10, true)).to.be.eq(0);
96
+ expect(S.compare('a', 'a', true)).to.be.eq(0);
97
+ expect(S.compare(true, true, true)).to.be.eq(0);
98
+ });
99
+
100
+ it('returns NaN for different types, even if their values are equivalent', function () {
101
+ expect(S.compare(10, '10', true)).to.be.NaN;
102
+ expect(S.compare('10', 10, true)).to.be.NaN;
103
+ expect(S.compare(1, true, true)).to.be.NaN;
104
+ expect(S.compare(true, 1, true)).to.be.NaN;
105
+ expect(S.compare(0, false, true)).to.be.NaN;
106
+ });
107
+
108
+ it('returns a non-zero number for different values of the same type', function () {
109
+ expect(S.compare(10, 5, true)).to.be.greaterThan(0);
110
+ expect(S.compare('b', 'a', true)).to.be.greaterThan(0);
111
+ expect(S.compare(true, false, true)).to.be.greaterThan(0);
112
+ });
113
+
114
+ it('returns 0 for deeply equal objects and NaN for different ones', function () {
115
+ expect(S.compare({a: 1}, {a: 1}, true)).to.be.eq(0);
116
+ expect(S.compare({a: 1}, {a: 2}, true)).to.be.NaN;
117
+ });
118
+
119
+ it('returns 0 for deeply equal arrays and NaN for different ones', function () {
120
+ expect(S.compare([1, 2], [1, 2], true)).to.be.eq(0);
121
+ expect(S.compare([1, 2], [1, 3], true)).to.be.NaN;
122
+ });
46
123
  });
47
124
  });
48
125
 
49
126
  describe('testAll', function () {
50
- it('tests "eq" and "neq" operators', function () {
127
+ it('should test "eq" and "neq" operators', function () {
51
128
  expect(S.testAll({eq: 10}, 10)).to.be.true;
52
129
  expect(S.testAll({eq: 10}, 9)).to.be.false;
53
130
  expect(S.testAll({neq: 10}, 9)).to.be.true;
54
131
  expect(S.testAll({neq: 10}, 10)).to.be.false;
55
132
  });
56
133
 
57
- it('tests "gt", "gte", "lt" and "lte" operators', function () {
134
+ it('should test "gt", "gte", "lt" and "lte" operators', function () {
58
135
  expect(S.testAll({gt: 5}, 6)).to.be.true;
59
136
  expect(S.testAll({gte: 5}, 5)).to.be.true;
60
137
  expect(S.testAll({lt: 5}, 4)).to.be.true;
@@ -65,54 +142,68 @@ describe('OperatorClauseTool', function () {
65
142
  expect(S.testAll({lte: 5}, 6)).to.be.false;
66
143
  });
67
144
 
68
- it('tests a "inq" operator', function () {
145
+ it('should test the "inq" operator', function () {
69
146
  expect(S.testAll({inq: [1, 2, 3]}, 2)).to.be.true;
70
147
  expect(S.testAll({inq: [1, 2, 3]}, 'a')).to.be.false;
71
148
  });
72
149
 
73
- it('tests a "nin" operator', function () {
150
+ it('should test the "nin" operator', function () {
74
151
  expect(S.testAll({nin: [1, 2, 3]}, 'a')).to.be.true;
75
152
  expect(S.testAll({nin: [1, 2, 3]}, 2)).to.be.false;
76
153
  });
77
154
 
78
- it('tests a "between" operator', function () {
155
+ it('should test the "between" operator', function () {
79
156
  expect(S.testAll({between: [-2, 2]}, 0)).to.be.true;
80
157
  expect(S.testAll({between: [-2, 2]}, 10)).to.be.false;
81
158
  });
82
159
 
83
- it('tests an "exists" operator', function () {
160
+ it('should test the "exists" operator', function () {
84
161
  expect(S.testAll({exists: true}, 10)).to.be.true;
85
162
  expect(S.testAll({exists: false}, undefined)).to.be.true;
86
163
  expect(S.testAll({exists: true}, undefined)).to.be.false;
87
164
  expect(S.testAll({exists: false}, 10)).to.be.false;
88
165
  });
89
166
 
90
- it('tests a "like" operator', function () {
91
- expect(S.testAll({like: 'World'}, 'Hello World!')).to.be.true;
92
- expect(S.testAll({like: 'world'}, 'Hello World!')).to.be.false;
167
+ it('should test the "like" operator', function () {
168
+ expect(S.testAll({like: '%World%'}, 'Hello World!')).to.be.true;
169
+ expect(S.testAll({like: '%world%'}, 'Hello World!')).to.be.false;
93
170
  });
94
171
 
95
- it('tests a "nlike" operator', function () {
96
- expect(S.testAll({nlike: 'John'}, 'Hello World!')).to.be.true;
97
- expect(S.testAll({nlike: 'World'}, 'Hello World!')).to.be.false;
172
+ it('should test the "nlike" operator', function () {
173
+ expect(S.testAll({nlike: '%John%'}, 'Hello World!')).to.be.true;
174
+ expect(S.testAll({nlike: '%World%'}, 'Hello World!')).to.be.false;
98
175
  });
99
176
 
100
- it('tests a "ilike" operator', function () {
101
- expect(S.testAll({ilike: 'WORLD'}, 'Hello World!')).to.be.true;
102
- expect(S.testAll({ilike: 'John'}, 'Hello World!')).to.be.false;
177
+ it('should test the "ilike" operator', function () {
178
+ expect(S.testAll({ilike: '%WORLD%'}, 'Hello World!')).to.be.true;
179
+ expect(S.testAll({ilike: '%John%'}, 'Hello World!')).to.be.false;
103
180
  });
104
181
 
105
- it('tests a "nilike" operator', function () {
106
- expect(S.testAll({nilike: 'John'}, 'Hello World!')).to.be.true;
107
- expect(S.testAll({nilike: 'world'}, 'Hello World!')).to.be.false;
182
+ it('should test the "nilike" operator', function () {
183
+ expect(S.testAll({nilike: '%John%'}, 'Hello World!')).to.be.true;
184
+ expect(S.testAll({nilike: '%world%'}, 'Hello World!')).to.be.false;
108
185
  });
109
186
 
110
- it('tests a "regexp" operator', function () {
187
+ it('should test the "regexp" operator', function () {
111
188
  expect(S.testAll({regexp: 'Wo.+'}, 'Hello World!')).to.be.true;
112
189
  expect(S.testAll({regexp: 'Fo.+'}, 'Hello World!')).to.be.false;
190
+ expect(S.testAll({regexp: 'wo.+', flags: 'i'}, 'World')).to.be.true;
191
+ expect(S.testAll({regexp: 'fo.+', flags: 'i'}, 'World')).to.be.false;
113
192
  });
114
193
 
115
- it('throws an error if a first argument is not an object', function () {
194
+ it('should allow to combine operators', function () {
195
+ const clause = {gt: 20, lt: 30};
196
+ expect(S.testAll(clause, 10)).to.be.false;
197
+ expect(S.testAll(clause, 25)).to.be.true;
198
+ expect(S.testAll(clause, 40)).to.be.false;
199
+ });
200
+
201
+ it('should return undefined for an empty clause or non-operator key', function () {
202
+ expect(S.testAll({}, 'value')).to.be.undefined;
203
+ expect(S.testAll({foo: 'bar'}, 'value')).to.be.undefined;
204
+ });
205
+
206
+ it('should throws an error if a first argument is not an object', function () {
116
207
  const throwable = () => S.testAll(10);
117
208
  expect(throwable).to.throw(
118
209
  'The first argument of OperatorUtils.testAll ' +
@@ -138,9 +229,7 @@ describe('OperatorClauseTool', function () {
138
229
  describe('eq', function () {
139
230
  it('returns true if a given value is equal to reference', function () {
140
231
  expect(S.testEqNeq({eq: 0}, 0)).to.be.true;
141
- expect(S.testEqNeq({eq: 0}, '0')).to.be.true;
142
- expect(S.testEqNeq({eq: 0}, false)).to.be.true;
143
- expect(S.testEqNeq({eq: 1}, true)).to.be.true;
232
+ expect(S.testEqNeq({eq: 1}, 1)).to.be.true;
144
233
  expect(S.testEqNeq({eq: 'a'}, 'a')).to.be.true;
145
234
  expect(S.testEqNeq({eq: true}, true)).to.be.true;
146
235
  expect(S.testEqNeq({eq: false}, false)).to.be.true;
@@ -150,6 +239,8 @@ describe('OperatorClauseTool', function () {
150
239
  });
151
240
 
152
241
  it('returns false if a given value is not-equal to reference', function () {
242
+ expect(S.testEqNeq({eq: 0}, '0')).to.be.false;
243
+ expect(S.testEqNeq({eq: 0}, false)).to.be.false;
153
244
  expect(S.testEqNeq({eq: 0}, 1)).to.be.false;
154
245
  expect(S.testEqNeq({eq: 0}, '1')).to.be.false;
155
246
  expect(S.testEqNeq({eq: 0}, true)).to.be.false;
@@ -161,6 +252,18 @@ describe('OperatorClauseTool', function () {
161
252
  expect(S.testEqNeq({eq: '0'}, Infinity)).to.be.false;
162
253
  expect(S.testEqNeq({eq: '0'}, null)).to.be.false;
163
254
  expect(S.testEqNeq({eq: '0'}, undefined)).to.be.false;
255
+ expect(S.testEqNeq({eq: 1}, '0')).to.be.false;
256
+ expect(S.testEqNeq({eq: 1}, false)).to.be.false;
257
+ expect(S.testEqNeq({eq: 1}, '1')).to.be.false;
258
+ expect(S.testEqNeq({eq: 1}, true)).to.be.false;
259
+ expect(S.testEqNeq({eq: 1}, Infinity)).to.be.false;
260
+ expect(S.testEqNeq({eq: 1}, null)).to.be.false;
261
+ expect(S.testEqNeq({eq: 1}, undefined)).to.be.false;
262
+ expect(S.testEqNeq({eq: '1'}, '0')).to.be.false;
263
+ expect(S.testEqNeq({eq: '1'}, true)).to.be.false;
264
+ expect(S.testEqNeq({eq: '1'}, Infinity)).to.be.false;
265
+ expect(S.testEqNeq({eq: '1'}, null)).to.be.false;
266
+ expect(S.testEqNeq({eq: '1'}, undefined)).to.be.false;
164
267
  expect(S.testEqNeq({eq: true}, false)).to.be.false;
165
268
  expect(S.testEqNeq({eq: true}, null)).to.be.false;
166
269
  expect(S.testEqNeq({eq: true}, undefined)).to.be.false;
@@ -168,14 +271,25 @@ describe('OperatorClauseTool', function () {
168
271
  expect(S.testEqNeq({eq: false}, null)).to.be.false;
169
272
  expect(S.testEqNeq({eq: false}, undefined)).to.be.false;
170
273
  });
274
+
275
+ it('returns true for deeply equal objects and arrays', function () {
276
+ expect(S.testEqNeq({eq: {a: 1, b: {c: 2}}}, {a: 1, b: {c: 2}})).to.be
277
+ .true;
278
+ expect(S.testEqNeq({eq: [1, {a: 2}]}, [1, {a: 2}])).to.be.true;
279
+ });
280
+
281
+ it('returns false for different objects and arrays', function () {
282
+ expect(S.testEqNeq({eq: {a: 1}}, {a: 2})).to.be.false;
283
+ expect(S.testEqNeq({eq: {a: 1}}, {b: 1})).to.be.false;
284
+ expect(S.testEqNeq({eq: [1, 2]}, [1, 3])).to.be.false;
285
+ expect(S.testEqNeq({eq: [1, 2]}, [1, 2, 3])).to.be.false;
286
+ });
171
287
  });
172
288
 
173
289
  describe('neq', function () {
174
- it('returns false if a given value is strictly equal to reference', function () {
290
+ it('returns false if a given value is equal to reference', function () {
175
291
  expect(S.testEqNeq({neq: 0}, 0)).to.be.false;
176
- expect(S.testEqNeq({neq: 0}, '0')).to.be.false;
177
- expect(S.testEqNeq({neq: 0}, false)).to.be.false;
178
- expect(S.testEqNeq({neq: 1}, true)).to.be.false;
292
+ expect(S.testEqNeq({neq: 1}, 1)).to.be.false;
179
293
  expect(S.testEqNeq({neq: 'a'}, 'a')).to.be.false;
180
294
  expect(S.testEqNeq({neq: true}, true)).to.be.false;
181
295
  expect(S.testEqNeq({neq: false}, false)).to.be.false;
@@ -184,7 +298,9 @@ describe('OperatorClauseTool', function () {
184
298
  expect(S.testEqNeq({neq: undefined}, undefined)).to.be.false;
185
299
  });
186
300
 
187
- it('returns true if a given value is strictly not-equal to reference', function () {
301
+ it('returns true if a given value is not-equal to reference', function () {
302
+ expect(S.testEqNeq({neq: 0}, '0')).to.be.true;
303
+ expect(S.testEqNeq({neq: 0}, false)).to.be.true;
188
304
  expect(S.testEqNeq({neq: 0}, 1)).to.be.true;
189
305
  expect(S.testEqNeq({neq: 0}, '1')).to.be.true;
190
306
  expect(S.testEqNeq({neq: 0}, true)).to.be.true;
@@ -196,6 +312,18 @@ describe('OperatorClauseTool', function () {
196
312
  expect(S.testEqNeq({neq: '0'}, Infinity)).to.be.true;
197
313
  expect(S.testEqNeq({neq: '0'}, null)).to.be.true;
198
314
  expect(S.testEqNeq({neq: '0'}, undefined)).to.be.true;
315
+ expect(S.testEqNeq({neq: 1}, '0')).to.be.true;
316
+ expect(S.testEqNeq({neq: 1}, false)).to.be.true;
317
+ expect(S.testEqNeq({neq: 1}, '1')).to.be.true;
318
+ expect(S.testEqNeq({neq: 1}, true)).to.be.true;
319
+ expect(S.testEqNeq({neq: 1}, Infinity)).to.be.true;
320
+ expect(S.testEqNeq({neq: 1}, null)).to.be.true;
321
+ expect(S.testEqNeq({neq: 1}, undefined)).to.be.true;
322
+ expect(S.testEqNeq({neq: '1'}, '0')).to.be.true;
323
+ expect(S.testEqNeq({neq: '1'}, true)).to.be.true;
324
+ expect(S.testEqNeq({neq: '1'}, Infinity)).to.be.true;
325
+ expect(S.testEqNeq({neq: '1'}, null)).to.be.true;
326
+ expect(S.testEqNeq({neq: '1'}, undefined)).to.be.true;
199
327
  expect(S.testEqNeq({neq: true}, false)).to.be.true;
200
328
  expect(S.testEqNeq({neq: true}, null)).to.be.true;
201
329
  expect(S.testEqNeq({neq: true}, undefined)).to.be.true;
@@ -203,6 +331,19 @@ describe('OperatorClauseTool', function () {
203
331
  expect(S.testEqNeq({neq: false}, null)).to.be.true;
204
332
  expect(S.testEqNeq({neq: false}, undefined)).to.be.true;
205
333
  });
334
+
335
+ it('returns false for deeply equal objects and arrays', function () {
336
+ expect(S.testEqNeq({neq: {a: 1, b: {c: 2}}}, {a: 1, b: {c: 2}})).to.be
337
+ .false;
338
+ expect(S.testEqNeq({neq: [1, {a: 2}]}, [1, {a: 2}])).to.be.false;
339
+ });
340
+
341
+ it('returns true for different objects and arrays', function () {
342
+ expect(S.testEqNeq({neq: {a: 1}}, {a: 2})).to.be.true;
343
+ expect(S.testEqNeq({neq: {a: 1}}, {b: 1})).to.be.true;
344
+ expect(S.testEqNeq({neq: [1, 2]}, [1, 3])).to.be.true;
345
+ expect(S.testEqNeq({neq: [1, 2]}, [1, 2, 3])).to.be.true;
346
+ });
206
347
  });
207
348
  });
208
349
 
@@ -373,18 +514,40 @@ describe('OperatorClauseTool', function () {
373
514
 
374
515
  it('returns true if a given value has in array', function () {
375
516
  expect(S.testInq({inq: [1, 2]}, 2)).to.be.true;
376
- expect(S.testInq({inq: [1, 2]}, '2')).to.be.true;
377
517
  expect(S.testInq({inq: ['a', 'b']}, 'b')).to.be.true;
378
- expect(S.testInq({inq: [1, 2]}, true)).to.be.true;
379
- expect(S.testInq({inq: [-1, 0]}, false)).to.be.true;
380
518
  });
381
519
 
382
520
  it('returns false if a given value is not in array', function () {
383
521
  expect(S.testInq({inq: [1, 2]}, 3)).to.be.false;
522
+ expect(S.testInq({inq: [1, 2]}, '2')).to.be.false;
384
523
  expect(S.testInq({inq: [1, 2]}, '3')).to.be.false;
385
524
  expect(S.testInq({inq: ['a', 'b']}, 'c')).to.be.false;
386
- expect(S.testInq({inq: [-1, 0]}, true)).to.be.false;
525
+ expect(S.testInq({inq: [1, 2]}, true)).to.be.false;
387
526
  expect(S.testInq({inq: [1, 2]}, false)).to.be.false;
527
+ expect(S.testInq({inq: [-1, 0]}, true)).to.be.false;
528
+ expect(S.testInq({inq: [-1, 0]}, false)).to.be.false;
529
+ });
530
+
531
+ it('returns true if a given object is deeply equal to an element in the array', function () {
532
+ const clause = {inq: [{a: 1}, {b: 2}]};
533
+ expect(S.testInq(clause, {a: 1})).to.be.true;
534
+ });
535
+
536
+ it('returns false if a given object is not deeply equal to any element in the array', function () {
537
+ const clause = {inq: [{a: 1}, {b: 2}]};
538
+ expect(S.testInq(clause, {c: 3})).to.be.false;
539
+ });
540
+
541
+ it('returns true if a given array is deeply equal to an element in the array', function () {
542
+ // prettier-ignore
543
+ const clause = {inq: [[1, 2], [3, 4]]};
544
+ expect(S.testInq(clause, [1, 2])).to.be.true;
545
+ });
546
+
547
+ it('returns false if a given array is not deeply equal to any element in the array', function () {
548
+ // prettier-ignore
549
+ const clause = {inq: [[1, 2], [3, 4]]};
550
+ expect(S.testInq(clause, [5, 6])).to.be.false;
388
551
  });
389
552
 
390
553
  it('throws an error if a first argument is not an object', function () {
@@ -428,20 +591,43 @@ describe('OperatorClauseTool', function () {
428
591
 
429
592
  it('returns false if a given value has in array', function () {
430
593
  expect(S.testNin({nin: [1, 2]}, 2)).to.be.false;
431
- expect(S.testNin({nin: [1, 2]}, '2')).to.be.false;
594
+
432
595
  expect(S.testNin({nin: ['a', 'b']}, 'b')).to.be.false;
433
- expect(S.testNin({nin: [1, 2]}, true)).to.be.false;
434
- expect(S.testNin({nin: [-1, 0]}, false)).to.be.false;
435
596
  });
436
597
 
437
598
  it('returns true if a given value is not in array', function () {
438
599
  expect(S.testNin({nin: [1, 2]}, 3)).to.be.true;
600
+ expect(S.testNin({nin: [1, 2]}, '2')).to.be.true;
439
601
  expect(S.testNin({nin: [1, 2]}, '3')).to.be.true;
440
602
  expect(S.testNin({nin: ['a', 'b']}, 'c')).to.be.true;
441
603
  expect(S.testNin({nin: [-1, 0]}, true)).to.be.true;
604
+ expect(S.testNin({nin: [-1, 0]}, false)).to.be.true;
605
+ expect(S.testNin({nin: [1, 2]}, true)).to.be.true;
442
606
  expect(S.testNin({nin: [1, 2]}, false)).to.be.true;
443
607
  });
444
608
 
609
+ it('returns false if a given object is deeply equal to an element in the array', function () {
610
+ const clause = {nin: [{a: 1}, {b: 2}]};
611
+ expect(S.testNin(clause, {a: 1})).to.be.false;
612
+ });
613
+
614
+ it('returns true if a given object is not deeply equal to any element in the array', function () {
615
+ const clause = {nin: [{a: 1}, {b: 2}]};
616
+ expect(S.testNin(clause, {c: 3})).to.be.true;
617
+ });
618
+
619
+ it('returns false if a given array is deeply equal to an element in the array', function () {
620
+ // prettier-ignore
621
+ const clause = {nin: [[1, 2], [3, 4]]};
622
+ expect(S.testNin(clause, [1, 2])).to.be.false;
623
+ });
624
+
625
+ it('returns true if a given array is not deeply equal to any element in the array', function () {
626
+ // prettier-ignore
627
+ const clause = {nin: [[1, 2], [3, 4]]};
628
+ expect(S.testNin(clause, [5, 6])).to.be.true;
629
+ });
630
+
445
631
  it('throws an error if a first argument is not an object', function () {
446
632
  const throwable = () => S.testNin(10);
447
633
  expect(throwable).to.throw(
@@ -640,318 +826,377 @@ describe('OperatorClauseTool', function () {
640
826
  });
641
827
 
642
828
  describe('testLike', function () {
643
- it('returns undefined if no operator given', function () {
829
+ it('should return undefined if no operator given', function () {
644
830
  const result = S.testLike({}, 'value');
645
831
  expect(result).to.be.undefined;
646
832
  });
647
833
 
648
- it('returns true if a given value matches a substring', function () {
649
- expect(S.testLike({like: 'val'}, 'value')).to.be.true;
650
- expect(S.testLike({like: 'lue'}, 'value')).to.be.true;
651
- expect(S.testLike({like: 'value'}, 'value')).to.be.true;
834
+ it('should return false when matching by substring', function () {
835
+ expect(S.testLike({like: 'val'}, 'value')).to.be.false;
836
+ expect(S.testLike({like: 'lue'}, 'value')).to.be.false;
837
+ expect(S.testLike({like: 'alu'}, 'value')).to.be.false;
652
838
  });
653
839
 
654
- it('returns false if a given value not matches a substring', function () {
840
+ it('should return false when the value is a substring', function () {
655
841
  expect(S.testLike({like: 'value'}, 'val')).to.be.false;
656
842
  expect(S.testLike({like: 'value'}, 'lue')).to.be.false;
657
- expect(S.testLike({like: 'value'}, 'foo')).to.be.false;
658
- });
659
-
660
- it('uses case-sensitive matching for a substring', function () {
661
- expect(S.testLike({like: 'Val'}, 'value')).to.be.false;
662
- expect(S.testLike({like: 'Val'}, 'Value')).to.be.true;
663
- expect(S.testLike({like: 'val'}, 'Value')).to.be.false;
664
- });
665
-
666
- it('returns true if a given value matches a string expression', function () {
667
- expect(S.testLike({like: 'val.+'}, 'value')).to.be.true;
668
- });
669
-
670
- it('returns false if a given value not matches a string expression', function () {
671
- expect(S.testLike({like: 'foo.+'}, 'value')).to.be.false;
672
- });
673
-
674
- it('uses case-sensitive matching for a string expression', function () {
675
- expect(S.testLike({like: 'Val.+'}, 'value')).to.be.false;
676
- expect(S.testLike({like: 'Val.+'}, 'Value')).to.be.true;
677
- expect(S.testLike({like: 'val.+'}, 'Value')).to.be.false;
678
- });
679
-
680
- it('returns true if a given value matches a RegExp', function () {
681
- expect(S.testLike({like: new RegExp(/val.+/)}, 'value')).to.be.true;
843
+ expect(S.testLike({like: 'value'}, 'alu')).to.be.false;
682
844
  });
683
845
 
684
- it('returns false if a given value matches a RegExp', function () {
685
- expect(S.testLike({like: new RegExp(/foo.+/)}, 'value')).to.be.false;
686
- });
687
-
688
- it('uses case-sensitive matching for a RegExp', function () {
689
- expect(S.testLike({like: new RegExp(/Val.+/)}, 'value')).to.be.false;
690
- expect(S.testLike({like: new RegExp(/Val.+/)}, 'Value')).to.be.true;
691
- expect(S.testLike({like: new RegExp(/val.+/)}, 'Value')).to.be.false;
692
- });
693
-
694
- it('throws an error if a first argument is not an object', function () {
695
- const throwable = () => S.testLike(10);
696
- expect(throwable).to.throw(
697
- 'The first argument of OperatorUtils.testLike ' +
698
- 'should be an Object, but 10 was given.',
699
- );
700
- });
701
-
702
- it('throws an error if an operator value is a number', function () {
703
- const like = 10;
704
- const throwable = () => S.testLike({like}, 10);
705
- expect(throwable).to.throw(InvalidOperatorValueError);
706
- });
707
-
708
- it('throws an error if an operator value is an object', function () {
709
- const like = {};
710
- const throwable = () => S.testLike({like}, 10);
711
- expect(throwable).to.throw(InvalidOperatorValueError);
846
+ it('should return true for exact match', function () {
847
+ expect(S.testLike({like: 'value'}, 'value')).to.be.true;
712
848
  });
713
849
 
714
- it('throws an error if an operator value is a null', function () {
715
- const like = null;
716
- const throwable = () => S.testLike({like}, 10);
717
- expect(throwable).to.throw(InvalidOperatorValueError);
850
+ it('should use case-sensitive matching', function () {
851
+ expect(S.testLike({like: 'VALUE'}, 'VALUE')).to.be.true;
852
+ expect(S.testLike({like: 'VALUE'}, 'value')).to.be.false;
853
+ expect(S.testLike({like: 'value'}, 'VALUE')).to.be.false;
854
+ });
855
+
856
+ it('should handle "%" wildcard as zero or more characters', function () {
857
+ expect(S.testLike({like: 'hello wo%'}, 'hello world today')).to.be.true;
858
+ expect(S.testLike({like: '%ld today'}, 'hello world today')).to.be.true;
859
+ expect(S.testLike({like: '%world%'}, 'hello world today')).to.be.true;
860
+ expect(S.testLike({like: '%hello wo%'}, 'hello world today')).to.be.true;
861
+ expect(S.testLike({like: '%ld today%'}, 'hello world today')).to.be.true;
862
+ expect(S.testLike({like: '%wurld%'}, 'hello world today')).to.be.false;
863
+ });
864
+
865
+ it('should handle "_" wildcard as any characters', function () {
866
+ expect(S.testLike({like: 'h_ll_'}, 'hello')).to.be.true;
867
+ expect(S.testLike({like: 'hello_world'}, 'hello world')).to.be.true;
868
+ expect(S.testLike({like: 'hello_'}, 'hello')).to.be.false;
869
+ expect(S.testLike({like: '_hello'}, 'hello')).to.be.false;
870
+ });
871
+
872
+ it('should throw an error for non-object clause', function () {
873
+ const throwable = v => () => {
874
+ S.testLike(v);
875
+ };
876
+ const error = s =>
877
+ format(
878
+ 'The first argument of OperatorUtils.testLike ' +
879
+ 'should be an Object, but %s was given.',
880
+ s,
881
+ );
882
+ expect(throwable('str')).to.throw(error('"str"'));
883
+ expect(throwable('')).to.throw(error('""'));
884
+ expect(throwable(10)).to.throw(error('10'));
885
+ expect(throwable(0)).to.throw(error('0'));
886
+ expect(throwable(true)).to.throw(error('true'));
887
+ expect(throwable(false)).to.throw(error('false'));
888
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
889
+ expect(throwable([])).to.throw(error('Array'));
890
+ expect(throwable(() => undefined)).to.throw(error('Function'));
891
+ throwable({})();
892
+ });
893
+
894
+ it('should throw an error for non-string operator value', function () {
895
+ const throwable = v => () => {
896
+ S.testLike({like: v});
897
+ };
898
+ const error = s =>
899
+ format(
900
+ 'Condition of {like: ...} should have a String, but %s was given.',
901
+ s,
902
+ );
903
+ expect(throwable(10)).to.throw(error('10'));
904
+ expect(throwable(0)).to.throw(error('0'));
905
+ expect(throwable(true)).to.throw(error('true'));
906
+ expect(throwable(false)).to.throw(error('false'));
907
+ expect(throwable({foo: 'bar'})).to.throw(error('Object'));
908
+ expect(throwable({})).to.throw(error('Object'));
909
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
910
+ expect(throwable([])).to.throw(error('Array'));
911
+ expect(throwable(() => undefined)).to.throw(error('Function'));
912
+ expect(throwable(new RegExp())).to.throw(error('RegExp (instance)'));
913
+ throwable('str')();
914
+ throwable(null);
915
+ throwable(undefined);
718
916
  });
719
917
  });
720
918
 
721
919
  describe('testNlike', function () {
722
- it('returns undefined if no operator given', function () {
920
+ it('should return undefined if no operator given', function () {
723
921
  const result = S.testNlike({}, 'value');
724
922
  expect(result).to.be.undefined;
725
923
  });
726
924
 
727
- it('returns false if a given value matches a substring', function () {
728
- expect(S.testNlike({nlike: 'val'}, 'value')).to.be.false;
729
- expect(S.testNlike({nlike: 'lue'}, 'value')).to.be.false;
730
- expect(S.testNlike({nlike: 'value'}, 'value')).to.be.false;
925
+ it('should return true when matching by substring', function () {
926
+ expect(S.testNlike({nlike: 'val'}, 'value')).to.be.true;
927
+ expect(S.testNlike({nlike: 'lue'}, 'value')).to.be.true;
928
+ expect(S.testNlike({nlike: 'alu'}, 'value')).to.be.true;
731
929
  });
732
930
 
733
- it('returns true if a given value not matches a substring', function () {
931
+ it('should return true when the value is a substring', function () {
734
932
  expect(S.testNlike({nlike: 'value'}, 'val')).to.be.true;
735
933
  expect(S.testNlike({nlike: 'value'}, 'lue')).to.be.true;
736
- expect(S.testNlike({nlike: 'value'}, 'foo')).to.be.true;
737
- });
738
-
739
- it('uses case-sensitive matching for a substring', function () {
740
- expect(S.testNlike({nlike: 'Val'}, 'value')).to.be.true;
741
- expect(S.testNlike({nlike: 'Val'}, 'Value')).to.be.false;
742
- expect(S.testNlike({nlike: 'val'}, 'Value')).to.be.true;
743
- });
744
-
745
- it('returns false if a given value matches a string expression', function () {
746
- expect(S.testNlike({nlike: 'val.+'}, 'value')).to.be.false;
747
- });
748
-
749
- it('returns true if a given value not matches a string expression', function () {
750
- expect(S.testNlike({nlike: 'foo.+'}, 'value')).to.be.true;
751
- });
752
-
753
- it('uses case-sensitive matching for a string expression', function () {
754
- expect(S.testNlike({nlike: 'Val.+'}, 'value')).to.be.true;
755
- expect(S.testNlike({nlike: 'Val.+'}, 'Value')).to.be.false;
756
- expect(S.testNlike({nlike: 'val.+'}, 'Value')).to.be.true;
757
- });
758
-
759
- it('returns false if a given value matches a RegExp', function () {
760
- expect(S.testNlike({nlike: new RegExp(/val.+/)}, 'value')).to.be.false;
934
+ expect(S.testNlike({nlike: 'value'}, 'alu')).to.be.true;
761
935
  });
762
936
 
763
- it('returns true if a given value matches a RegExp', function () {
764
- expect(S.testNlike({nlike: new RegExp(/foo.+/)}, 'value')).to.be.true;
765
- });
766
-
767
- it('uses case-sensitive matching for a RegExp', function () {
768
- expect(S.testNlike({nlike: new RegExp(/Val.+/)}, 'value')).to.be.true;
769
- expect(S.testNlike({nlike: new RegExp(/Val.+/)}, 'Value')).to.be.false;
770
- expect(S.testNlike({nlike: new RegExp(/val.+/)}, 'Value')).to.be.true;
771
- });
772
-
773
- it('throws an error if a first argument is not an object', function () {
774
- const throwable = () => S.testNlike(10);
775
- expect(throwable).to.throw(
776
- 'The first argument of OperatorUtils.testNlike ' +
777
- 'should be an Object, but 10 was given.',
778
- );
779
- });
780
-
781
- it('throws an error if an operator value is a number', function () {
782
- const nlike = 10;
783
- const throwable = () => S.testNlike({nlike}, 10);
784
- expect(throwable).to.throw(InvalidOperatorValueError);
785
- });
786
-
787
- it('throws an error if an operator value is an object', function () {
788
- const nlike = {};
789
- const throwable = () => S.testNlike({nlike}, 10);
790
- expect(throwable).to.throw(InvalidOperatorValueError);
937
+ it('should return true for exact match', function () {
938
+ expect(S.testNlike({nlike: 'value'}, 'value')).to.be.false;
791
939
  });
792
940
 
793
- it('throws an error if an operator value is a null', function () {
794
- const nlike = null;
795
- const throwable = () => S.testNlike({nlike}, 10);
796
- expect(throwable).to.throw(InvalidOperatorValueError);
941
+ it('should use case-sensitive matching', function () {
942
+ expect(S.testNlike({nlike: 'VALUE'}, 'VALUE')).to.be.false;
943
+ expect(S.testNlike({nlike: 'VALUE'}, 'value')).to.be.true;
944
+ expect(S.testNlike({nlike: 'value'}, 'VALUE')).to.be.true;
945
+ });
946
+
947
+ it('should handle "%" wildcard as zero or more characters', function () {
948
+ expect(S.testNlike({nlike: 'hello wo%'}, 'hello world today')).to.be
949
+ .false;
950
+ expect(S.testNlike({nlike: '%ld today'}, 'hello world today')).to.be
951
+ .false;
952
+ expect(S.testNlike({nlike: '%world%'}, 'hello world today')).to.be.false;
953
+ expect(S.testNlike({nlike: '%hello wo%'}, 'hello world today')).to.be
954
+ .false;
955
+ expect(S.testNlike({nlike: '%ld today%'}, 'hello world today')).to.be
956
+ .false;
957
+ expect(S.testNlike({nlike: '%wurld%'}, 'hello world today')).to.be.true;
958
+ });
959
+
960
+ it('should handle "_" wildcard as any characters', function () {
961
+ expect(S.testNlike({nlike: 'h_ll_'}, 'hello')).to.be.false;
962
+ expect(S.testNlike({nlike: 'hello_world'}, 'hello world')).to.be.false;
963
+ expect(S.testNlike({nlike: 'hello_'}, 'hello')).to.be.true;
964
+ expect(S.testNlike({nlike: '_hello'}, 'hello')).to.be.true;
965
+ });
966
+
967
+ it('should throw an error for non-object clause', function () {
968
+ const throwable = v => () => {
969
+ S.testNlike(v);
970
+ };
971
+ const error = s =>
972
+ format(
973
+ 'The first argument of OperatorUtils.testNlike ' +
974
+ 'should be an Object, but %s was given.',
975
+ s,
976
+ );
977
+ expect(throwable('str')).to.throw(error('"str"'));
978
+ expect(throwable('')).to.throw(error('""'));
979
+ expect(throwable(10)).to.throw(error('10'));
980
+ expect(throwable(0)).to.throw(error('0'));
981
+ expect(throwable(true)).to.throw(error('true'));
982
+ expect(throwable(false)).to.throw(error('false'));
983
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
984
+ expect(throwable([])).to.throw(error('Array'));
985
+ expect(throwable(() => undefined)).to.throw(error('Function'));
986
+ throwable({})();
987
+ });
988
+
989
+ it('should throw an error for non-string operator value', function () {
990
+ const throwable = v => () => {
991
+ S.testNlike({nlike: v});
992
+ };
993
+ const error = s =>
994
+ format(
995
+ 'Condition of {nlike: ...} should have a String, but %s was given.',
996
+ s,
997
+ );
998
+ expect(throwable(10)).to.throw(error('10'));
999
+ expect(throwable(0)).to.throw(error('0'));
1000
+ expect(throwable(true)).to.throw(error('true'));
1001
+ expect(throwable(false)).to.throw(error('false'));
1002
+ expect(throwable({foo: 'bar'})).to.throw(error('Object'));
1003
+ expect(throwable({})).to.throw(error('Object'));
1004
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
1005
+ expect(throwable([])).to.throw(error('Array'));
1006
+ expect(throwable(() => undefined)).to.throw(error('Function'));
1007
+ expect(throwable(new RegExp())).to.throw(error('RegExp (instance)'));
1008
+ throwable('str')();
1009
+ throwable(null);
1010
+ throwable(undefined);
797
1011
  });
798
1012
  });
799
1013
 
800
1014
  describe('testIlike', function () {
801
- it('returns undefined if no operator given', function () {
1015
+ it('should return undefined if no operator given', function () {
802
1016
  const result = S.testIlike({}, 'value');
803
1017
  expect(result).to.be.undefined;
804
1018
  });
805
1019
 
806
- it('returns true if a given value matches a substring', function () {
807
- expect(S.testIlike({ilike: 'val'}, 'value')).to.be.true;
808
- expect(S.testIlike({ilike: 'lue'}, 'value')).to.be.true;
809
- expect(S.testIlike({ilike: 'value'}, 'value')).to.be.true;
1020
+ it('should return false when matching by substring', function () {
1021
+ expect(S.testIlike({ilike: 'val'}, 'value')).to.be.false;
1022
+ expect(S.testIlike({ilike: 'lue'}, 'value')).to.be.false;
1023
+ expect(S.testIlike({ilike: 'alu'}, 'value')).to.be.false;
810
1024
  });
811
1025
 
812
- it('returns false if a given value not matches a substring', function () {
1026
+ it('should return false when the value is a substring', function () {
813
1027
  expect(S.testIlike({ilike: 'value'}, 'val')).to.be.false;
814
1028
  expect(S.testIlike({ilike: 'value'}, 'lue')).to.be.false;
815
- expect(S.testIlike({ilike: 'value'}, 'foo')).to.be.false;
816
- });
817
-
818
- it('uses case-insensitive matching for a substring', function () {
819
- expect(S.testIlike({ilike: 'Val'}, 'value')).to.be.true;
820
- expect(S.testIlike({ilike: 'Val'}, 'Value')).to.be.true;
821
- expect(S.testIlike({ilike: 'val'}, 'Value')).to.be.true;
822
- });
823
-
824
- it('returns true if a given value matches a string expression', function () {
825
- expect(S.testIlike({ilike: 'val.+'}, 'value')).to.be.true;
826
- });
827
-
828
- it('returns false if a given value not matches a string expression', function () {
829
- expect(S.testIlike({ilike: 'foo.+'}, 'value')).to.be.false;
830
- });
831
-
832
- it('uses case-insensitive matching for a string expression', function () {
833
- expect(S.testIlike({ilike: 'Val.+'}, 'value')).to.be.true;
834
- expect(S.testIlike({ilike: 'Val.+'}, 'Value')).to.be.true;
835
- expect(S.testIlike({ilike: 'val.+'}, 'Value')).to.be.true;
836
- });
837
-
838
- it('returns true if a given value matches a RegExp', function () {
839
- expect(S.testIlike({ilike: new RegExp(/val.+/)}, 'value')).to.be.true;
840
- });
841
-
842
- it('returns false if a given value matches a RegExp', function () {
843
- expect(S.testIlike({ilike: new RegExp(/foo.+/)}, 'value')).to.be.false;
844
- });
845
-
846
- it('uses case-insensitive matching for a RegExp', function () {
847
- expect(S.testIlike({ilike: new RegExp(/Val.+/)}, 'value')).to.be.true;
848
- expect(S.testIlike({ilike: new RegExp(/Val.+/)}, 'Value')).to.be.true;
849
- expect(S.testIlike({ilike: new RegExp(/val.+/)}, 'Value')).to.be.true;
1029
+ expect(S.testIlike({ilike: 'value'}, 'alu')).to.be.false;
850
1030
  });
851
1031
 
852
- it('throws an error if a first argument is not an object', function () {
853
- const throwable = () => S.testIlike(10);
854
- expect(throwable).to.throw(
855
- 'The first argument of OperatorUtils.testIlike ' +
856
- 'should be an Object, but 10 was given.',
857
- );
858
- });
859
-
860
- it('throws an error if an operator value is a number', function () {
861
- const ilike = 10;
862
- const throwable = () => S.testIlike({ilike}, 10);
863
- expect(throwable).to.throw(InvalidOperatorValueError);
864
- });
865
-
866
- it('throws an error if an operator value is an object', function () {
867
- const ilike = {};
868
- const throwable = () => S.testIlike({ilike}, 10);
869
- expect(throwable).to.throw(InvalidOperatorValueError);
1032
+ it('should return true for exact match', function () {
1033
+ expect(S.testIlike({ilike: 'value'}, 'value')).to.be.true;
870
1034
  });
871
1035
 
872
- it('throws an error if an operator value is a null', function () {
873
- const ilike = null;
874
- const throwable = () => S.testIlike({ilike}, 10);
875
- expect(throwable).to.throw(InvalidOperatorValueError);
1036
+ it('should use case-insensitive matching', function () {
1037
+ expect(S.testIlike({ilike: 'VALUE'}, 'VALUE')).to.be.true;
1038
+ expect(S.testIlike({ilike: 'VALUE'}, 'value')).to.be.true;
1039
+ expect(S.testIlike({ilike: 'value'}, 'VALUE')).to.be.true;
1040
+ });
1041
+
1042
+ it('should handle "%" wildcard as zero or more characters', function () {
1043
+ expect(S.testIlike({ilike: 'hello wo%'}, 'hello world today')).to.be.true;
1044
+ expect(S.testIlike({ilike: '%ld today'}, 'hello world today')).to.be.true;
1045
+ expect(S.testIlike({ilike: '%world%'}, 'hello world today')).to.be.true;
1046
+ expect(S.testIlike({ilike: '%hello wo%'}, 'hello world today')).to.be
1047
+ .true;
1048
+ expect(S.testIlike({ilike: '%ld today%'}, 'hello world today')).to.be
1049
+ .true;
1050
+ expect(S.testIlike({ilike: '%wurld%'}, 'hello world today')).to.be.false;
1051
+ });
1052
+
1053
+ it('should handle "_" wildcard as any characters', function () {
1054
+ expect(S.testIlike({ilike: 'h_ll_'}, 'hello')).to.be.true;
1055
+ expect(S.testIlike({ilike: 'hello_world'}, 'hello world')).to.be.true;
1056
+ expect(S.testIlike({ilike: 'hello_'}, 'hello')).to.be.false;
1057
+ expect(S.testIlike({ilike: '_hello'}, 'hello')).to.be.false;
1058
+ });
1059
+
1060
+ it('should throw an error for non-object clause', function () {
1061
+ const throwable = v => () => {
1062
+ S.testIlike(v);
1063
+ };
1064
+ const error = s =>
1065
+ format(
1066
+ 'The first argument of OperatorUtils.testIlike ' +
1067
+ 'should be an Object, but %s was given.',
1068
+ s,
1069
+ );
1070
+ expect(throwable('str')).to.throw(error('"str"'));
1071
+ expect(throwable('')).to.throw(error('""'));
1072
+ expect(throwable(10)).to.throw(error('10'));
1073
+ expect(throwable(0)).to.throw(error('0'));
1074
+ expect(throwable(true)).to.throw(error('true'));
1075
+ expect(throwable(false)).to.throw(error('false'));
1076
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
1077
+ expect(throwable([])).to.throw(error('Array'));
1078
+ expect(throwable(() => undefined)).to.throw(error('Function'));
1079
+ throwable({})();
1080
+ });
1081
+
1082
+ it('should throw an error for non-string operator value', function () {
1083
+ const throwable = v => () => {
1084
+ S.testIlike({ilike: v});
1085
+ };
1086
+ const error = s =>
1087
+ format(
1088
+ 'Condition of {ilike: ...} should have a String, but %s was given.',
1089
+ s,
1090
+ );
1091
+ expect(throwable(10)).to.throw(error('10'));
1092
+ expect(throwable(0)).to.throw(error('0'));
1093
+ expect(throwable(true)).to.throw(error('true'));
1094
+ expect(throwable(false)).to.throw(error('false'));
1095
+ expect(throwable({foo: 'bar'})).to.throw(error('Object'));
1096
+ expect(throwable({})).to.throw(error('Object'));
1097
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
1098
+ expect(throwable([])).to.throw(error('Array'));
1099
+ expect(throwable(() => undefined)).to.throw(error('Function'));
1100
+ expect(throwable(new RegExp())).to.throw(error('RegExp (instance)'));
1101
+ throwable('str')();
1102
+ throwable(null);
1103
+ throwable(undefined);
876
1104
  });
877
1105
  });
878
1106
 
879
1107
  describe('testNilike', function () {
880
- it('returns undefined if no operator given', function () {
1108
+ it('should return undefined if no operator given', function () {
881
1109
  const result = S.testNilike({}, 'value');
882
1110
  expect(result).to.be.undefined;
883
1111
  });
884
1112
 
885
- it('returns false if a given value matches a substring', function () {
886
- expect(S.testNilike({nilike: 'val'}, 'value')).to.be.false;
887
- expect(S.testNilike({nilike: 'lue'}, 'value')).to.be.false;
888
- expect(S.testNilike({nilike: 'value'}, 'value')).to.be.false;
1113
+ it('should return true when matching by substring', function () {
1114
+ expect(S.testNilike({nilike: 'val'}, 'value')).to.be.true;
1115
+ expect(S.testNilike({nilike: 'lue'}, 'value')).to.be.true;
1116
+ expect(S.testNilike({nilike: 'alu'}, 'value')).to.be.true;
889
1117
  });
890
1118
 
891
- it('returns true if a given value not matches a substring', function () {
1119
+ it('should return true when the value is a substring', function () {
892
1120
  expect(S.testNilike({nilike: 'value'}, 'val')).to.be.true;
893
1121
  expect(S.testNilike({nilike: 'value'}, 'lue')).to.be.true;
894
- expect(S.testNilike({nilike: 'value'}, 'foo')).to.be.true;
895
- });
896
-
897
- it('uses case-insensitive matching for a substring', function () {
898
- expect(S.testNilike({nilike: 'Val'}, 'value')).to.be.false;
899
- expect(S.testNilike({nilike: 'Val'}, 'Value')).to.be.false;
900
- expect(S.testNilike({nilike: 'val'}, 'Value')).to.be.false;
901
- });
902
-
903
- it('returns false if a given value matches a string expression', function () {
904
- expect(S.testNilike({nilike: 'val.+'}, 'value')).to.be.false;
905
- });
906
-
907
- it('returns true if a given value not matches a string expression', function () {
908
- expect(S.testNilike({nilike: 'foo.+'}, 'value')).to.be.true;
909
- });
910
-
911
- it('uses case-insensitive matching for a string expression', function () {
912
- expect(S.testNilike({nilike: 'Val.+'}, 'value')).to.be.false;
913
- expect(S.testNilike({nilike: 'Val.+'}, 'Value')).to.be.false;
914
- expect(S.testNilike({nilike: 'val.+'}, 'Value')).to.be.false;
915
- });
916
-
917
- it('returns false if a given value matches a RegExp', function () {
918
- expect(S.testNilike({nilike: new RegExp(/val.+/)}, 'value')).to.be.false;
919
- });
920
-
921
- it('returns true if a given value matches a RegExp', function () {
922
- expect(S.testNilike({nilike: new RegExp(/foo.+/)}, 'value')).to.be.true;
923
- });
924
-
925
- it('uses case-insensitive matching for a RegExp', function () {
926
- expect(S.testNilike({nilike: new RegExp(/Val.+/)}, 'value')).to.be.false;
927
- expect(S.testNilike({nilike: new RegExp(/Val.+/)}, 'Value')).to.be.false;
928
- expect(S.testNilike({nilike: new RegExp(/val.+/)}, 'Value')).to.be.false;
929
- });
930
-
931
- it('throws an error if a first argument is not an object', function () {
932
- const throwable = () => S.testNilike(10);
933
- expect(throwable).to.throw(
934
- 'The first argument of OperatorUtils.testNilike ' +
935
- 'should be an Object, but 10 was given.',
936
- );
1122
+ expect(S.testNilike({nilike: 'value'}, 'alu')).to.be.true;
937
1123
  });
938
1124
 
939
- it('throws an error if an operator value is a number', function () {
940
- const nilike = 10;
941
- const throwable = () => S.testNilike({nilike}, 10);
942
- expect(throwable).to.throw(InvalidOperatorValueError);
943
- });
944
-
945
- it('throws an error if an operator value is an object', function () {
946
- const nilike = {};
947
- const throwable = () => S.testNilike({nilike}, 10);
948
- expect(throwable).to.throw(InvalidOperatorValueError);
1125
+ it('should return false for exact match', function () {
1126
+ expect(S.testNilike({nilike: 'value'}, 'value')).to.be.false;
949
1127
  });
950
1128
 
951
- it('throws an error if an operator value is a null', function () {
952
- const nilike = null;
953
- const throwable = () => S.testNilike({nilike}, 10);
954
- expect(throwable).to.throw(InvalidOperatorValueError);
1129
+ it('should use case-insensitive matching', function () {
1130
+ expect(S.testNilike({nilike: 'VALUE'}, 'VALUE')).to.be.false;
1131
+ expect(S.testNilike({nilike: 'VALUE'}, 'value')).to.be.false;
1132
+ expect(S.testNilike({nilike: 'value'}, 'VALUE')).to.be.false;
1133
+ });
1134
+
1135
+ it('should handle "%" wildcard as zero or more characters', function () {
1136
+ expect(S.testNilike({nilike: 'hello wo%'}, 'hello world today')).to.be
1137
+ .false;
1138
+ expect(S.testNilike({nilike: '%ld today'}, 'hello world today')).to.be
1139
+ .false;
1140
+ expect(S.testNilike({nilike: '%world%'}, 'hello world today')).to.be
1141
+ .false;
1142
+ expect(S.testNilike({nilike: '%hello wo%'}, 'hello world today')).to.be
1143
+ .false;
1144
+ expect(S.testNilike({nilike: '%ld today%'}, 'hello world today')).to.be
1145
+ .false;
1146
+ expect(S.testNilike({nilike: '%wurld%'}, 'hello world today')).to.be.true;
1147
+ });
1148
+
1149
+ it('should handle "_" wildcard as any characters', function () {
1150
+ expect(S.testNilike({nilike: 'h_ll_'}, 'hello')).to.be.false;
1151
+ expect(S.testNilike({nilike: 'hello_world'}, 'hello world')).to.be.false;
1152
+ expect(S.testNilike({nilike: 'hello_'}, 'hello')).to.be.true;
1153
+ expect(S.testNilike({nilike: '_hello'}, 'hello')).to.be.true;
1154
+ });
1155
+
1156
+ it('should throw an error for non-object clause', function () {
1157
+ const throwable = v => () => {
1158
+ S.testNilike(v);
1159
+ };
1160
+ const error = s =>
1161
+ format(
1162
+ 'The first argument of OperatorUtils.testNilike ' +
1163
+ 'should be an Object, but %s was given.',
1164
+ s,
1165
+ );
1166
+ expect(throwable('str')).to.throw(error('"str"'));
1167
+ expect(throwable('')).to.throw(error('""'));
1168
+ expect(throwable(10)).to.throw(error('10'));
1169
+ expect(throwable(0)).to.throw(error('0'));
1170
+ expect(throwable(true)).to.throw(error('true'));
1171
+ expect(throwable(false)).to.throw(error('false'));
1172
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
1173
+ expect(throwable([])).to.throw(error('Array'));
1174
+ expect(throwable(() => undefined)).to.throw(error('Function'));
1175
+ throwable({})();
1176
+ });
1177
+
1178
+ it('should throw an error for non-string operator value', function () {
1179
+ const throwable = v => () => {
1180
+ S.testNilike({nilike: v});
1181
+ };
1182
+ const error = s =>
1183
+ format(
1184
+ 'Condition of {nilike: ...} should have a String, but %s was given.',
1185
+ s,
1186
+ );
1187
+ expect(throwable(10)).to.throw(error('10'));
1188
+ expect(throwable(0)).to.throw(error('0'));
1189
+ expect(throwable(true)).to.throw(error('true'));
1190
+ expect(throwable(false)).to.throw(error('false'));
1191
+ expect(throwable({foo: 'bar'})).to.throw(error('Object'));
1192
+ expect(throwable({})).to.throw(error('Object'));
1193
+ expect(throwable([1, 2, 3])).to.throw(error('Array'));
1194
+ expect(throwable([])).to.throw(error('Array'));
1195
+ expect(throwable(() => undefined)).to.throw(error('Function'));
1196
+ expect(throwable(new RegExp())).to.throw(error('RegExp (instance)'));
1197
+ throwable('str')();
1198
+ throwable(null);
1199
+ throwable(undefined);
955
1200
  });
956
1201
  });
957
1202