@everyonesoftware/common 1.0.0

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 (163) hide show
  1. package/.c8rc.json +12 -0
  2. package/.github/workflows/publish.yml +38 -0
  3. package/.mocharc.json +9 -0
  4. package/README.md +9 -0
  5. package/package.json +36 -0
  6. package/sources/assertMessageParameters.ts +22 -0
  7. package/sources/asyncIterator.ts +437 -0
  8. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
  9. package/sources/asyncResult.ts +95 -0
  10. package/sources/basicDisposable.ts +57 -0
  11. package/sources/byteList.ts +202 -0
  12. package/sources/byteListStream.ts +121 -0
  13. package/sources/byteReadStream.ts +24 -0
  14. package/sources/byteWriteStream.ts +16 -0
  15. package/sources/bytes.ts +25 -0
  16. package/sources/characterList.ts +195 -0
  17. package/sources/characterListStream.ts +151 -0
  18. package/sources/characterReadStream.ts +81 -0
  19. package/sources/characterReadStreamIterator.ts +128 -0
  20. package/sources/characterWriteStream.ts +45 -0
  21. package/sources/commandLineParameter.ts +45 -0
  22. package/sources/commandLineParameters.ts +21 -0
  23. package/sources/comparable.ts +144 -0
  24. package/sources/comparer.ts +133 -0
  25. package/sources/comparison.ts +20 -0
  26. package/sources/concatenateIterable.ts +119 -0
  27. package/sources/concatenateIterator.ts +165 -0
  28. package/sources/condition.ts +329 -0
  29. package/sources/currentProcess.ts +158 -0
  30. package/sources/dateTime.ts +130 -0
  31. package/sources/depthFirstSearch.ts +230 -0
  32. package/sources/disposable.ts +31 -0
  33. package/sources/emptyError.ts +10 -0
  34. package/sources/english.ts +45 -0
  35. package/sources/equalFunctions.ts +123 -0
  36. package/sources/fetchHttpClient.ts +89 -0
  37. package/sources/fetchHttpResponse.ts +106 -0
  38. package/sources/flatMapIterable.ts +104 -0
  39. package/sources/flatMapIterator.ts +152 -0
  40. package/sources/generator.ts +251 -0
  41. package/sources/httpClient.ts +36 -0
  42. package/sources/httpHeader.ts +37 -0
  43. package/sources/httpHeaders.ts +216 -0
  44. package/sources/httpIncomingRequest.ts +30 -0
  45. package/sources/httpIncomingResponse.ts +19 -0
  46. package/sources/httpMethod.ts +164 -0
  47. package/sources/httpOutgoingRequest.ts +119 -0
  48. package/sources/httpOutgoingResponse.ts +113 -0
  49. package/sources/httpServer.ts +34 -0
  50. package/sources/inMemoryCharacterWriteStream.ts +78 -0
  51. package/sources/index.ts +101 -0
  52. package/sources/iterable.ts +345 -0
  53. package/sources/iterator.ts +481 -0
  54. package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
  55. package/sources/javascript.ts +59 -0
  56. package/sources/javascriptArrayList.ts +175 -0
  57. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
  58. package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
  59. package/sources/javascriptMapMap.ts +143 -0
  60. package/sources/javascriptSetSet.ts +134 -0
  61. package/sources/list.ts +330 -0
  62. package/sources/listQueue.ts +62 -0
  63. package/sources/listStack.ts +62 -0
  64. package/sources/luxonDateTime.ts +109 -0
  65. package/sources/map.ts +302 -0
  66. package/sources/mapAsyncIterator.ts +141 -0
  67. package/sources/mapIterable.ts +105 -0
  68. package/sources/mapIterator.ts +145 -0
  69. package/sources/mutableCondition.ts +451 -0
  70. package/sources/mutableHttpHeaders.ts +204 -0
  71. package/sources/mutableMap.ts +292 -0
  72. package/sources/network.ts +18 -0
  73. package/sources/node.ts +37 -0
  74. package/sources/nodeJSCharacterWriteStream.ts +42 -0
  75. package/sources/nodeJSHttpIncomingRequest.ts +132 -0
  76. package/sources/nodeJSHttpServer.ts +134 -0
  77. package/sources/notFoundError.ts +12 -0
  78. package/sources/postCondition.ts +284 -0
  79. package/sources/postConditionError.ts +12 -0
  80. package/sources/preCondition.ts +284 -0
  81. package/sources/preConditionError.ts +12 -0
  82. package/sources/promiseAsyncResult.ts +174 -0
  83. package/sources/property.ts +63 -0
  84. package/sources/queue.ts +49 -0
  85. package/sources/realNetwork.ts +28 -0
  86. package/sources/recreationDotGovClient.ts +259 -0
  87. package/sources/searchControl.ts +42 -0
  88. package/sources/set.ts +244 -0
  89. package/sources/skipAsyncIterator.ts +145 -0
  90. package/sources/skipIterator.ts +155 -0
  91. package/sources/stack.ts +48 -0
  92. package/sources/stringComparer.ts +33 -0
  93. package/sources/stringIterator.ts +149 -0
  94. package/sources/strings.ts +322 -0
  95. package/sources/syncResult.ts +300 -0
  96. package/sources/takeAsyncIterator.ts +141 -0
  97. package/sources/takeIterator.ts +151 -0
  98. package/sources/toStringFunctions.ts +185 -0
  99. package/sources/types.ts +371 -0
  100. package/sources/whereAsyncIterator.ts +143 -0
  101. package/sources/whereIterable.ts +108 -0
  102. package/sources/whereIterator.ts +157 -0
  103. package/sources/wonderlandTrailClient.ts +1503 -0
  104. package/tests/assertTest.ts +113 -0
  105. package/tests/assertTestTests.ts +75 -0
  106. package/tests/basicTestSkip.ts +51 -0
  107. package/tests/byteListStreamTests.ts +390 -0
  108. package/tests/byteListTests.ts +27 -0
  109. package/tests/bytesTests.ts +43 -0
  110. package/tests/characterListStreamTests.ts +391 -0
  111. package/tests/characterListTests.ts +250 -0
  112. package/tests/characterWriteStreamTests.ts +12 -0
  113. package/tests/comparerTests.ts +92 -0
  114. package/tests/conditionTests.ts +877 -0
  115. package/tests/consoleTestRunner.ts +404 -0
  116. package/tests/consoleTestRunnerTests.ts +651 -0
  117. package/tests/dateTimeTests.ts +30 -0
  118. package/tests/depthFirstSearchTests.ts +106 -0
  119. package/tests/disposableTests.ts +121 -0
  120. package/tests/englishTests.ts +103 -0
  121. package/tests/equalFunctionsTests.ts +223 -0
  122. package/tests/failedTest.ts +43 -0
  123. package/tests/fetchHttpClientTests.ts +33 -0
  124. package/tests/generatorTests.ts +86 -0
  125. package/tests/httpClientTests.ts +18 -0
  126. package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
  127. package/tests/iterableTests.ts +141 -0
  128. package/tests/iteratorTests.ts +1086 -0
  129. package/tests/javascriptMapMapTests.ts +21 -0
  130. package/tests/listTests.ts +338 -0
  131. package/tests/mapIteratorTests.ts +55 -0
  132. package/tests/mapTests.ts +104 -0
  133. package/tests/mutableConditionTests.ts +273 -0
  134. package/tests/mutableMapTests.ts +154 -0
  135. package/tests/nodeJSHttpServerTests.ts +75 -0
  136. package/tests/notFoundErrorTests.ts +24 -0
  137. package/tests/postConditionErrorTests.ts +24 -0
  138. package/tests/preConditionErrorTests.ts +24 -0
  139. package/tests/promiseAsyncResultTests.ts +688 -0
  140. package/tests/propertyTests.ts +63 -0
  141. package/tests/queueTests.ts +29 -0
  142. package/tests/recreationDotGovClientTests.ts +191 -0
  143. package/tests/setTests.ts +140 -0
  144. package/tests/skippedTest.ts +39 -0
  145. package/tests/stackTests.ts +66 -0
  146. package/tests/stringComparerTests.ts +60 -0
  147. package/tests/stringIteratorTests.ts +156 -0
  148. package/tests/stringsTests.ts +516 -0
  149. package/tests/syncResultTests.ts +1251 -0
  150. package/tests/test.ts +228 -0
  151. package/tests/testAction.ts +75 -0
  152. package/tests/testActionTests.ts +93 -0
  153. package/tests/testFailureTests.ts +12 -0
  154. package/tests/testRunner.ts +267 -0
  155. package/tests/testRunnerTests.ts +895 -0
  156. package/tests/testSkip.ts +34 -0
  157. package/tests/tests.ts +103 -0
  158. package/tests/toStringFunctionsTests.ts +55 -0
  159. package/tests/typesTests.ts +257 -0
  160. package/tests/whereIteratorTests.ts +77 -0
  161. package/tests/wonderlandTrailClientTests.ts +452 -0
  162. package/tsconfig.json +17 -0
  163. package/tsup.config.ts +13 -0
