@e22m4u/js-repository 0.0.31

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.
Files changed (183) hide show
  1. package/.c8rc +9 -0
  2. package/.commitlintrc +5 -0
  3. package/.editorconfig +13 -0
  4. package/.eslintignore +1 -0
  5. package/.eslintrc.cjs +27 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.husky/pre-commit +9 -0
  8. package/.mocharc.cjs +7 -0
  9. package/.prettierrc +7 -0
  10. package/LICENSE +21 -0
  11. package/README.md +523 -0
  12. package/mocha.setup.js +10 -0
  13. package/package.json +57 -0
  14. package/src/adapter/adapter-loader.d.ts +16 -0
  15. package/src/adapter/adapter-loader.js +63 -0
  16. package/src/adapter/adapter-loader.spec.js +31 -0
  17. package/src/adapter/adapter-registry.d.ts +14 -0
  18. package/src/adapter/adapter-registry.js +36 -0
  19. package/src/adapter/adapter-registry.spec.js +36 -0
  20. package/src/adapter/adapter.d.ts +118 -0
  21. package/src/adapter/adapter.js +181 -0
  22. package/src/adapter/adapter.spec.js +144 -0
  23. package/src/adapter/builtin/memory-adapter.d.ts +118 -0
  24. package/src/adapter/builtin/memory-adapter.js +342 -0
  25. package/src/adapter/builtin/memory-adapter.spec.js +2925 -0
  26. package/src/adapter/decorator/data-sanitizing-decorator.d.ts +13 -0
  27. package/src/adapter/decorator/data-sanitizing-decorator.js +44 -0
  28. package/src/adapter/decorator/data-sanitizing-decorator.spec.js +59 -0
  29. package/src/adapter/decorator/data-validation-decorator.d.ts +13 -0
  30. package/src/adapter/decorator/data-validation-decorator.js +41 -0
  31. package/src/adapter/decorator/data-validation-decorator.spec.js +59 -0
  32. package/src/adapter/decorator/default-values-decorator.d.ts +13 -0
  33. package/src/adapter/decorator/default-values-decorator.js +57 -0
  34. package/src/adapter/decorator/default-values-decorator.spec.js +141 -0
  35. package/src/adapter/decorator/fields-filtering-decorator.d.ts +13 -0
  36. package/src/adapter/decorator/fields-filtering-decorator.js +72 -0
  37. package/src/adapter/decorator/fields-filtering-decorator.spec.js +119 -0
  38. package/src/adapter/decorator/inclusion-decorator.d.ts +13 -0
  39. package/src/adapter/decorator/inclusion-decorator.js +78 -0
  40. package/src/adapter/decorator/inclusion-decorator.spec.js +117 -0
  41. package/src/adapter/decorator/index.d.ts +5 -0
  42. package/src/adapter/decorator/index.js +5 -0
  43. package/src/adapter/index.d.ts +3 -0
  44. package/src/adapter/index.js +3 -0
  45. package/src/definition/datasource/datasource-definition-validator.d.ts +14 -0
  46. package/src/definition/datasource/datasource-definition-validator.js +33 -0
  47. package/src/definition/datasource/datasource-definition-validator.spec.js +63 -0
  48. package/src/definition/datasource/datasource-definition.d.ts +7 -0
  49. package/src/definition/datasource/index.d.ts +2 -0
  50. package/src/definition/datasource/index.js +1 -0
  51. package/src/definition/definition-registry.d.ts +50 -0
  52. package/src/definition/definition-registry.js +98 -0
  53. package/src/definition/definition-registry.spec.js +78 -0
  54. package/src/definition/index.d.ts +3 -0
  55. package/src/definition/index.js +3 -0
  56. package/src/definition/model/index.d.ts +7 -0
  57. package/src/definition/model/index.js +6 -0
  58. package/src/definition/model/model-data-sanitizer.d.ts +15 -0
  59. package/src/definition/model/model-data-sanitizer.js +33 -0
  60. package/src/definition/model/model-data-validator.d.ts +32 -0
  61. package/src/definition/model/model-data-validator.js +144 -0
  62. package/src/definition/model/model-data-validator.spec.js +1889 -0
  63. package/src/definition/model/model-definition-utils.d.ts +161 -0
  64. package/src/definition/model/model-definition-utils.js +371 -0
  65. package/src/definition/model/model-definition-utils.spec.js +1474 -0
  66. package/src/definition/model/model-definition-validator.d.ts +14 -0
  67. package/src/definition/model/model-definition-validator.js +83 -0
  68. package/src/definition/model/model-definition-validator.spec.js +143 -0
  69. package/src/definition/model/model-definition.d.ts +28 -0
  70. package/src/definition/model/properties/data-type.d.ts +11 -0
  71. package/src/definition/model/properties/data-type.js +11 -0
  72. package/src/definition/model/properties/default-values-definition-validator.d.ts +15 -0
  73. package/src/definition/model/properties/default-values-definition-validator.js +53 -0
  74. package/src/definition/model/properties/default-values-definition-validator.spec.js +136 -0
  75. package/src/definition/model/properties/index.d.ts +5 -0
  76. package/src/definition/model/properties/index.js +4 -0
  77. package/src/definition/model/properties/primary-keys-definition-validator.d.ts +15 -0
  78. package/src/definition/model/properties/primary-keys-definition-validator.js +55 -0
  79. package/src/definition/model/properties/primary-keys-definition-validator.spec.js +145 -0
  80. package/src/definition/model/properties/properties-definition-validator.d.ts +15 -0
  81. package/src/definition/model/properties/properties-definition-validator.js +194 -0
  82. package/src/definition/model/properties/properties-definition-validator.spec.js +373 -0
  83. package/src/definition/model/properties/property-definition.d.ts +20 -0
  84. package/src/definition/model/relations/index.d.ts +3 -0
  85. package/src/definition/model/relations/index.js +2 -0
  86. package/src/definition/model/relations/relation-definition.d.ts +254 -0
  87. package/src/definition/model/relations/relation-type.d.ts +9 -0
  88. package/src/definition/model/relations/relation-type.js +9 -0
  89. package/src/definition/model/relations/relations-definition-validator.d.ts +15 -0
  90. package/src/definition/model/relations/relations-definition-validator.js +449 -0
  91. package/src/definition/model/relations/relations-definition-validator.spec.js +772 -0
  92. package/src/errors/index.d.ts +3 -0
  93. package/src/errors/index.js +3 -0
  94. package/src/errors/invalid-argument-error.d.ts +6 -0
  95. package/src/errors/invalid-argument-error.js +6 -0
  96. package/src/errors/invalid-argument-error.spec.js +33 -0
  97. package/src/errors/invalid-operator-value-error.d.ts +13 -0
  98. package/src/errors/invalid-operator-value-error.js +24 -0
  99. package/src/errors/invalid-operator-value-error.spec.js +11 -0
  100. package/src/errors/not-implemented-error.d.ts +6 -0
  101. package/src/errors/not-implemented-error.js +6 -0
  102. package/src/errors/not-implemented-error.spec.js +33 -0
  103. package/src/filter/fields-clause-tool.d.ts +38 -0
  104. package/src/filter/fields-clause-tool.js +88 -0
  105. package/src/filter/fields-clause-tool.spec.js +133 -0
  106. package/src/filter/filter.d.ts +335 -0
  107. package/src/filter/include-clause-tool.d.ts +53 -0
  108. package/src/filter/include-clause-tool.js +364 -0
  109. package/src/filter/include-clause-tool.spec.js +653 -0
  110. package/src/filter/index.d.ts +7 -0
  111. package/src/filter/index.js +6 -0
  112. package/src/filter/operator-clause-tool.d.ts +223 -0
  113. package/src/filter/operator-clause-tool.js +515 -0
  114. package/src/filter/operator-clause-tool.spec.js +1064 -0
  115. package/src/filter/order-clause-tool.d.ts +32 -0
  116. package/src/filter/order-clause-tool.js +97 -0
  117. package/src/filter/order-clause-tool.spec.js +438 -0
  118. package/src/filter/slice-clause-tool.d.ts +30 -0
  119. package/src/filter/slice-clause-tool.js +65 -0
  120. package/src/filter/slice-clause-tool.spec.js +117 -0
  121. package/src/filter/where-clause-tool.d.ts +23 -0
  122. package/src/filter/where-clause-tool.js +165 -0
  123. package/src/filter/where-clause-tool.spec.js +280 -0
  124. package/src/index.d.ts +9 -0
  125. package/src/index.js +8 -0
  126. package/src/relations/belongs-to-resolver.d.ts +46 -0
  127. package/src/relations/belongs-to-resolver.js +242 -0
  128. package/src/relations/belongs-to-resolver.spec.js +1047 -0
  129. package/src/relations/has-many-resolver.d.ts +67 -0
  130. package/src/relations/has-many-resolver.js +317 -0
  131. package/src/relations/has-many-resolver.spec.js +2911 -0
  132. package/src/relations/has-one-resolver.d.ts +67 -0
  133. package/src/relations/has-one-resolver.js +311 -0
  134. package/src/relations/has-one-resolver.spec.js +2274 -0
  135. package/src/relations/index.d.ts +4 -0
  136. package/src/relations/index.js +4 -0
  137. package/src/relations/references-many-resolver.d.ts +27 -0
  138. package/src/relations/references-many-resolver.js +113 -0
  139. package/src/relations/references-many-resolver.spec.js +631 -0
  140. package/src/repository/index.d.ts +2 -0
  141. package/src/repository/index.js +2 -0
  142. package/src/repository/repository-registry.d.ts +29 -0
  143. package/src/repository/repository-registry.js +57 -0
  144. package/src/repository/repository-registry.spec.js +38 -0
  145. package/src/repository/repository.d.ts +164 -0
  146. package/src/repository/repository.js +207 -0
  147. package/src/repository/repository.spec.js +202 -0
  148. package/src/schema.d.ts +37 -0
  149. package/src/schema.js +41 -0
  150. package/src/types.d.ts +30 -0
  151. package/src/utils/capitalize.d.ts +6 -0
  152. package/src/utils/capitalize.js +10 -0
  153. package/src/utils/capitalize.spec.js +14 -0
  154. package/src/utils/clone-deep.d.ts +6 -0
  155. package/src/utils/clone-deep.js +61 -0
  156. package/src/utils/clone-deep.spec.js +28 -0
  157. package/src/utils/exclude-object-keys.d.ts +10 -0
  158. package/src/utils/exclude-object-keys.js +20 -0
  159. package/src/utils/exclude-object-keys.spec.js +49 -0
  160. package/src/utils/get-ctor-name.d.ts +6 -0
  161. package/src/utils/get-ctor-name.js +11 -0
  162. package/src/utils/get-ctor-name.spec.js +17 -0
  163. package/src/utils/get-value-by-path.d.ts +12 -0
  164. package/src/utils/get-value-by-path.js +23 -0
  165. package/src/utils/get-value-by-path.spec.js +36 -0
  166. package/src/utils/index.d.ts +10 -0
  167. package/src/utils/index.js +10 -0
  168. package/src/utils/is-ctor.d.ts +7 -0
  169. package/src/utils/is-ctor.js +10 -0
  170. package/src/utils/is-ctor.spec.js +26 -0
  171. package/src/utils/is-pure-object.d.ts +6 -0
  172. package/src/utils/is-pure-object.js +15 -0
  173. package/src/utils/is-pure-object.spec.js +25 -0
  174. package/src/utils/select-object-keys.d.ts +10 -0
  175. package/src/utils/select-object-keys.js +37 -0
  176. package/src/utils/select-object-keys.spec.js +40 -0
  177. package/src/utils/singularize.d.ts +6 -0
  178. package/src/utils/singularize.js +22 -0
  179. package/src/utils/singularize.spec.js +23 -0
  180. package/src/utils/string-to-regexp.d.ts +10 -0
  181. package/src/utils/string-to-regexp.js +22 -0
  182. package/src/utils/string-to-regexp.spec.js +35 -0
  183. package/tsconfig.json +9 -0