@@ -0,0 +1,877 @@
1
+ import { Condition } from "../sources/condition";
2
+ import { JavascriptIterable } from "../sources/javascript";
3
+ import { MutableCondition } from "../sources/mutableCondition";
4
+ import { PreConditionError } from "../sources/preConditionError";
5
+ import { join } from "../sources/strings";
6
+ import { Test } from "./test";
7
+ import { TestRunner } from "./testRunner";
8
+
9
+ export function test(runner: TestRunner): void
10
+ {
11
+ runner.testFile("condition.ts", () =>
12
+ {
13
+ runner.testType("Condition", () =>
14
+ {
15
+ runner.testFunction("create()", (test: Test) =>
16
+ {
17
+ const condition: MutableCondition = Condition.create();
18
+ test.assertNotUndefinedAndNotNull(condition);
19
+ test.assertThrows(() => condition.assertFalse(true),
20
+ new Error([
21
+ "Expected: false",
22
+ "Actual: true",
23
+ ].join("\n")));
24
+ });
25
+
26
+ runner.testFunction("assertUndefined(unknown,string?,string?)", () =>
27
+ {
28
+ runner.test("with undefined", () =>
29
+ {
30
+ const condition: MutableCondition = Condition.create();
31
+ condition.assertUndefined(undefined, "fake-expression", "fake-message");
32
+ });
33
+
34
+ function assertUndefinedErrorTest(value: unknown, expected: Error): void
35
+ {
36
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
37
+ {
38
+ const condition: MutableCondition = Condition.create();
39
+ test.assertThrows(() => condition.assertUndefined(value), expected);
40
+ });
41
+ }
42
+
43
+ assertUndefinedErrorTest(
44
+ null,
45
+ new Error(join("\n", [
46
+ "Expected: undefined",
47
+ "Actual: null",
48
+ ])));
49
+ assertUndefinedErrorTest(
50
+ "",
51
+ new Error(join("\n", [
52
+ "Expected: undefined",
53
+ "Actual: \"\"",
54
+ ])));
55
+ assertUndefinedErrorTest(
56
+ 50,
57
+ new Error(join("\n", [
58
+ "Expected: undefined",
59
+ "Actual: 50",
60
+ ])));
61
+ });
62
+
63
+ runner.testFunction("assertNotUndefinedAndNotNull<T>(undefined|null|T,string?,string?)", () =>
64
+ {
65
+ runner.test("with undefined", (test: Test) =>
66
+ {
67
+ const condition: MutableCondition = Condition.create();
68
+ test.assertThrows(() => condition.assertNotUndefinedAndNotNull(undefined),
69
+ new Error([
70
+ "Expected: not undefined and not null",
71
+ "Actual: undefined",
72
+ ].join("\n")));
73
+ });
74
+
75
+ runner.test("with null", (test: Test) =>
76
+ {
77
+ const condition: MutableCondition = Condition.create();
78
+ test.assertThrows(() => condition.assertNotUndefinedAndNotNull(null),
79
+ new Error([
80
+ "Expected: not undefined and not null",
81
+ "Actual: null",
82
+ ].join("\n")));
83
+ });
84
+
85
+ runner.test("with not undefined and not null", (test: Test) =>
86
+ {
87
+ function valueCreator(): string | undefined
88
+ {
89
+ return "hello";
90
+ }
91
+
92
+ const condition: MutableCondition = Condition.create();
93
+ const value: string | undefined = valueCreator();
94
+ condition.assertNotUndefinedAndNotNull(value);
95
+ test.assertEqual(value.substring(1, 3), "el");
96
+ });
97
+
98
+ runner.test("with undefined and expression", (test: Test) =>
99
+ {
100
+ const condition: MutableCondition = Condition.create();
101
+ test.assertThrows(() => condition.assertNotUndefinedAndNotNull(undefined, "fake-expression"),
102
+ new Error([
103
+ "Expression: fake-expression",
104
+ "Expected: not undefined and not null",
105
+ "Actual: undefined"
106
+ ].join("\n")));
107
+ });
108
+
109
+ runner.test("with null, expression, and message", (test: Test) =>
110
+ {
111
+ const condition: MutableCondition = Condition.create();
112
+ test.assertThrows(() => condition.assertNotUndefinedAndNotNull(null, "fake-expression", "fake-message"),
113
+ new Error([
114
+ "Message: fake-message",
115
+ "Expression: fake-expression",
116
+ "Expected: not undefined and not null",
117
+ "Actual: null"
118
+ ].join("\n")));
119
+ });
120
+ });
121
+
122
+ runner.testFunction("assertTrue(boolean)", () =>
123
+ {
124
+ runner.test("with false", (test: Test) =>
125
+ {
126
+ const condition: MutableCondition = Condition.create();
127
+ test.assertThrows(() => condition.assertTrue(false),
128
+ new Error([
129
+ "Expected: true",
130
+ "Actual: false",
131
+ ].join("\n")));
132
+ });
133
+
134
+ runner.test("with true", (test: Test) =>
135
+ {
136
+ function valueCreator(): boolean { return true; }
137
+ const condition: MutableCondition = Condition.create();
138
+ const value: boolean = valueCreator();
139
+ condition.assertTrue(value);
140
+ test.assertTrue(value);
141
+ });
142
+ });
143
+
144
+ runner.testFunction("assertFalse(boolean)", () =>
145
+ {
146
+ runner.test("with true", (test: Test) =>
147
+ {
148
+ const condition: MutableCondition = Condition.create();
149
+ test.assertThrows(() => condition.assertFalse(true),
150
+ new Error([
151
+ "Expected: false",
152
+ "Actual: true",
153
+ ].join("\n")));
154
+ });
155
+
156
+ runner.test("with false", (test: Test) =>
157
+ {
158
+ function valueCreator(): boolean { return false; }
159
+ const condition: MutableCondition = Condition.create();
160
+ const value: boolean = valueCreator();
161
+ condition.assertFalse(value);
162
+ test.assertFalse(value);
163
+ });
164
+ });
165
+
166
+ runner.testFunction("assertSame<T>(T,T,string?,string?)", () =>
167
+ {
168
+ function assertSameErrorTest<T>(expected: T, actual: T, expression: string | undefined, message: string | undefined, expectedError: Error): void
169
+ {
170
+ runner.test(`with ${runner.andList([expected, actual, expression, message])}`, (test: Test) =>
171
+ {
172
+ const condition: MutableCondition = Condition.create();
173
+ test.assertThrows(() => condition.assertSame(expected, actual, expression, message), expectedError);
174
+ });
175
+ }
176
+
177
+ assertSameErrorTest(
178
+ undefined,
179
+ null,
180
+ "fake-expression",
181
+ "fake-message",
182
+ new Error(join("\n", [
183
+ "Message: fake-message",
184
+ "Expression: fake-expression",
185
+ "Expected: undefined",
186
+ "Actual: null",
187
+ ])));
188
+ assertSameErrorTest(
189
+ 3,
190
+ 4,
191
+ "fake-expression",
192
+ "fake-message",
193
+ new Error(join("\n", [
194
+ "Message: fake-message",
195
+ "Expression: fake-expression",
196
+ "Expected: 3",
197
+ "Actual: 4",
198
+ ])));
199
+ assertSameErrorTest(
200
+ {},
201
+ {},
202
+ "fake-expression",
203
+ "fake-message",
204
+ new Error(join("\n", [
205
+ "Message: fake-message",
206
+ "Expression: fake-expression",
207
+ "Expected: {}",
208
+ "Actual: {}",
209
+ ])));
210
+ assertSameErrorTest(
211
+ { "a": "b" },
212
+ { "a": "b" },
213
+ "fake-expression",
214
+ "fake-message",
215
+ new Error(join("\n", [
216
+ "Message: fake-message",
217
+ "Expression: fake-expression",
218
+ "Expected: {\"a\":\"b\"}",
219
+ "Actual: {\"a\":\"b\"}",
220
+ ])));
221
+ assertSameErrorTest(
222
+ [],
223
+ [],
224
+ "fake-expression",
225
+ "fake-message",
226
+ new Error(join("\n", [
227
+ "Message: fake-message",
228
+ "Expression: fake-expression",
229
+ "Expected: []",
230
+ "Actual: []",
231
+ ])));
232
+
233
+ function assertSameTest<T>(expected: T, actual: T, expression: string | undefined, message: string | undefined): void
234
+ {
235
+ runner.test(`with ${runner.andList([expected, actual, expression, message])}`, (_test: Test) =>
236
+ {
237
+ const condition: MutableCondition = Condition.create();
238
+ condition.assertSame(expected, actual, expression, message);
239
+ });
240
+ }
241
+
242
+ assertSameTest(undefined, undefined, "fake-expression", "fake-message");
243
+ assertSameTest(null, null, "fake-expression", "fake-message");
244
+ assertSameTest(0, 0, "fake-expression", "fake-message");
245
+ assertSameTest(10, 10, "fake-expression", "fake-message");
246
+ assertSameTest(true, true, "fake-expression", "fake-message");
247
+ assertSameTest("abc", "abc", "fake-expression", "fake-message");
248
+
249
+ const o = {};
250
+ assertSameTest(o, o, "fake-expression", "fake-message");
251
+ });
252
+
253
+ runner.testFunction("assertNotSame<T>(T,T,string?,string?)", () =>
254
+ {
255
+ function assertNotSameErrorTest<T>(expected: T, actual: T, expression: string | undefined, message: string | undefined, expectedError: Error): void
256
+ {
257
+ runner.test(`with ${runner.andList([expected, actual, expression, message])}`, (test: Test) =>
258
+ {
259
+ const condition: MutableCondition = Condition.create();
260
+ test.assertThrows(() => condition.assertNotSame(expected, actual, expression, message), expectedError);
261
+ });
262
+ }
263
+
264
+ assertNotSameErrorTest(
265
+ undefined,
266
+ undefined,
267
+ "fake-expression",
268
+ "fake-message",
269
+ new Error(join("\n", [
270
+ "Message: fake-message",
271
+ "Expression: fake-expression",
272
+ "Expected: not undefined",
273
+ "Actual: undefined",
274
+ ])));
275
+ assertNotSameErrorTest(
276
+ null,
277
+ null,
278
+ "fake-expression",
279
+ "fake-message",
280
+ new Error(join("\n", [
281
+ "Message: fake-message",
282
+ "Expression: fake-expression",
283
+ "Expected: not null",
284
+ "Actual: null",
285
+ ])));
286
+ assertNotSameErrorTest(
287
+ 0,
288
+ 0,
289
+ "fake-expression",
290
+ "fake-message",
291
+ new Error(join("\n", [
292
+ "Message: fake-message",
293
+ "Expression: fake-expression",
294
+ "Expected: not 0",
295
+ "Actual: 0",
296
+ ])));
297
+ assertNotSameErrorTest(
298
+ 10,
299
+ 10,
300
+ "fake-expression",
301
+ "fake-message",
302
+ new Error(join("\n", [
303
+ "Message: fake-message",
304
+ "Expression: fake-expression",
305
+ "Expected: not 10",
306
+ "Actual: 10",
307
+ ])));
308
+ assertNotSameErrorTest(
309
+ true,
310
+ true,
311
+ "fake-expression",
312
+ "fake-message",
313
+ new Error(join("\n", [
314
+ "Message: fake-message",
315
+ "Expression: fake-expression",
316
+ "Expected: not true",
317
+ "Actual: true",
318
+ ])));
319
+ assertNotSameErrorTest(
320
+ "abc",
321
+ "abc",
322
+ "fake-expression",
323
+ "fake-message",
324
+ new Error(join("\n", [
325
+ "Message: fake-message",
326
+ "Expression: fake-expression",
327
+ "Expected: not \"abc\"",
328
+ "Actual: \"abc\"",
329
+ ])));
330
+
331
+ const o = {};
332
+ assertNotSameErrorTest(
333
+ o,
334
+ o,
335
+ "fake-expression",
336
+ "fake-message",
337
+ new Error(join("\n", [
338
+ "Message: fake-message",
339
+ "Expression: fake-expression",
340
+ "Expected: not {}",
341
+ "Actual: {}",
342
+ ])));
343
+
344
+ function assertNotSameTest<T>(expected: T, actual: T, expression: string | undefined, message: string | undefined): void
345
+ {
346
+ runner.test(`with ${runner.andList([expected, actual, expression, message])}`, (_test: Test) =>
347
+ {
348
+ const condition: MutableCondition = Condition.create();
349
+ condition.assertNotSame(expected, actual, expression, message);
350
+ });
351
+ }
352
+
353
+ assertNotSameTest(undefined, null, "fake-expression", "fake-message");
354
+ assertNotSameTest(false, true, "fake-expression", "fake-message");
355
+ assertNotSameTest(1, 2, "fake-expression", "fake-message");
356
+ assertNotSameTest({}, {}, "fake-expression", "fake-message");
357
+ assertNotSameTest({ "a": "b" }, { "a": "b" }, "fake-expression", "fake-message");
358
+ assertNotSameTest([], [], "fake-expression", "fake-message");
359
+ });
360
+
361
+ runner.testFunction("assertNotEmpty(string,string?,string?)", () =>
362
+ {
363
+ function assertNotEmptyErrorTest(value: string, expression: string | undefined, message: string | undefined, expectedError: Error): void
364
+ {
365
+ runner.test(`with ${runner.andList([value, expression, message])}`, (test: Test) =>
366
+ {
367
+ const condition: MutableCondition = Condition.create();
368
+ test.assertThrows(() => condition.assertNotEmpty(value, expression, message), expectedError);
369
+ });
370
+ }
371
+
372
+ assertNotEmptyErrorTest(undefined!, "fake-expression", "fake-message", new Error(join("\n", [
373
+ "Message: fake-message",
374
+ "Expression: fake-expression",
375
+ "Expected: not undefined and not null",
376
+ "Actual: undefined",
377
+ ])));
378
+ assertNotEmptyErrorTest(null!, "fake-expression", "fake-message", new Error(join("\n", [
379
+ "Message: fake-message",
380
+ "Expression: fake-expression",
381
+ "Expected: not undefined and not null",
382
+ "Actual: null",
383
+ ])));
384
+ assertNotEmptyErrorTest("", "fake-expression", "fake-message", new Error(join("\n", [
385
+ "Message: fake-message",
386
+ "Expression: fake-expression",
387
+ "Expected: not empty",
388
+ "Actual: \"\"",
389
+ ])));
390
+
391
+ function assertNotEmptyTest(value: string, expression: string | undefined, message: string | undefined): void
392
+ {
393
+ runner.test(`with ${runner.andList([value, expression, message])}`, (_test: Test) =>
394
+ {
395
+ const condition: MutableCondition = Condition.create();
396
+ condition.assertNotEmpty(value, expression, message);
397
+ });
398
+ }
399
+
400
+ assertNotEmptyTest(" ", "fake-expression", "fake-message");
401
+ assertNotEmptyTest("a", "fake-expression", "fake-message");
402
+ });
403
+
404
+ runner.testFunction("assertLessThan(number,number,string?,string?)", () =>
405
+ {
406
+ function assertLessThanErrorTest(value: number, upperBound: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
407
+ {
408
+ runner.test(`with ${runner.andList([value, upperBound])}`, (test: Test) =>
409
+ {
410
+ const condition: MutableCondition = Condition.create();
411
+ test.assertThrows(() => condition.assertLessThan(value, upperBound, expression, message), expectedError);
412
+ });
413
+ }
414
+
415
+ assertLessThanErrorTest(-1, -1, undefined, undefined, new Error(join("\n", [
416
+ "Expected: less than -1",
417
+ "Actual: -1",
418
+ ])));
419
+ assertLessThanErrorTest(0, 0, undefined, undefined, new Error(join("\n", [
420
+ "Expected: less than 0",
421
+ "Actual: 0",
422
+ ])));
423
+ assertLessThanErrorTest(2, 1, undefined, undefined, new Error(join("\n", [
424
+ "Expected: less than 1",
425
+ "Actual: 2",
426
+ ])));
427
+ assertLessThanErrorTest(2, 1, "fake-expression", "fake-message", new Error(join("\n", [
428
+ "Message: fake-message",
429
+ "Expression: fake-expression",
430
+ "Expected: less than 1",
431
+ "Actual: 2",
432
+ ])));
433
+
434
+ function assertLessThanTest(value: number, upperBound: number, expression?: string, message?: string): void
435
+ {
436
+ runner.test(`with ${runner.andList([value, upperBound])}`, () =>
437
+ {
438
+ const condition: MutableCondition = Condition.create();
439
+ condition.assertLessThan(value, upperBound, expression, message);
440
+ });
441
+ }
442
+
443
+ assertLessThanTest(-10, -9);
444
+ assertLessThanTest(-1, 0);
445
+ assertLessThanTest(0, 1);
446
+ assertLessThanTest(4, 5);
447
+ });
448
+
449
+ runner.testFunction("assertLessThanOrEqualTo(number,number,string?,string?)", () =>
450
+ {
451
+ function assertLessThanOrEqualToErrorTest(value: number, upperBound: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
452
+ {
453
+ runner.test(`with ${runner.andList([value, upperBound])}`, (test: Test) =>
454
+ {
455
+ const condition: MutableCondition = Condition.create();
456
+ test.assertThrows(() => condition.assertLessThanOrEqualTo(value, upperBound, expression, message), expectedError);
457
+ });
458
+ }
459
+
460
+ assertLessThanOrEqualToErrorTest(2, 1, undefined, undefined, new Error(join("\n", [
461
+ "Expected: less than or equal to 1",
462
+ "Actual: 2",
463
+ ])));
464
+ assertLessThanOrEqualToErrorTest(2, 1, "fake-expression", "fake-message", new Error(join("\n", [
465
+ "Message: fake-message",
466
+ "Expression: fake-expression",
467
+ "Expected: less than or equal to 1",
468
+ "Actual: 2",
469
+ ])));
470
+
471
+ function assertLessThanOrEqualToTest(value: number, upperBound: number, expression: string | undefined, message: string | undefined): void
472
+ {
473
+ runner.test(`with ${runner.andList([value, upperBound])}`, () =>
474
+ {
475
+ const condition: MutableCondition = Condition.create();
476
+ condition.assertLessThanOrEqualTo(value, upperBound, expression, message);
477
+ });
478
+ }
479
+
480
+ assertLessThanOrEqualToTest(-10, -9, undefined, undefined);
481
+ assertLessThanOrEqualToTest(-1, 0, undefined, undefined);
482
+ assertLessThanOrEqualToTest(0, 1, undefined, undefined);
483
+ assertLessThanOrEqualToTest(4, 5, undefined, undefined);
484
+ assertLessThanOrEqualToTest(-1, -1, undefined, undefined);
485
+ assertLessThanOrEqualToTest(0, 0, undefined, undefined);
486
+ assertLessThanOrEqualToTest(1, 1, undefined, undefined);
487
+ });
488
+
489
+ runner.testFunction("assertGreaterThanOrEqualTo(number,number,string?,string?)", () =>
490
+ {
491
+ function assertGreaterThanOrEqualToErrorTest(value: number, lowerBound: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
492
+ {
493
+ runner.test(`with ${runner.andList([value, lowerBound])}`, (test: Test) =>
494
+ {
495
+ const condition: MutableCondition = Condition.create();
496
+ test.assertThrows(() => condition.assertGreaterThanOrEqualTo(value, lowerBound, expression, message), expectedError);
497
+ });
498
+ }
499
+
500
+ assertGreaterThanOrEqualToErrorTest(1, 2, undefined, undefined, new Error(join("\n", [
501
+ "Expected: greater than or equal to 2",
502
+ "Actual: 1",
503
+ ])));
504
+ assertGreaterThanOrEqualToErrorTest(1, 2, "fake-expression", "fake-message", new Error(join("\n", [
505
+ "Message: fake-message",
506
+ "Expression: fake-expression",
507
+ "Expected: greater than or equal to 2",
508
+ "Actual: 1",
509
+ ])));
510
+
511
+ function assertGreaterThanOrEqualToTest(value: number, lowerBound: number, expression?: string, message?: string): void
512
+ {
513
+ runner.test(`with ${runner.andList([value, lowerBound])}`, (_test: Test) =>
514
+ {
515
+ const condition: MutableCondition = Condition.create();
516
+ condition.assertGreaterThanOrEqualTo(value, lowerBound, expression, message);
517
+ });
518
+ }
519
+
520
+ assertGreaterThanOrEqualToTest(-9, -10);
521
+ assertGreaterThanOrEqualToTest(0, -1);
522
+ assertGreaterThanOrEqualToTest(1, 0);
523
+ assertGreaterThanOrEqualToTest(5, 4);
524
+ assertGreaterThanOrEqualToTest(-1, -1);
525
+ assertGreaterThanOrEqualToTest(0, 0);
526
+ assertGreaterThanOrEqualToTest(1, 1);
527
+ });
528
+
529
+ runner.testFunction("assertGreaterThan(number,number,string?,string?)", () =>
530
+ {
531
+ function assertGreaterThanErrorTest(value: number, lowerBound: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
532
+ {
533
+ runner.test(`with ${runner.andList([value, lowerBound])}`, (test: Test) =>
534
+ {
535
+ const condition: MutableCondition = Condition.create();
536
+ test.assertThrows(() => condition.assertGreaterThan(value, lowerBound, expression, message), expectedError);
537
+ });
538
+ }
539
+
540
+ assertGreaterThanErrorTest(-1, -1, undefined, undefined, new Error(join("\n", [
541
+ "Expected: greater than -1",
542
+ "Actual: -1",
543
+ ])));
544
+ assertGreaterThanErrorTest(0, 0, undefined, undefined, new Error(join("\n", [
545
+ "Expected: greater than 0",
546
+ "Actual: 0",
547
+ ])));
548
+ assertGreaterThanErrorTest(1, 2, undefined, undefined, new Error(join("\n", [
549
+ "Expected: greater than 2",
550
+ "Actual: 1",
551
+ ])));
552
+ assertGreaterThanErrorTest(1, 2, "fake-expression", "fake-message", new Error(join("\n", [
553
+ "Message: fake-message",
554
+ "Expression: fake-expression",
555
+ "Expected: greater than 2",
556
+ "Actual: 1",
557
+ ])));
558
+
559
+ function assertGreaterThanTest(value: number, lowerBound: number, expression?: string, message?: string): void
560
+ {
561
+ runner.test(`with ${runner.andList([value, lowerBound])}`, (_test: Test) =>
562
+ {
563
+ const condition: MutableCondition = Condition.create();
564
+ condition.assertGreaterThan(value, lowerBound, expression, message);
565
+ });
566
+ }
567
+
568
+ assertGreaterThanTest(-9, -10);
569
+ assertGreaterThanTest(0, -1);
570
+ assertGreaterThanTest(1, 0);
571
+ assertGreaterThanTest(5, 4);
572
+ });
573
+
574
+ runner.testFunction("assertBetween(number,number,number,string?,string?)", () =>
575
+ {
576
+ function assertBetweenErrorTest(lowerBound: number, value: number, upperBound: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
577
+ {
578
+ runner.test(`with ${runner.andList([lowerBound, value, upperBound])}`, (test: Test) =>
579
+ {
580
+ const condition: MutableCondition = Condition.create();
581
+ test.assertThrows(() => condition.assertBetween(lowerBound, value, upperBound, expression, message), expectedError);
582
+ });
583
+ }
584
+
585
+ assertBetweenErrorTest(0, 1, 0, undefined, undefined, new Error(join("\n", [
586
+ "Expected: 0",
587
+ "Actual: 1",
588
+ ])));
589
+ assertBetweenErrorTest(0, -1, 0, undefined, undefined, new Error(join("\n", [
590
+ "Expected: 0",
591
+ "Actual: -1",
592
+ ])));
593
+ assertBetweenErrorTest(0, -1, 2, undefined, undefined, new Error(join("\n", [
594
+ "Expected: between 0 and 2",
595
+ "Actual: -1",
596
+ ])));
597
+ assertBetweenErrorTest(0, 3, 2, undefined, undefined, new Error(join("\n", [
598
+ "Expected: between 0 and 2",
599
+ "Actual: 3",
600
+ ])));
601
+ assertBetweenErrorTest(5, 3, 2, "fake-expression", "fake-message", new Error(join("\n", [
602
+ "Expression: lowerBound",
603
+ "Expected: less than or equal to 2",
604
+ "Actual: 5",
605
+ ])));
606
+
607
+ function assertBetweenTest(lowerBound: number, value: number, upperBound: number, expression?: string, message?: string): void
608
+ {
609
+ runner.test(`with ${runner.andList([lowerBound, value, upperBound])}`, () =>
610
+ {
611
+ const condition: MutableCondition = Condition.create();
612
+ condition.assertBetween(lowerBound, value, upperBound, expression, message);
613
+ });
614
+ }
615
+
616
+ assertBetweenTest(-12, -11, -10);
617
+ assertBetweenTest(-1, 0, 1);
618
+ assertBetweenTest(0, 1, 2);
619
+ assertBetweenTest(4, 5, 6);
620
+ assertBetweenTest(0, 0, 0);
621
+ assertBetweenTest(1, 1, 1);
622
+ });
623
+
624
+ runner.testFunction("assertAccessIndex(number,number,string?,string?)", () =>
625
+ {
626
+ function assertAccessIndexTest(index: number, count: number, expression?: string, message?: string): void
627
+ {
628
+ runner.test(`with ${runner.andList([index, count])}`, (_test: Test) =>
629
+ {
630
+ const condition: MutableCondition = Condition.create();
631
+ condition.assertAccessIndex(index, count, expression, message);
632
+ });
633
+ }
634
+
635
+ assertAccessIndexTest(0, 1);
636
+ assertAccessIndexTest(0, 2);
637
+ assertAccessIndexTest(1, 2);
638
+
639
+ function assertAccessIndexErrorTest(index: number, count: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
640
+ {
641
+ runner.test(`with ${runner.andList([index, count])}`, (test: Test) =>
642
+ {
643
+ const condition: MutableCondition = Condition.create();
644
+ test.assertThrows(() => condition.assertAccessIndex(index, count, expression, message), expectedError);
645
+ });
646
+ }
647
+
648
+ assertAccessIndexErrorTest(-1, 0, undefined, undefined, new Error(join("\n", [
649
+ "Expression: count",
650
+ "Expected: greater than or equal to 1",
651
+ "Actual: 0",
652
+ ])));
653
+ assertAccessIndexErrorTest(0, 0, undefined, undefined, new Error(join("\n", [
654
+ "Expression: count",
655
+ "Expected: greater than or equal to 1",
656
+ "Actual: 0",
657
+ ])));
658
+ assertAccessIndexErrorTest(1, 0, undefined, undefined, new Error(join("\n", [
659
+ "Expression: count",
660
+ "Expected: greater than or equal to 1",
661
+ "Actual: 0",
662
+ ])));
663
+ assertAccessIndexErrorTest(-1, 1, undefined, undefined, new Error(join("\n", [
664
+ "Expected: 0",
665
+ "Actual: -1",
666
+ ])));
667
+ assertAccessIndexErrorTest(1, 1, undefined, undefined, new Error(join("\n", [
668
+ "Expected: 0",
669
+ "Actual: 1",
670
+ ])));
671
+ assertAccessIndexErrorTest(-1, 2, undefined, undefined, new Error(join("\n", [
672
+ "Expected: between 0 and 1",
673
+ "Actual: -1",
674
+ ])));
675
+ assertAccessIndexErrorTest(1, 1, "fake-expression", "fake-message", new Error(join("\n", [
676
+ "Message: fake-message",
677
+ "Expression: fake-expression",
678
+ "Expected: 0",
679
+ "Actual: 1",
680
+ ])));
681
+ assertAccessIndexErrorTest(3, 2, "fake-expression", "fake-message", new Error(join("\n", [
682
+ "Message: fake-message",
683
+ "Expression: fake-expression",
684
+ "Expected: between 0 and 1",
685
+ "Actual: 3",
686
+ ])));
687
+ });
688
+
689
+ runner.testFunction("assertInsertIndex(number,number,string?,string?)", () =>
690
+ {
691
+ function assertInsertIndexErrorTest(index: number, count: number, expression: string | undefined, message: string | undefined, expectedError: Error): void
692
+ {
693
+ runner.test(`with ${runner.andList([index, count])}`, (test: Test) =>
694
+ {
695
+ const condition: MutableCondition = Condition.create();
696
+ test.assertThrows(() => condition.assertInsertIndex(index, count, expression, message), expectedError);
697
+ });
698
+ }
699
+
700
+ assertInsertIndexErrorTest(-1, 0, undefined, undefined, new Error(join("\n", [
701
+ "Expected: 0",
702
+ "Actual: -1",
703
+ ])));
704
+ assertInsertIndexErrorTest(1, 0, undefined, undefined, new Error(join("\n", [
705
+ "Expected: 0",
706
+ "Actual: 1",
707
+ ])));
708
+ assertInsertIndexErrorTest(-1, 1, undefined, undefined, new Error(join("\n", [
709
+ "Expected: between 0 and 1",
710
+ "Actual: -1",
711
+ ])));
712
+ assertInsertIndexErrorTest(2, 1, undefined, undefined, new Error(join("\n", [
713
+ "Expected: between 0 and 1",
714
+ "Actual: 2",
715
+ ])));
716
+ assertInsertIndexErrorTest(-1, 2, undefined, undefined, new Error(join("\n", [
717
+ "Expected: between 0 and 2",
718
+ "Actual: -1",
719
+ ])));
720
+ assertInsertIndexErrorTest(2, 1, "fake-expression", "fake-message", new Error(join("\n", [
721
+ "Message: fake-message",
722
+ "Expression: fake-expression",
723
+ "Expected: between 0 and 1",
724
+ "Actual: 2",
725
+ ])));
726
+ assertInsertIndexErrorTest(3, 2, "fake-expression", "fake-message", new Error(join("\n", [
727
+ "Message: fake-message",
728
+ "Expression: fake-expression",
729
+ "Expected: between 0 and 2",
730
+ "Actual: 3",
731
+ ])));
732
+
733
+ function assertInsertIndexTest(index: number, count: number, expression?: string, message?: string): void
734
+ {
735
+ runner.test(`with ${runner.andList([index, count])}`, (_test: Test) =>
736
+ {
737
+ const condition: MutableCondition = Condition.create();
738
+ condition.assertInsertIndex(index, count, expression, message);
739
+ });
740
+ }
741
+
742
+ assertInsertIndexTest(0, 0);
743
+ assertInsertIndexTest(0, 1);
744
+ assertInsertIndexTest(1, 1);
745
+ assertInsertIndexTest(0, 2);
746
+ assertInsertIndexTest(1, 2);
747
+ assertInsertIndexTest(2, 2);
748
+ });
749
+
750
+ runner.testFunction("assertOneOf<T>(JavascriptIterable<T>,T,string?,string?)", () =>
751
+ {
752
+ function assertOneOfErrorTest<T>(possibilities: JavascriptIterable<T>, value: T, expression: string | undefined, message: string | undefined, expectedError: Error): void
753
+ {
754
+ runner.test(`with ${runner.andList([possibilities, value, expression, message])}`, (test: Test) =>
755
+ {
756
+ const condition: MutableCondition = Condition.create();
757
+ test.assertThrows(() => condition.assertOneOf(possibilities, value, expression, message), expectedError);
758
+ });
759
+ }
760
+
761
+ assertOneOfErrorTest(
762
+ undefined!,
763
+ 5,
764
+ undefined,
765
+ undefined,
766
+ new PreConditionError(
767
+ "Expression: possibilities",
768
+ "Expected: not undefined and not null",
769
+ "Actual: undefined",
770
+ ));
771
+ assertOneOfErrorTest(
772
+ null!,
773
+ 5,
774
+ undefined,
775
+ undefined,
776
+ new PreConditionError(
777
+ "Expression: possibilities",
778
+ "Expected: not undefined and not null",
779
+ "Actual: null",
780
+ ));
781
+ assertOneOfErrorTest(
782
+ [],
783
+ 5,
784
+ undefined,
785
+ undefined,
786
+ new PreConditionError(
787
+ "Expected: one of []",
788
+ "Actual: 5",
789
+ ));
790
+ assertOneOfErrorTest(
791
+ [],
792
+ 5,
793
+ "fake-expression",
794
+ "fake-message",
795
+ new PreConditionError(
796
+ "Message: fake-message",
797
+ "Expression: fake-expression",
798
+ "Expected: one of []",
799
+ "Actual: 5",
800
+ ));
801
+ assertOneOfErrorTest(
802
+ [1, 2, 3],
803
+ 5,
804
+ "fake-expression",
805
+ "fake-message",
806
+ new PreConditionError(
807
+ "Message: fake-message",
808
+ "Expression: fake-expression",
809
+ "Expected: one of [1,2,3]",
810
+ "Actual: 5",
811
+ ));
812
+
813
+ function assertOneOfTest<T>(possibilities: JavascriptIterable<T>, value: T, expression?: string, message?: string): void
814
+ {
815
+ runner.test(`with ${runner.andList([possibilities, value, expression, message])}`, (_test: Test) =>
816
+ {
817
+ const condition: MutableCondition = Condition.create();
818
+ condition.assertOneOf(possibilities, value, expression, message);
819
+ });
820
+ }
821
+
822
+ assertOneOfTest([5], 5);
823
+ assertOneOfTest([1, 3, 5, 7], 5);
824
+ });
825
+
826
+ runner.testFunction("assertInteger(number,string?,string?)", () =>
827
+ {
828
+ function assertIntegerErrorTest(value: number, expected: Error): void
829
+ {
830
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
831
+ {
832
+ const condition: MutableCondition = Condition.create();
833
+ test.assertThrows(() => condition.assertInteger(value), expected);
834
+ });
835
+ }
836
+
837
+ assertIntegerErrorTest(
838
+ 1.2,
839
+ new Error(join("\n", [
840
+ "Expected: integer",
841
+ "Actual: 1.2",
842
+ ])));
843
+ assertIntegerErrorTest(
844
+ NaN,
845
+ new Error(join("\n", [
846
+ "Expected: integer",
847
+ "Actual: NaN",
848
+ ])));
849
+ assertIntegerErrorTest(
850
+ Infinity,
851
+ new Error(join("\n", [
852
+ "Expected: integer",
853
+ "Actual: Infinity",
854
+ ])));
855
+ assertIntegerErrorTest(
856
+ -Infinity,
857
+ new Error(join("\n", [
858
+ "Expected: integer",
859
+ "Actual: -Infinity",
860
+ ])));
861
+
862
+ function assertIntegerTest(value: number): void
863
+ {
864
+ runner.test(`with ${value}`, (_test: Test) =>
865
+ {
866
+ const condition: MutableCondition = Condition.create();
867
+ condition.assertInteger(value);
868
+ });
869
+ }
870
+
871
+ assertIntegerTest(-1);
872
+ assertIntegerTest(0);
873
+ assertIntegerTest(1);
874
+ });
875
+ });
876
+ });
877
+ }