@@ -0,0 +1,1064 @@
1
+ import {expect} from 'chai';
2
+ import {format} from '@e22m4u/js-format';
3
+ import {OperatorClauseTool} from './operator-clause-tool.js';
4
+ import {InvalidOperatorValueError} from '../errors/index.js';
5
+
6
+ const S = new OperatorClauseTool();
7
+
8
+ describe('OperatorClauseTool', function () {
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 () {
28
+ const obj = {};
29
+ 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
+ expect(S.compare('a', 'a')).to.be.eq(0);
33
+ expect(S.compare(obj, obj)).to.be.eq(0);
34
+ expect(S.compare(null, null)).to.be.eq(0);
35
+ expect(S.compare(undefined, undefined)).to.be.eq(0);
36
+ });
37
+
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;
46
+ });
47
+ });
48
+
49
+ describe('testAll', function () {
50
+ it('tests "eq" and "neq" operators', function () {
51
+ expect(S.testAll({eq: 10}, 10)).to.be.true;
52
+ expect(S.testAll({eq: 10}, 9)).to.be.false;
53
+ expect(S.testAll({neq: 10}, 9)).to.be.true;
54
+ expect(S.testAll({neq: 10}, 10)).to.be.false;
55
+ });
56
+
57
+ it('tests "gt", "gte", "lt" and "lte" operators', function () {
58
+ expect(S.testAll({gt: 5}, 6)).to.be.true;
59
+ expect(S.testAll({gte: 5}, 5)).to.be.true;
60
+ expect(S.testAll({lt: 5}, 4)).to.be.true;
61
+ expect(S.testAll({lte: 5}, 5)).to.be.true;
62
+ expect(S.testAll({gt: 5}, 5)).to.be.false;
63
+ expect(S.testAll({gte: 5}, 4)).to.be.false;
64
+ expect(S.testAll({lt: 5}, 5)).to.be.false;
65
+ expect(S.testAll({lte: 5}, 6)).to.be.false;
66
+ });
67
+
68
+ it('tests a "inq" operator', function () {
69
+ expect(S.testAll({inq: [1, 2, 3]}, 2)).to.be.true;
70
+ expect(S.testAll({inq: [1, 2, 3]}, 'a')).to.be.false;
71
+ });
72
+
73
+ it('tests a "nin" operator', function () {
74
+ expect(S.testAll({nin: [1, 2, 3]}, 'a')).to.be.true;
75
+ expect(S.testAll({nin: [1, 2, 3]}, 2)).to.be.false;
76
+ });
77
+
78
+ it('tests a "between" operator', function () {
79
+ expect(S.testAll({between: [-2, 2]}, 0)).to.be.true;
80
+ expect(S.testAll({between: [-2, 2]}, 10)).to.be.false;
81
+ });
82
+
83
+ it('tests an "exists" operator', function () {
84
+ expect(S.testAll({exists: true}, 10)).to.be.true;
85
+ expect(S.testAll({exists: false}, undefined)).to.be.true;
86
+ expect(S.testAll({exists: true}, undefined)).to.be.false;
87
+ expect(S.testAll({exists: false}, 10)).to.be.false;
88
+ });
89
+
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;
93
+ });
94
+
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;
98
+ });
99
+
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;
103
+ });
104
+
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;
108
+ });
109
+
110
+ it('tests a "regexp" operator', function () {
111
+ expect(S.testAll({regexp: 'Wo.+'}, 'Hello World!')).to.be.true;
112
+ expect(S.testAll({regexp: 'Fo.+'}, 'Hello World!')).to.be.false;
113
+ });
114
+
115
+ it('throws an error if a first argument is not an object', function () {
116
+ const throwable = () => S.testAll(10);
117
+ expect(throwable).to.throw(
118
+ 'A first argument of OperatorUtils.testAll ' +
119
+ 'should be an Object, but 10 given.',
120
+ );
121
+ });
122
+ });
123
+
124
+ describe('testEqNeq', function () {
125
+ it('returns undefined if no operator given', function () {
126
+ const result = S.testEqNeq({}, 'value');
127
+ expect(result).to.be.undefined;
128
+ });
129
+
130
+ it('throws an error if a first argument is not an object', function () {
131
+ const throwable = () => S.testEqNeq(10);
132
+ expect(throwable).to.throw(
133
+ 'A first argument of OperatorUtils.testEqNeq ' +
134
+ 'should be an Object, but 10 given.',
135
+ );
136
+ });
137
+
138
+ describe('eq', function () {
139
+ it('returns true if a given value is equal to reference', function () {
140
+ 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;
144
+ expect(S.testEqNeq({eq: 'a'}, 'a')).to.be.true;
145
+ expect(S.testEqNeq({eq: true}, true)).to.be.true;
146
+ expect(S.testEqNeq({eq: false}, false)).to.be.true;
147
+ expect(S.testEqNeq({eq: Infinity}, Infinity)).to.be.true;
148
+ expect(S.testEqNeq({eq: null}, null)).to.be.true;
149
+ expect(S.testEqNeq({eq: undefined}, undefined)).to.be.true;
150
+ });
151
+
152
+ it('returns false if a given value is not-equal to reference', function () {
153
+ expect(S.testEqNeq({eq: 0}, 1)).to.be.false;
154
+ expect(S.testEqNeq({eq: 0}, '1')).to.be.false;
155
+ expect(S.testEqNeq({eq: 0}, true)).to.be.false;
156
+ expect(S.testEqNeq({eq: 0}, Infinity)).to.be.false;
157
+ expect(S.testEqNeq({eq: 0}, null)).to.be.false;
158
+ expect(S.testEqNeq({eq: 0}, undefined)).to.be.false;
159
+ expect(S.testEqNeq({eq: '0'}, '1')).to.be.false;
160
+ expect(S.testEqNeq({eq: '0'}, true)).to.be.false;
161
+ expect(S.testEqNeq({eq: '0'}, Infinity)).to.be.false;
162
+ expect(S.testEqNeq({eq: '0'}, null)).to.be.false;
163
+ expect(S.testEqNeq({eq: '0'}, undefined)).to.be.false;
164
+ expect(S.testEqNeq({eq: true}, false)).to.be.false;
165
+ expect(S.testEqNeq({eq: true}, null)).to.be.false;
166
+ expect(S.testEqNeq({eq: true}, undefined)).to.be.false;
167
+ expect(S.testEqNeq({eq: false}, true)).to.be.false;
168
+ expect(S.testEqNeq({eq: false}, null)).to.be.false;
169
+ expect(S.testEqNeq({eq: false}, undefined)).to.be.false;
170
+ });
171
+ });
172
+
173
+ describe('neq', function () {
174
+ it('returns false if a given value is strictly equal to reference', function () {
175
+ 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;
179
+ expect(S.testEqNeq({neq: 'a'}, 'a')).to.be.false;
180
+ expect(S.testEqNeq({neq: true}, true)).to.be.false;
181
+ expect(S.testEqNeq({neq: false}, false)).to.be.false;
182
+ expect(S.testEqNeq({neq: Infinity}, Infinity)).to.be.false;
183
+ expect(S.testEqNeq({neq: null}, null)).to.be.false;
184
+ expect(S.testEqNeq({neq: undefined}, undefined)).to.be.false;
185
+ });
186
+
187
+ it('returns true if a given value is strictly not-equal to reference', function () {
188
+ expect(S.testEqNeq({neq: 0}, 1)).to.be.true;
189
+ expect(S.testEqNeq({neq: 0}, '1')).to.be.true;
190
+ expect(S.testEqNeq({neq: 0}, true)).to.be.true;
191
+ expect(S.testEqNeq({neq: 0}, Infinity)).to.be.true;
192
+ expect(S.testEqNeq({neq: 0}, null)).to.be.true;
193
+ expect(S.testEqNeq({neq: 0}, undefined)).to.be.true;
194
+ expect(S.testEqNeq({neq: '0'}, '1')).to.be.true;
195
+ expect(S.testEqNeq({neq: '0'}, true)).to.be.true;
196
+ expect(S.testEqNeq({neq: '0'}, Infinity)).to.be.true;
197
+ expect(S.testEqNeq({neq: '0'}, null)).to.be.true;
198
+ expect(S.testEqNeq({neq: '0'}, undefined)).to.be.true;
199
+ expect(S.testEqNeq({neq: true}, false)).to.be.true;
200
+ expect(S.testEqNeq({neq: true}, null)).to.be.true;
201
+ expect(S.testEqNeq({neq: true}, undefined)).to.be.true;
202
+ expect(S.testEqNeq({neq: false}, true)).to.be.true;
203
+ expect(S.testEqNeq({neq: false}, null)).to.be.true;
204
+ expect(S.testEqNeq({neq: false}, undefined)).to.be.true;
205
+ });
206
+ });
207
+ });
208
+
209
+ describe('testGtLt', function () {
210
+ it('returns undefined if no operator given', function () {
211
+ const result = S.testGtLt({}, 'value');
212
+ expect(result).to.be.undefined;
213
+ });
214
+
215
+ it('throws an error if a first argument is not an object', function () {
216
+ const throwable = () => S.testGtLt(10);
217
+ expect(throwable).to.throw(
218
+ 'A first argument of OperatorUtils.testGtLt ' +
219
+ 'should be an Object, but 10 given.',
220
+ );
221
+ });
222
+
223
+ describe('gt', function () {
224
+ it('returns true if a given value is greater than reference', function () {
225
+ expect(S.testGtLt({gt: 0}, 5)).to.be.true;
226
+ expect(S.testGtLt({gt: 0}, '5')).to.be.true;
227
+ expect(S.testGtLt({gt: 0}, Infinity)).to.be.true;
228
+ expect(S.testGtLt({gt: 0}, true)).to.be.true;
229
+ expect(S.testGtLt({gt: -1}, false)).to.be.true;
230
+ expect(S.testGtLt({gt: 'a'}, 'b')).to.be.true;
231
+ });
232
+
233
+ it('returns false if a given value is equal to reference', function () {
234
+ expect(S.testGtLt({gt: 0}, 0)).to.be.false;
235
+ expect(S.testGtLt({gt: 0}, '0')).to.be.false;
236
+ expect(S.testGtLt({gt: 0}, false)).to.be.false;
237
+ expect(S.testGtLt({gt: 1}, true)).to.be.false;
238
+ expect(S.testGtLt({gt: 'a'}, 'a')).to.be.false;
239
+ });
240
+
241
+ it('returns false if a given value is lower than reference', function () {
242
+ expect(S.testGtLt({gt: 2}, 0)).to.be.false;
243
+ expect(S.testGtLt({gt: 2}, '0')).to.be.false;
244
+ expect(S.testGtLt({gt: 2}, true)).to.be.false;
245
+ expect(S.testGtLt({gt: 2}, false)).to.be.false;
246
+ expect(S.testGtLt({gt: 'b'}, 'a')).to.be.false;
247
+ });
248
+
249
+ it('returns false if we do not know how to compare', function () {
250
+ expect(S.testGtLt({gt: 1}, [])).to.be.false;
251
+ expect(S.testGtLt({gt: 1}, {})).to.be.false;
252
+ expect(S.testGtLt({gt: 1}, null)).to.be.false;
253
+ expect(S.testGtLt({gt: 1}, undefined)).to.be.false;
254
+ expect(S.testGtLt({gt: 1}, NaN)).to.be.false;
255
+ expect(S.testGtLt({gt: 1}, Symbol())).to.be.false;
256
+ });
257
+ });
258
+
259
+ describe('gte', function () {
260
+ it('returns true if a given value is greater than reference', function () {
261
+ expect(S.testGtLt({gte: 0}, 5)).to.be.true;
262
+ expect(S.testGtLt({gte: 0}, '5')).to.be.true;
263
+ expect(S.testGtLt({gte: 0}, Infinity)).to.be.true;
264
+ expect(S.testGtLt({gte: 0}, true)).to.be.true;
265
+ expect(S.testGtLt({gte: -1}, false)).to.be.true;
266
+ expect(S.testGtLt({gte: 'a'}, 'b')).to.be.true;
267
+ });
268
+
269
+ it('returns true if a given value is equal to reference', function () {
270
+ expect(S.testGtLt({gte: 0}, 0)).to.be.true;
271
+ expect(S.testGtLt({gte: 0}, '0')).to.be.true;
272
+ expect(S.testGtLt({gte: 0}, false)).to.be.true;
273
+ expect(S.testGtLt({gte: 1}, true)).to.be.true;
274
+ expect(S.testGtLt({gte: 'a'}, 'a')).to.be.true;
275
+ });
276
+
277
+ it('returns false if a given value is lower than reference', function () {
278
+ expect(S.testGtLt({gte: 2}, 0)).to.be.false;
279
+ expect(S.testGtLt({gte: 2}, '0')).to.be.false;
280
+ expect(S.testGtLt({gte: 2}, true)).to.be.false;
281
+ expect(S.testGtLt({gte: 2}, false)).to.be.false;
282
+ expect(S.testGtLt({gte: 'b'}, 'a')).to.be.false;
283
+ });
284
+
285
+ it('returns false if we do not know how to compare', function () {
286
+ expect(S.testGtLt({gte: 1}, [])).to.be.false;
287
+ expect(S.testGtLt({gte: 1}, {})).to.be.false;
288
+ expect(S.testGtLt({gte: 1}, null)).to.be.false;
289
+ expect(S.testGtLt({gte: 1}, undefined)).to.be.false;
290
+ expect(S.testGtLt({gte: 1}, NaN)).to.be.false;
291
+ expect(S.testGtLt({gte: 1}, Symbol())).to.be.false;
292
+ });
293
+ });
294
+
295
+ describe('lt', function () {
296
+ it('returns false if a given value is greater than reference', function () {
297
+ expect(S.testGtLt({lt: 0}, 5)).to.be.false;
298
+ expect(S.testGtLt({lt: 0}, '5')).to.be.false;
299
+ expect(S.testGtLt({lt: 0}, Infinity)).to.be.false;
300
+ expect(S.testGtLt({lt: 0}, true)).to.be.false;
301
+ expect(S.testGtLt({lt: -1}, false)).to.be.false;
302
+ expect(S.testGtLt({lt: 'a'}, 'b')).to.be.false;
303
+ });
304
+
305
+ it('returns false if a given value is equal to reference', function () {
306
+ expect(S.testGtLt({lt: 0}, 0)).to.be.false;
307
+ expect(S.testGtLt({lt: 0}, '0')).to.be.false;
308
+ expect(S.testGtLt({lt: 0}, false)).to.be.false;
309
+ expect(S.testGtLt({lt: 1}, true)).to.be.false;
310
+ expect(S.testGtLt({lt: 'a'}, 'a')).to.be.false;
311
+ });
312
+
313
+ it('returns true if a given value is lower than reference', function () {
314
+ expect(S.testGtLt({lt: 2}, 0)).to.be.true;
315
+ expect(S.testGtLt({lt: 2}, '0')).to.be.true;
316
+ expect(S.testGtLt({lt: 2}, true)).to.be.true;
317
+ expect(S.testGtLt({lt: 2}, false)).to.be.true;
318
+ expect(S.testGtLt({lt: 'b'}, 'a')).to.be.true;
319
+ });
320
+
321
+ it('returns false if we do not know how to compare', function () {
322
+ expect(S.testGtLt({lt: 1}, [])).to.be.false;
323
+ expect(S.testGtLt({lt: 1}, {})).to.be.false;
324
+ expect(S.testGtLt({lt: 1}, null)).to.be.false;
325
+ expect(S.testGtLt({lt: 1}, undefined)).to.be.false;
326
+ expect(S.testGtLt({lt: 1}, NaN)).to.be.false;
327
+ expect(S.testGtLt({lt: 1}, Symbol())).to.be.false;
328
+ });
329
+ });
330
+
331
+ describe('lte', function () {
332
+ it('returns false if a given value is greater than reference', function () {
333
+ expect(S.testGtLt({lte: 0}, 5)).to.be.false;
334
+ expect(S.testGtLt({lte: 0}, '5')).to.be.false;
335
+ expect(S.testGtLt({lte: 0}, Infinity)).to.be.false;
336
+ expect(S.testGtLt({lte: 0}, true)).to.be.false;
337
+ expect(S.testGtLt({lte: -1}, false)).to.be.false;
338
+ expect(S.testGtLt({lte: 'a'}, 'b')).to.be.false;
339
+ });
340
+
341
+ it('returns true if a given value is equal to reference', function () {
342
+ expect(S.testGtLt({lte: 0}, 0)).to.be.true;
343
+ expect(S.testGtLt({lte: 0}, '0')).to.be.true;
344
+ expect(S.testGtLt({lte: 0}, false)).to.be.true;
345
+ expect(S.testGtLt({lte: 1}, true)).to.be.true;
346
+ expect(S.testGtLt({lte: 'a'}, 'a')).to.be.true;
347
+ });
348
+
349
+ it('returns true if a given value is lower than reference', function () {
350
+ expect(S.testGtLt({lte: 2}, 0)).to.be.true;
351
+ expect(S.testGtLt({lte: 2}, '0')).to.be.true;
352
+ expect(S.testGtLt({lte: 2}, true)).to.be.true;
353
+ expect(S.testGtLt({lte: 2}, false)).to.be.true;
354
+ expect(S.testGtLt({lte: 'b'}, 'a')).to.be.true;
355
+ });
356
+
357
+ it('returns false if we do not know how to compare', function () {
358
+ expect(S.testGtLt({lte: 1}, [])).to.be.false;
359
+ expect(S.testGtLt({lte: 1}, {})).to.be.false;
360
+ expect(S.testGtLt({lte: 1}, null)).to.be.false;
361
+ expect(S.testGtLt({lte: 1}, undefined)).to.be.false;
362
+ expect(S.testGtLt({lte: 1}, NaN)).to.be.false;
363
+ expect(S.testGtLt({lte: 1}, Symbol())).to.be.false;
364
+ });
365
+ });
366
+ });
367
+
368
+ describe('testInq', function () {
369
+ it('returns undefined if no operator given', function () {
370
+ const result = S.testInq({}, 'value');
371
+ expect(result).to.be.undefined;
372
+ });
373
+
374
+ it('returns true if a given value has in array', function () {
375
+ expect(S.testInq({inq: [1, 2]}, 2)).to.be.true;
376
+ expect(S.testInq({inq: [1, 2]}, '2')).to.be.true;
377
+ 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
+ });
381
+
382
+ it('returns false if a given value is not in array', function () {
383
+ expect(S.testInq({inq: [1, 2]}, 3)).to.be.false;
384
+ expect(S.testInq({inq: [1, 2]}, '3')).to.be.false;
385
+ expect(S.testInq({inq: ['a', 'b']}, 'c')).to.be.false;
386
+ expect(S.testInq({inq: [-1, 0]}, true)).to.be.false;
387
+ expect(S.testInq({inq: [1, 2]}, false)).to.be.false;
388
+ });
389
+
390
+ it('throws an error if a first argument is not an object', function () {
391
+ const throwable = () => S.testInq(10);
392
+ expect(throwable).to.throw(
393
+ 'A first argument of OperatorUtils.testInq ' +
394
+ 'should be an Object, but 10 given.',
395
+ );
396
+ });
397
+
398
+ it('throws an error if an operator value is a number', function () {
399
+ const inq = 10;
400
+ const throwable = () => S.testInq({inq}, 10);
401
+ expect(throwable).to.throw(InvalidOperatorValueError);
402
+ });
403
+
404
+ it('throws an error if an operator value is a string', function () {
405
+ const inq = '10';
406
+ const throwable = () => S.testInq({inq}, 10);
407
+ expect(throwable).to.throw(InvalidOperatorValueError);
408
+ });
409
+
410
+ it('throws an error if an operator value is an object', function () {
411
+ const inq = {};
412
+ const throwable = () => S.testInq({inq}, 10);
413
+ expect(throwable).to.throw(InvalidOperatorValueError);
414
+ });
415
+
416
+ it('throws an error if an operator value is a null', function () {
417
+ const inq = null;
418
+ const throwable = () => S.testInq({inq}, 10);
419
+ expect(throwable).to.throw(InvalidOperatorValueError);
420
+ });
421
+ });
422
+
423
+ describe('testNin', function () {
424
+ it('returns undefined if no operator given', function () {
425
+ const result = S.testNin({}, 'value');
426
+ expect(result).to.be.undefined;
427
+ });
428
+
429
+ it('returns false if a given value has in array', function () {
430
+ expect(S.testNin({nin: [1, 2]}, 2)).to.be.false;
431
+ expect(S.testNin({nin: [1, 2]}, '2')).to.be.false;
432
+ 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
+ });
436
+
437
+ it('returns true if a given value is not in array', function () {
438
+ expect(S.testNin({nin: [1, 2]}, 3)).to.be.true;
439
+ expect(S.testNin({nin: [1, 2]}, '3')).to.be.true;
440
+ expect(S.testNin({nin: ['a', 'b']}, 'c')).to.be.true;
441
+ expect(S.testNin({nin: [-1, 0]}, true)).to.be.true;
442
+ expect(S.testNin({nin: [1, 2]}, false)).to.be.true;
443
+ });
444
+
445
+ it('throws an error if a first argument is not an object', function () {
446
+ const throwable = () => S.testNin(10);
447
+ expect(throwable).to.throw(
448
+ 'A first argument of OperatorUtils.testNin ' +
449
+ 'should be an Object, but 10 given.',
450
+ );
451
+ });
452
+
453
+ it('throws an error if an operator value is a number', function () {
454
+ const nin = 10;
455
+ const throwable = () => S.testNin({nin}, 10);
456
+ expect(throwable).to.throw(InvalidOperatorValueError);
457
+ });
458
+
459
+ it('throws an error if an operator value is a string', function () {
460
+ const nin = '10';
461
+ const throwable = () => S.testNin({nin}, 10);
462
+ expect(throwable).to.throw(InvalidOperatorValueError);
463
+ });
464
+
465
+ it('throws an error if an operator value is an object', function () {
466
+ const nin = {};
467
+ const throwable = () => S.testNin({nin}, 10);
468
+ expect(throwable).to.throw(InvalidOperatorValueError);
469
+ });
470
+
471
+ it('throws an error if an operator value is a null', function () {
472
+ const nin = null;
473
+ const throwable = () => S.testNin({nin}, 10);
474
+ expect(throwable).to.throw(InvalidOperatorValueError);
475
+ });
476
+ });
477
+
478
+ describe('testBetween', function () {
479
+ it('returns undefined if no operator given', function () {
480
+ const result = S.testBetween({}, 'value');
481
+ expect(result).to.be.undefined;
482
+ });
483
+
484
+ it('returns true if a given value exists in a range', function () {
485
+ expect(S.testBetween({between: [-2, 2]}, -2)).to.be.true;
486
+ expect(S.testBetween({between: [-2, 2]}, 0)).to.be.true;
487
+ expect(S.testBetween({between: [-2, 2]}, 2)).to.be.true;
488
+ expect(S.testBetween({between: [-2, 2]}, '-2')).to.be.true;
489
+ expect(S.testBetween({between: [-2, 2]}, '0')).to.be.true;
490
+ expect(S.testBetween({between: [-2, 2]}, '2')).to.be.true;
491
+ expect(S.testBetween({between: ['b', 'd']}, 'b')).to.be.true;
492
+ expect(S.testBetween({between: ['b', 'd']}, 'c')).to.be.true;
493
+ expect(S.testBetween({between: ['b', 'd']}, 'd')).to.be.true;
494
+ expect(S.testBetween({between: [-2, 2]}, true)).to.be.true;
495
+ expect(S.testBetween({between: [-2, 2]}, false)).to.be.true;
496
+ });
497
+
498
+ it('returns false if a given value not exists in a range', function () {
499
+ expect(S.testBetween({between: [-2, 2]}, -5)).to.be.false;
500
+ expect(S.testBetween({between: [-2, 2]}, 5)).to.be.false;
501
+ expect(S.testBetween({between: [-2, 2]}, '-5')).to.be.false;
502
+ expect(S.testBetween({between: [-2, 2]}, '5')).to.be.false;
503
+ expect(S.testBetween({between: ['b', 'd']}, 'a')).to.be.false;
504
+ expect(S.testBetween({between: ['b', 'd']}, 'e')).to.be.false;
505
+ expect(S.testBetween({between: [-2, 2]}, null)).to.be.false;
506
+ expect(S.testBetween({between: [-2, 2]}, undefined)).to.be.false;
507
+ expect(S.testBetween({between: [-2, 2]}, NaN)).to.be.false;
508
+ expect(S.testBetween({between: [-2, 2]}, Infinity)).to.be.false;
509
+ expect(S.testBetween({between: [-2, 2]}, Symbol())).to.be.false;
510
+ expect(S.testBetween({between: [-2, 2]}, [])).to.be.false;
511
+ expect(S.testBetween({between: [-2, 2]}, {})).to.be.false;
512
+ });
513
+
514
+ it('throws an error if a first argument is not an object', function () {
515
+ const throwable = () => S.testBetween(10);
516
+ expect(throwable).to.throw(
517
+ 'A first argument of OperatorUtils.testBetween ' +
518
+ 'should be an Object, but 10 given.',
519
+ );
520
+ });
521
+
522
+ it('throws an error if a given range is not valid', function () {
523
+ const setOf1 = [10];
524
+ const setOf2 = [10, 20];
525
+ const setOf3 = [10, 20, 30];
526
+ const throwable1 = () => S.testBetween({between: setOf1}, 10);
527
+ const throwable2 = () => S.testBetween({between: setOf2}, 10);
528
+ const throwable3 = () => S.testBetween({between: setOf3}, 10);
529
+ expect(throwable1).to.throw(InvalidOperatorValueError);
530
+ expect(throwable2).to.not.throw(InvalidOperatorValueError);
531
+ expect(throwable3).to.throw(InvalidOperatorValueError);
532
+ });
533
+
534
+ it('throws an error if an operator value is a number', function () {
535
+ const between = 10;
536
+ const throwable = () => S.testBetween({between}, 10);
537
+ expect(throwable).to.throw(InvalidOperatorValueError);
538
+ });
539
+
540
+ it('throws an error if an operator value is a string', function () {
541
+ const between = '10';
542
+ const throwable = () => S.testBetween({between}, 10);
543
+ expect(throwable).to.throw(InvalidOperatorValueError);
544
+ });
545
+
546
+ it('throws an error if an operator value is a boolean', function () {
547
+ const between = true;
548
+ const throwable = () => S.testBetween({between}, 10);
549
+ expect(throwable).to.throw(InvalidOperatorValueError);
550
+ });
551
+
552
+ it('throws an error if an operator value is an object', function () {
553
+ const between = {};
554
+ const throwable = () => S.testBetween({between}, 10);
555
+ expect(throwable).to.throw(InvalidOperatorValueError);
556
+ });
557
+
558
+ it('throws an error if an operator value is a null', function () {
559
+ const between = null;
560
+ const throwable = () => S.testBetween({between}, 10);
561
+ expect(throwable).to.throw(InvalidOperatorValueError);
562
+ });
563
+ });
564
+
565
+ describe('testExists', function () {
566
+ it('returns undefined if no operator given', function () {
567
+ const result = S.testExists({}, 'value');
568
+ expect(result).to.be.undefined;
569
+ });
570
+
571
+ it('throws an error if a first argument is not an object', function () {
572
+ const throwable = () => S.testExists(10);
573
+ expect(throwable).to.throw(
574
+ 'A first argument of OperatorUtils.testExists ' +
575
+ 'should be an Object, but 10 given.',
576
+ );
577
+ });
578
+
579
+ describe('exists', function () {
580
+ it('returns true for non-undefined values', function () {
581
+ expect(S.testExists({exists: true}, 0)).to.be.true;
582
+ expect(S.testExists({exists: true}, '')).to.be.true;
583
+ expect(S.testExists({exists: true}, null)).to.be.true;
584
+ expect(S.testExists({exists: true}, NaN)).to.be.true;
585
+ expect(S.testExists({exists: true}, Infinity)).to.be.true;
586
+ expect(S.testExists({exists: true}, Symbol())).to.be.true;
587
+ expect(S.testExists({exists: true}, true)).to.be.true;
588
+ expect(S.testExists({exists: true}, false)).to.be.true;
589
+ expect(S.testExists({exists: true}, [])).to.be.true;
590
+ expect(S.testExists({exists: true}, {})).to.be.true;
591
+ });
592
+
593
+ it('returns false for undefined value', function () {
594
+ expect(S.testExists({exists: true}, undefined)).to.be.false;
595
+ });
596
+ });
597
+
598
+ describe('not exists', function () {
599
+ it('returns false for non-undefined values', function () {
600
+ expect(S.testExists({exists: false}, 0)).to.be.false;
601
+ expect(S.testExists({exists: false}, '')).to.be.false;
602
+ expect(S.testExists({exists: false}, null)).to.be.false;
603
+ expect(S.testExists({exists: false}, NaN)).to.be.false;
604
+ expect(S.testExists({exists: false}, Infinity)).to.be.false;
605
+ expect(S.testExists({exists: false}, Symbol())).to.be.false;
606
+ expect(S.testExists({exists: false}, true)).to.be.false;
607
+ expect(S.testExists({exists: false}, false)).to.be.false;
608
+ expect(S.testExists({exists: false}, [])).to.be.false;
609
+ expect(S.testExists({exists: false}, {})).to.be.false;
610
+ });
611
+
612
+ it('returns true for undefined value', function () {
613
+ expect(S.testExists({exists: false}, undefined)).to.be.true;
614
+ });
615
+ });
616
+
617
+ it('throws an error if an operator value is a number', function () {
618
+ const exists = 10;
619
+ const throwable = () => S.testExists({exists}, 10);
620
+ expect(throwable).to.throw(InvalidOperatorValueError);
621
+ });
622
+
623
+ it('throws an error if an operator value is a string', function () {
624
+ const exists = '10';
625
+ const throwable = () => S.testExists({exists}, 10);
626
+ expect(throwable).to.throw(InvalidOperatorValueError);
627
+ });
628
+
629
+ it('throws an error if an operator value is an object', function () {
630
+ const exists = {};
631
+ const throwable = () => S.testExists({exists}, 10);
632
+ expect(throwable).to.throw(InvalidOperatorValueError);
633
+ });
634
+
635
+ it('throws an error if an operator value is a null', function () {
636
+ const exists = null;
637
+ const throwable = () => S.testExists({exists}, 10);
638
+ expect(throwable).to.throw(InvalidOperatorValueError);
639
+ });
640
+ });
641
+
642
+ describe('testLike', function () {
643
+ it('returns undefined if no operator given', function () {
644
+ const result = S.testLike({}, 'value');
645
+ expect(result).to.be.undefined;
646
+ });
647
+
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;
652
+ });
653
+
654
+ it('returns false if a given value not matches a substring', function () {
655
+ expect(S.testLike({like: 'value'}, 'val')).to.be.false;
656
+ 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;
682
+ });
683
+
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
+ 'A first argument of OperatorUtils.testLike ' +
698
+ 'should be an Object, but 10 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);
712
+ });
713
+
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);
718
+ });
719
+ });
720
+
721
+ describe('testNlike', function () {
722
+ it('returns undefined if no operator given', function () {
723
+ const result = S.testNlike({}, 'value');
724
+ expect(result).to.be.undefined;
725
+ });
726
+
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;
731
+ });
732
+
733
+ it('returns true if a given value not matches a substring', function () {
734
+ expect(S.testNlike({nlike: 'value'}, 'val')).to.be.true;
735
+ 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;
761
+ });
762
+
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
+ 'A first argument of OperatorUtils.testNlike ' +
777
+ 'should be an Object, but 10 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);
791
+ });
792
+
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);
797
+ });
798
+ });
799
+
800
+ describe('testIlike', function () {
801
+ it('returns undefined if no operator given', function () {
802
+ const result = S.testIlike({}, 'value');
803
+ expect(result).to.be.undefined;
804
+ });
805
+
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;
810
+ });
811
+
812
+ it('returns false if a given value not matches a substring', function () {
813
+ expect(S.testIlike({ilike: 'value'}, 'val')).to.be.false;
814
+ 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;
850
+ });
851
+
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
+ 'A first argument of OperatorUtils.testIlike ' +
856
+ 'should be an Object, but 10 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);
870
+ });
871
+
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);
876
+ });
877
+ });
878
+
879
+ describe('testNilike', function () {
880
+ it('returns undefined if no operator given', function () {
881
+ const result = S.testNilike({}, 'value');
882
+ expect(result).to.be.undefined;
883
+ });
884
+
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;
889
+ });
890
+
891
+ it('returns true if a given value not matches a substring', function () {
892
+ expect(S.testNilike({nilike: 'value'}, 'val')).to.be.true;
893
+ 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
+ 'A first argument of OperatorUtils.testNilike ' +
935
+ 'should be an Object, but 10 given.',
936
+ );
937
+ });
938
+
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);
949
+ });
950
+
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);
955
+ });
956
+ });
957
+
958
+ describe('testRegexp', function () {
959
+ it('returns undefined if no operator given', function () {
960
+ const result = S.testRegexp({}, 'value');
961
+ expect(result).to.be.undefined;
962
+ });
963
+
964
+ it('returns true if a given value matches a substring', function () {
965
+ expect(S.testRegexp({regexp: 'val'}, 'value')).to.be.true;
966
+ expect(S.testRegexp({regexp: 'lue'}, 'value')).to.be.true;
967
+ expect(S.testRegexp({regexp: 'value'}, 'value')).to.be.true;
968
+ });
969
+
970
+ it('returns false if a given value not matches a substring', function () {
971
+ expect(S.testRegexp({regexp: 'value'}, 'val')).to.be.false;
972
+ expect(S.testRegexp({regexp: 'value'}, 'lue')).to.be.false;
973
+ expect(S.testRegexp({regexp: 'value'}, 'foo')).to.be.false;
974
+ });
975
+
976
+ it('uses case-sensitive matching for a substring', function () {
977
+ expect(S.testRegexp({regexp: 'Val'}, 'value')).to.be.false;
978
+ expect(S.testRegexp({regexp: 'Val'}, 'Value')).to.be.true;
979
+ expect(S.testRegexp({regexp: 'val'}, 'Value')).to.be.false;
980
+ });
981
+
982
+ it('returns true if a given value matches a string expression', function () {
983
+ expect(S.testRegexp({regexp: 'val.+'}, 'value')).to.be.true;
984
+ });
985
+
986
+ it('returns false if a given value not matches a string expression', function () {
987
+ expect(S.testRegexp({regexp: 'foo.+'}, 'value')).to.be.false;
988
+ });
989
+
990
+ it('uses case-sensitive matching for a string expression', function () {
991
+ expect(S.testRegexp({regexp: 'Val.+'}, 'value')).to.be.false;
992
+ expect(S.testRegexp({regexp: 'Val.+'}, 'Value')).to.be.true;
993
+ expect(S.testRegexp({regexp: 'val.+'}, 'Value')).to.be.false;
994
+ });
995
+
996
+ it('returns true if a given value matches a RegExp', function () {
997
+ expect(S.testRegexp({regexp: /val.+/}, 'value')).to.be.true;
998
+ });
999
+
1000
+ it('returns false if a given value matches a RegExp', function () {
1001
+ expect(S.testRegexp({regexp: /foo.+/}, 'value')).to.be.false;
1002
+ });
1003
+
1004
+ it('uses case-sensitive matching for a RegExp', function () {
1005
+ expect(S.testRegexp({regexp: /Val.+/}, 'value')).to.be.false;
1006
+ expect(S.testRegexp({regexp: /Val.+/}, 'Value')).to.be.true;
1007
+ expect(S.testRegexp({regexp: /val.+/}, 'Value')).to.be.false;
1008
+ });
1009
+
1010
+ it('returns false if a given value is not a string', function () {
1011
+ expect(S.testRegexp({regexp: /val.+/}, 10)).to.be.false;
1012
+ expect(S.testRegexp({regexp: /val.+/}, '')).to.be.false;
1013
+ });
1014
+
1015
+ it('uses the "flags" option', function () {
1016
+ expect(S.testRegexp({regexp: /Val.+/}, 'value')).to.be.false;
1017
+ expect(S.testRegexp({regexp: 'Val.+'}, 'value')).to.be.false;
1018
+ expect(S.testRegexp({regexp: /Val.+/, flags: 'i'}, 'value')).to.be.true;
1019
+ expect(S.testRegexp({regexp: 'Val.+', flags: 'i'}, 'value')).to.be.true;
1020
+ });
1021
+
1022
+ it('throws an error if a first argument is not an object', function () {
1023
+ const throwable = () => S.testRegexp(10);
1024
+ expect(throwable).to.throw(
1025
+ 'A first argument of OperatorUtils.testRegexp ' +
1026
+ 'should be an Object, but 10 given.',
1027
+ );
1028
+ });
1029
+
1030
+ it('throws an error if an operator value is a number', function () {
1031
+ const regexp = 10;
1032
+ const throwable = () => S.testRegexp({regexp}, 10);
1033
+ expect(throwable).to.throw(InvalidOperatorValueError);
1034
+ });
1035
+
1036
+ it('throws an error if an operator value is an object', function () {
1037
+ const regexp = {};
1038
+ const throwable = () => S.testRegexp({regexp}, 10);
1039
+ expect(throwable).to.throw(InvalidOperatorValueError);
1040
+ });
1041
+
1042
+ it('throws an error if an operator value is a null', function () {
1043
+ const regexp = null;
1044
+ const throwable = () => S.testRegexp({regexp}, 10);
1045
+ expect(throwable).to.throw(InvalidOperatorValueError);
1046
+ });
1047
+
1048
+ it('throws an error if a "flags" value is not a string', function () {
1049
+ const throwable = v => () =>
1050
+ S.testRegexp({regexp: 'Val.+', flags: v}, 'val');
1051
+ const error = v =>
1052
+ format('RegExp flags must be a String, but %s given.', v);
1053
+ expect(throwable(10)).to.throw(error('10'));
1054
+ expect(throwable(true)).to.throw(error('true'));
1055
+ expect(throwable([])).to.throw(error('Array'));
1056
+ expect(throwable({})).to.throw(error('Object'));
1057
+ throwable('')();
1058
+ throwable(0)();
1059
+ throwable(false)();
1060
+ throwable(undefined)();
1061
+ throwable(null)();
1062
+ });
1063
+ });
1064
+ });