@everyonesoftware/common 3.0.0 → 4.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 (176) hide show
  1. package/outputs/chunk-AY3YWKOM.js +7741 -0
  2. package/outputs/chunk-AY3YWKOM.js.map +1 -0
  3. package/outputs/sources.cjs +9007 -0
  4. package/outputs/sources.cjs.map +1 -0
  5. package/outputs/sources.d.cts +4082 -0
  6. package/outputs/sources.d.ts +4082 -0
  7. package/outputs/sources.js +1370 -0
  8. package/outputs/sources.js.map +1 -0
  9. package/outputs/tests.cjs +17208 -0
  10. package/outputs/tests.cjs.map +1 -0
  11. package/outputs/tests.d.cts +3 -0
  12. package/outputs/tests.d.ts +3 -0
  13. package/outputs/tests.js +9798 -0
  14. package/outputs/tests.js.map +1 -0
  15. package/package.json +6 -1
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -54
  18. package/.mocharc.json +0 -9
  19. package/sources/assertMessageParameters.ts +0 -22
  20. package/sources/asyncIterator.ts +0 -437
  21. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
  22. package/sources/asyncResult.ts +0 -95
  23. package/sources/basicDisposable.ts +0 -57
  24. package/sources/byteList.ts +0 -202
  25. package/sources/byteListStream.ts +0 -121
  26. package/sources/byteReadStream.ts +0 -24
  27. package/sources/byteWriteStream.ts +0 -16
  28. package/sources/bytes.ts +0 -25
  29. package/sources/characterList.ts +0 -195
  30. package/sources/characterListStream.ts +0 -151
  31. package/sources/characterReadStream.ts +0 -81
  32. package/sources/characterReadStreamIterator.ts +0 -128
  33. package/sources/characterWriteStream.ts +0 -45
  34. package/sources/commandLineParameter.ts +0 -45
  35. package/sources/commandLineParameters.ts +0 -21
  36. package/sources/comparable.ts +0 -144
  37. package/sources/comparer.ts +0 -133
  38. package/sources/comparison.ts +0 -20
  39. package/sources/concatenateIterable.ts +0 -119
  40. package/sources/concatenateIterator.ts +0 -165
  41. package/sources/condition.ts +0 -329
  42. package/sources/currentProcess.ts +0 -158
  43. package/sources/dateTime.ts +0 -130
  44. package/sources/depthFirstSearch.ts +0 -230
  45. package/sources/disposable.ts +0 -31
  46. package/sources/emptyError.ts +0 -10
  47. package/sources/english.ts +0 -45
  48. package/sources/equalFunctions.ts +0 -123
  49. package/sources/fetchHttpClient.ts +0 -89
  50. package/sources/fetchHttpResponse.ts +0 -106
  51. package/sources/flatMapIterable.ts +0 -104
  52. package/sources/flatMapIterator.ts +0 -152
  53. package/sources/generator.ts +0 -251
  54. package/sources/httpClient.ts +0 -36
  55. package/sources/httpHeader.ts +0 -37
  56. package/sources/httpHeaders.ts +0 -216
  57. package/sources/httpIncomingRequest.ts +0 -30
  58. package/sources/httpIncomingResponse.ts +0 -19
  59. package/sources/httpMethod.ts +0 -164
  60. package/sources/httpOutgoingRequest.ts +0 -119
  61. package/sources/httpOutgoingResponse.ts +0 -113
  62. package/sources/httpServer.ts +0 -34
  63. package/sources/inMemoryCharacterWriteStream.ts +0 -78
  64. package/sources/index.ts +0 -101
  65. package/sources/iterable.ts +0 -345
  66. package/sources/iterator.ts +0 -481
  67. package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
  68. package/sources/javascript.ts +0 -59
  69. package/sources/javascriptArrayList.ts +0 -175
  70. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
  71. package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
  72. package/sources/javascriptMapMap.ts +0 -143
  73. package/sources/javascriptSetSet.ts +0 -134
  74. package/sources/list.ts +0 -330
  75. package/sources/listQueue.ts +0 -62
  76. package/sources/listStack.ts +0 -62
  77. package/sources/luxonDateTime.ts +0 -109
  78. package/sources/map.ts +0 -302
  79. package/sources/mapAsyncIterator.ts +0 -141
  80. package/sources/mapIterable.ts +0 -105
  81. package/sources/mapIterator.ts +0 -145
  82. package/sources/mutableCondition.ts +0 -451
  83. package/sources/mutableHttpHeaders.ts +0 -204
  84. package/sources/mutableMap.ts +0 -292
  85. package/sources/network.ts +0 -18
  86. package/sources/node.ts +0 -37
  87. package/sources/nodeJSCharacterWriteStream.ts +0 -42
  88. package/sources/nodeJSHttpIncomingRequest.ts +0 -132
  89. package/sources/nodeJSHttpServer.ts +0 -134
  90. package/sources/notFoundError.ts +0 -12
  91. package/sources/postCondition.ts +0 -284
  92. package/sources/postConditionError.ts +0 -12
  93. package/sources/preCondition.ts +0 -284
  94. package/sources/preConditionError.ts +0 -12
  95. package/sources/promiseAsyncResult.ts +0 -174
  96. package/sources/property.ts +0 -63
  97. package/sources/queue.ts +0 -49
  98. package/sources/realNetwork.ts +0 -28
  99. package/sources/recreationDotGovClient.ts +0 -259
  100. package/sources/searchControl.ts +0 -42
  101. package/sources/set.ts +0 -244
  102. package/sources/skipAsyncIterator.ts +0 -145
  103. package/sources/skipIterator.ts +0 -155
  104. package/sources/stack.ts +0 -48
  105. package/sources/stringComparer.ts +0 -33
  106. package/sources/stringIterator.ts +0 -149
  107. package/sources/strings.ts +0 -322
  108. package/sources/syncResult.ts +0 -300
  109. package/sources/takeAsyncIterator.ts +0 -141
  110. package/sources/takeIterator.ts +0 -151
  111. package/sources/toStringFunctions.ts +0 -185
  112. package/sources/types.ts +0 -371
  113. package/sources/whereAsyncIterator.ts +0 -143
  114. package/sources/whereIterable.ts +0 -108
  115. package/sources/whereIterator.ts +0 -157
  116. package/sources/wonderlandTrailClient.ts +0 -1503
  117. package/tests/assertTest.ts +0 -113
  118. package/tests/assertTestTests.ts +0 -75
  119. package/tests/basicTestSkip.ts +0 -51
  120. package/tests/byteListStreamTests.ts +0 -390
  121. package/tests/byteListTests.ts +0 -27
  122. package/tests/bytesTests.ts +0 -43
  123. package/tests/characterListStreamTests.ts +0 -391
  124. package/tests/characterListTests.ts +0 -250
  125. package/tests/characterWriteStreamTests.ts +0 -12
  126. package/tests/comparerTests.ts +0 -92
  127. package/tests/conditionTests.ts +0 -877
  128. package/tests/consoleTestRunner.ts +0 -404
  129. package/tests/consoleTestRunnerTests.ts +0 -651
  130. package/tests/dateTimeTests.ts +0 -30
  131. package/tests/depthFirstSearchTests.ts +0 -106
  132. package/tests/disposableTests.ts +0 -121
  133. package/tests/englishTests.ts +0 -103
  134. package/tests/equalFunctionsTests.ts +0 -223
  135. package/tests/failedTest.ts +0 -43
  136. package/tests/fetchHttpClientTests.ts +0 -33
  137. package/tests/generatorTests.ts +0 -86
  138. package/tests/httpClientTests.ts +0 -18
  139. package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
  140. package/tests/iterableTests.ts +0 -141
  141. package/tests/iteratorTests.ts +0 -1086
  142. package/tests/javascriptMapMapTests.ts +0 -21
  143. package/tests/listTests.ts +0 -338
  144. package/tests/mapIteratorTests.ts +0 -55
  145. package/tests/mapTests.ts +0 -104
  146. package/tests/mutableConditionTests.ts +0 -273
  147. package/tests/mutableMapTests.ts +0 -154
  148. package/tests/nodeJSHttpServerTests.ts +0 -75
  149. package/tests/notFoundErrorTests.ts +0 -24
  150. package/tests/postConditionErrorTests.ts +0 -24
  151. package/tests/preConditionErrorTests.ts +0 -24
  152. package/tests/promiseAsyncResultTests.ts +0 -688
  153. package/tests/propertyTests.ts +0 -63
  154. package/tests/queueTests.ts +0 -29
  155. package/tests/recreationDotGovClientTests.ts +0 -191
  156. package/tests/setTests.ts +0 -140
  157. package/tests/skippedTest.ts +0 -39
  158. package/tests/stackTests.ts +0 -66
  159. package/tests/stringComparerTests.ts +0 -60
  160. package/tests/stringIteratorTests.ts +0 -156
  161. package/tests/stringsTests.ts +0 -516
  162. package/tests/syncResultTests.ts +0 -1251
  163. package/tests/test.ts +0 -228
  164. package/tests/testAction.ts +0 -75
  165. package/tests/testActionTests.ts +0 -93
  166. package/tests/testFailureTests.ts +0 -12
  167. package/tests/testRunner.ts +0 -267
  168. package/tests/testRunnerTests.ts +0 -895
  169. package/tests/testSkip.ts +0 -34
  170. package/tests/tests.ts +0 -103
  171. package/tests/toStringFunctionsTests.ts +0 -55
  172. package/tests/typesTests.ts +0 -257
  173. package/tests/whereIteratorTests.ts +0 -77
  174. package/tests/wonderlandTrailClientTests.ts +0 -452
  175. package/tsconfig.json +0 -20
  176. package/tsup.config.ts +0 -13
@@ -1,688 +0,0 @@
1
- import { PromiseAsyncResult } from "../sources/promiseAsyncResult";
2
- import { NotFoundError } from "../sources/notFoundError";
3
- import { PreConditionError } from "../sources/preConditionError";
4
- import { Test } from "./test";
5
- import { TestRunner } from "./testRunner";
6
-
7
- export function test(runner: TestRunner): void
8
- {
9
- runner.testFile("promiseAsyncResult.ts", () =>
10
- {
11
- runner.testType("PromiseAsyncResult<T>", () =>
12
- {
13
- runner.testFunction("create()", () =>
14
- {
15
- function createErrorTest<T>(testName: string, promise: Promise<T>, expected: Error): void
16
- {
17
- runner.test(testName, (test: Test) =>
18
- {
19
- test.assertThrows(() => PromiseAsyncResult.create(promise), expected);
20
- });
21
- }
22
-
23
- createErrorTest("with undefined", undefined!, new PreConditionError(
24
- "Expression: action or promise",
25
- "Expected: not undefined and not null",
26
- "Actual: undefined",
27
- ));
28
- createErrorTest("with null", null!, new PreConditionError(
29
- "Expression: action or promise",
30
- "Expected: not undefined and not null",
31
- "Actual: null",
32
- ));
33
-
34
- runner.test("with Promise", async (test: Test) =>
35
- {
36
- const result: PromiseAsyncResult<number> = PromiseAsyncResult.create(Promise.resolve(5));
37
- test.assertNotUndefinedAndNotNull(result);
38
-
39
- const value: number = await result;
40
- test.assertEqual(5, value);
41
- });
42
- });
43
-
44
- runner.testFunction("then()", () =>
45
- {
46
- runner.test("with error parent", async (test: Test) =>
47
- {
48
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
49
- const thenResult: PromiseAsyncResult<string> = parentResult.then(() => "hello");
50
- await test.assertThrowsAsync(thenResult, new Error("abc"));
51
- });
52
-
53
- runner.test("with error parent and thenFunction with side-effects", async (test: Test) =>
54
- {
55
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
56
- let counter: number = 0;
57
- const thenResult: PromiseAsyncResult<string> = parentResult.then(() => { counter++; return "hello"; });
58
- test.assertEqual(0, counter);
59
- await test.assertThrowsAsync(thenResult, new Error("abc"));
60
- test.assertEqual(0, counter, "counter should still be 0 because the thenFunction shouldn't be invoked.");
61
- });
62
-
63
- runner.test("with successful parent and successful thenFunction that ignores parentResult value", async (test: Test) =>
64
- {
65
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(1);
66
- const thenResult: PromiseAsyncResult<string> = parentResult.then(() => "hello");
67
- test.assertEqual("hello", await thenResult);
68
- });
69
-
70
- runner.test("with successful parent and successful thenFunction that uses parentResult value", async (test: Test) =>
71
- {
72
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(1);
73
- const thenResult: PromiseAsyncResult<string> = parentResult.then((argument: number) => (argument + 1).toString());
74
- test.assertEqual("2", await thenResult);
75
- });
76
-
77
- runner.test("with successful parent and successful thenFunction that uses parentResult value with side-effects", async (test: Test) =>
78
- {
79
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(1);
80
- let counter: number = 0;
81
- const thenResult: PromiseAsyncResult<string> = parentResult.then((argument: number) => { counter++; return (argument + 1).toString(); });
82
- test.assertEqual(0, counter);
83
-
84
- await PromiseAsyncResult.yield();
85
- test.assertEqual(1, counter);
86
-
87
- test.assertEqual("2", await thenResult);
88
- test.assertEqual(1, counter);
89
- });
90
-
91
- runner.test("with successful parent and thenFunction that throws", async (test: Test) =>
92
- {
93
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(10);
94
- let counter: number = 0;
95
- const thenResult: PromiseAsyncResult<string> = parentResult.then((argument: number) =>
96
- {
97
- counter++;
98
- throw new Error(`arg: ${argument}, ${counter}`);
99
- });
100
- test.assertEqual(counter, 0);
101
-
102
- await PromiseAsyncResult.yield();
103
- test.assertEqual(counter, 1);
104
-
105
- for (let i = 0; i < 3; i++)
106
- {
107
- await test.assertThrowsAsync(thenResult, new Error("arg: 10, 1"));
108
- test.assertEqual(counter, 1);
109
- }
110
- });
111
- });
112
-
113
- runner.testFunction("onValue()", () =>
114
- {
115
- runner.test("with error parent", async (test: Test) =>
116
- {
117
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
118
- let counter: number = 0;
119
- const onValueResult: PromiseAsyncResult<number> = parentResult.onValue(() => { counter++; });
120
- test.assertSame(counter, 0);
121
- for (let i = 0; i < 3; i++)
122
- {
123
- await test.assertThrowsAsync(onValueResult, new Error("abc"));
124
- test.assertSame(counter, 0);
125
- }
126
- });
127
-
128
- runner.test("with successful parent and successful thenFunction that ignores parentResult value", async (test: Test) =>
129
- {
130
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(10);
131
- let counter: number = 0;
132
- const onValueResult: PromiseAsyncResult<number> = parentResult.onValue(() => { counter++; });
133
- test.assertSame(counter, 0);
134
- for (let i = 0; i < 3; i++)
135
- {
136
- test.assertSame(10, await onValueResult);
137
- test.assertSame(counter, 1);
138
- }
139
- });
140
-
141
- runner.test("with successful parent and successful thenFunction that uses parentResult value", async (test: Test) =>
142
- {
143
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(2);
144
- let counter: number = 0;
145
- const onValueResult: PromiseAsyncResult<number> = parentResult.onValue((argument: number) => { counter += argument; });
146
- test.assertSame(counter, 0);
147
- for (let i = 0; i < 3; i++)
148
- {
149
- test.assertSame(await onValueResult, 2);
150
- test.assertSame(counter, 2);
151
- }
152
- });
153
-
154
- runner.test("with successful parent and onValueFunction that throws", async (test: Test) =>
155
- {
156
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(2);
157
- let counter: number = 0;
158
- const onValueResult: PromiseAsyncResult<number> = parentResult.onValue((argument: number) =>
159
- {
160
- counter += argument;
161
- throw new Error(`argument: ${argument}`);
162
- });
163
- test.assertSame(counter, 0);
164
- for (let i = 0; i < 3; i++)
165
- {
166
- await test.assertThrowsAsync(onValueResult, new Error("argument: 2"));
167
- test.assertSame(counter, 2);
168
- }
169
- });
170
- });
171
-
172
- runner.testFunction("catch()", () =>
173
- {
174
- runner.test("with undefined errorType", (test: Test) =>
175
- {
176
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
177
- test.assertThrows(() => parentResult.catch(undefined!, () => 6),
178
- new PreConditionError(
179
- "Expression: errorType",
180
- "Expected: not undefined and not null",
181
- "Actual: undefined"));
182
- });
183
-
184
- runner.test("with null errorType", (test: Test) =>
185
- {
186
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
187
- test.assertThrows(() => parentResult.catch(null!, () => 6),
188
- new PreConditionError(
189
- "Expression: errorType",
190
- "Expected: not undefined and not null",
191
- "Actual: null"));
192
- });
193
-
194
- runner.test("with error parent", async (test: Test) =>
195
- {
196
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
197
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(Error, () => 20);
198
- test.assertSame(await catchResult, 20);
199
- });
200
-
201
- runner.test("with error parent, no errorType, and no error parameter", async (test: Test) =>
202
- {
203
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
204
- let counter: number = 0;
205
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(() => { counter++; return 21; });
206
- test.assertSame(0, counter);
207
- for (let i = 0; i < 3; i++)
208
- {
209
- test.assertSame(await catchResult, 21);
210
- test.assertSame(1, counter);
211
- }
212
- });
213
-
214
- runner.test("with error parent, no errorType, and unknown error parameter", async (test: Test) =>
215
- {
216
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
217
- let counter: number = 0;
218
- const catchResult: PromiseAsyncResult<number> = parentResult.catch((error: unknown) =>
219
- {
220
- if (error instanceof Error)
221
- {
222
- counter += error.message.length;
223
- }
224
- else
225
- {
226
- counter -= 1;
227
- }
228
- return 21;
229
- });
230
- test.assertSame(0, counter);
231
- for (let i = 0; i < 3; i++)
232
- {
233
- test.assertSame(await catchResult, 21);
234
- test.assertSame(3, counter);
235
- }
236
- });
237
-
238
- runner.test("with error parent and catchFunction with side-effects", async (test: Test) =>
239
- {
240
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
241
- let counter: number = 0;
242
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(Error, () => { counter++; return 21; });
243
- test.assertSame(0, counter);
244
- for (let i = 0; i < 3; i++)
245
- {
246
- test.assertSame(await catchResult, 21);
247
- test.assertSame(1, counter);
248
- }
249
- });
250
-
251
- runner.test("with errorType that is a super-type of the actual error without error parameter", async (test: Test) =>
252
- {
253
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("abc"));
254
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(Error, () => 5);
255
- test.assertSame(await catchResult, 5);
256
- });
257
-
258
- runner.test("with errorType that is a super-type of the actual error with error parameter", async (test: Test) =>
259
- {
260
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("abc"));
261
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(Error, (error: Error) => error.message.length);
262
- test.assertSame(await catchResult, 3);
263
- });
264
-
265
- runner.test("with errorType that is a sub-type of the actual error", async (test: Test) =>
266
- {
267
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
268
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(PreConditionError, () => 20);
269
- await test.assertThrowsAsync(catchResult, new Error("abc"));
270
- });
271
-
272
- runner.test("with errorType that is unrelated to the actual error", async (test: Test) =>
273
- {
274
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("def"));
275
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(RangeError, () => 20);
276
- await test.assertThrowsAsync(catchResult, new PreConditionError("def"));
277
- });
278
-
279
- runner.test("with catchFunction that throws", async (test: Test) =>
280
- {
281
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("def"));
282
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(Error, () => { throw new TypeError("abc"); });
283
- await test.assertThrowsAsync(catchResult, new TypeError("abc"));
284
- });
285
-
286
- runner.test("with successful parent", async (test: Test) =>
287
- {
288
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(1);
289
- const catchResult: PromiseAsyncResult<number> = parentResult.catch(Error, () => 2);
290
- test.assertSame(await catchResult, 1);
291
- });
292
- });
293
-
294
- runner.testFunction("onError()", () =>
295
- {
296
- runner.test("with undefined errorType", (test: Test) =>
297
- {
298
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
299
- test.assertThrows(() => parentResult.onError(undefined!, () => { }),
300
- new PreConditionError(
301
- "Expression: errorType",
302
- "Expected: not undefined and not null",
303
- "Actual: undefined"));
304
- });
305
-
306
- runner.test("with null errorType", (test: Test) =>
307
- {
308
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
309
- test.assertThrows(() => parentResult.onError(null!, () => { }),
310
- new PreConditionError(
311
- "Expression: errorType",
312
- "Expected: not undefined and not null",
313
- "Actual: null"));
314
- });
315
-
316
- runner.test("with error parent, no errorType, and no error parameter", async (test: Test) =>
317
- {
318
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
319
- let counter: number = 0;
320
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(() => { counter++; });
321
- test.assertSame(0, counter);
322
- for (let i = 0; i < 3; i++)
323
- {
324
- await test.assertThrowsAsync(catchResult, new Error("abc"));
325
- test.assertSame(1, counter);
326
- }
327
- });
328
-
329
- runner.test("with error parent, no errorType, and unknown error parameter", async (test: Test) =>
330
- {
331
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
332
- let counter: number = 0;
333
- const catchResult: PromiseAsyncResult<number> = parentResult.onError((error: unknown) =>
334
- {
335
- if (error instanceof Error)
336
- {
337
- counter += error.message.length;
338
- }
339
- else
340
- {
341
- counter -= 1;
342
- }
343
- });
344
- test.assertSame(0, counter);
345
- for (let i = 0; i < 3; i++)
346
- {
347
- await test.assertThrowsAsync(catchResult, new Error("abc"));
348
- test.assertSame(3, counter);
349
- }
350
- });
351
-
352
- runner.test("with errorType that is a super-type of the actual error without error parameter", async (test: Test) =>
353
- {
354
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("abc"));
355
- let counter: number = 0;
356
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(Error, () => { counter++; });
357
- test.assertSame(counter, 0);
358
- for (let i = 0; i < 3; i++)
359
- {
360
- await test.assertThrowsAsync(catchResult, new PreConditionError("abc"));
361
- test.assertSame(counter, 1);
362
- }
363
- });
364
-
365
- runner.test("with errorType that is a super-type of the actual error with error parameter", async (test: Test) =>
366
- {
367
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("abc"));
368
- let counter: number = 0;
369
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(Error, (error: Error) => { counter += error.message.length; });
370
- test.assertSame(counter, 0);
371
- for (let i = 0; i < 3; i++)
372
- {
373
- await test.assertThrowsAsync(catchResult, new PreConditionError("abc"));
374
- test.assertSame(counter, 3);
375
- }
376
- });
377
-
378
- runner.test("with errorType that is a sub-type of the actual error", async (test: Test) =>
379
- {
380
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
381
- let counter: number = 0;
382
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(PreConditionError, () => { counter++; });
383
- test.assertSame(counter, 0);
384
- for (let i = 0; i < 3; i++)
385
- {
386
- await test.assertThrowsAsync(catchResult, new Error("abc"));
387
- test.assertSame(counter, 0);
388
- }
389
- });
390
-
391
- runner.test("with errorType that is unrelated to the actual error", async (test: Test) =>
392
- {
393
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("def"));
394
- let counter: number = 0;
395
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(RangeError, () => { counter++; });
396
- test.assertSame(counter, 0);
397
- for (let i = 0; i < 3; i++)
398
- {
399
- await test.assertThrowsAsync(catchResult, new PreConditionError("def"));
400
- test.assertSame(counter, 0);
401
- }
402
- });
403
-
404
- runner.test("with onErrorFunction that throws", async (test: Test) =>
405
- {
406
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("def"));
407
- let counter: number = 0;
408
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(Error, () => { counter++; throw new Error("abc"); });
409
- test.assertSame(counter, 0);
410
- for (let i = 0; i < 3; i++)
411
- {
412
- await test.assertThrowsAsync(catchResult, new Error("abc"));
413
- test.assertSame(counter, 1);
414
- }
415
- });
416
-
417
- runner.test("with successful parent", async (test: Test) =>
418
- {
419
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(1);
420
- let counter: number = 0;
421
- const catchResult: PromiseAsyncResult<number> = parentResult.onError(Error, () => { counter++; });
422
- test.assertSame(counter, 0);
423
- for (let i = 0; i < 3; i++)
424
- {
425
- test.assertSame(await catchResult, 1);
426
- test.assertSame(counter, 0);
427
- }
428
- });
429
- });
430
-
431
- runner.testFunction("convertError()", () =>
432
- {
433
- runner.test("with undefined convertErrorFunction", (test: Test) =>
434
- {
435
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
436
- test.assertThrows(() => parentResult.convertError(undefined!),
437
- new PreConditionError(
438
- "Expression: convertErrorFunction",
439
- "Expected: not undefined and not null",
440
- "Actual: undefined"));
441
- });
442
-
443
- runner.test("with null convertErrorFunction", (test: Test) =>
444
- {
445
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
446
- test.assertThrows(() => parentResult.convertError(null!),
447
- new PreConditionError(
448
- "Expression: convertErrorFunction",
449
- "Expected: not undefined and not null",
450
- "Actual: null"));
451
- });
452
-
453
- runner.test("with successful parent", async (test: Test) =>
454
- {
455
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
456
- let counter: number = 0;
457
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError((error: unknown) =>
458
- {
459
- counter++;
460
- return new Error(`${error} - def`);
461
- });
462
- test.assertSame(counter, 0);
463
- for (let i = 0; i < 3; i++)
464
- {
465
- test.assertSame(await convertErrorResult, 5);
466
- test.assertSame(counter, 0);
467
- }
468
- });
469
-
470
- runner.test("with error parent and non-throwing convertErrorFunction", async (test: Test) =>
471
- {
472
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
473
- let counter: number = 0;
474
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError((error: unknown) =>
475
- {
476
- counter++;
477
- return new Error(`${(error as Error).message} - def`);
478
- });
479
- test.assertSame(counter, 0);
480
- for (let i = 0; i < 3; i++)
481
- {
482
- await test.assertThrowsAsync(convertErrorResult, new Error("abc - def"));
483
- test.assertSame(counter, 1);
484
- }
485
- });
486
-
487
- runner.test("with error parent and throwing convertErrorFunction", async (test: Test) =>
488
- {
489
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
490
- let counter: number = 0;
491
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError((error: unknown) =>
492
- {
493
- counter++;
494
- throw new Error(`${(error as Error).message} - def`);
495
- });
496
- test.assertSame(counter, 0);
497
- for (let i = 0; i < 3; i++)
498
- {
499
- await test.assertThrowsAsync(convertErrorResult, new Error("abc - def"));
500
- test.assertSame(counter, 1);
501
- }
502
- });
503
-
504
- runner.test("with successful parent", async (test: Test) =>
505
- {
506
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
507
- let counter: number = 0;
508
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(Error, (error: Error) =>
509
- {
510
- counter++;
511
- return new Error(`${error.message} - def`);
512
- });
513
- test.assertSame(counter, 0);
514
- for (let i = 0; i < 3; i++)
515
- {
516
- test.assertSame(await convertErrorResult, 5);
517
- test.assertSame(counter, 0);
518
- }
519
- });
520
-
521
- runner.test("with error parent, exact error match, and non-throwing convertErrorFunction", async (test: Test) =>
522
- {
523
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
524
- let counter: number = 0;
525
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(Error, (error: Error) =>
526
- {
527
- counter++;
528
- return new Error(`${error.message} - def`);
529
- });
530
- test.assertSame(counter, 0);
531
- for (let i = 0; i < 3; i++)
532
- {
533
- await test.assertThrowsAsync(convertErrorResult, new Error("abc - def"));
534
- test.assertSame(counter, 1);
535
- }
536
- });
537
-
538
- runner.test("with error parent, super error match, and non-throwing convertErrorFunction", async (test: Test) =>
539
- {
540
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("abc"));
541
- let counter: number = 0;
542
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(Error, (error: Error) =>
543
- {
544
- counter++;
545
- return new Error(`${error.message} - def`);
546
- });
547
- test.assertSame(counter, 0);
548
- for (let i = 0; i < 3; i++)
549
- {
550
- await test.assertThrowsAsync(convertErrorResult, new Error(`abc - def`));
551
- test.assertSame(counter, 1);
552
- }
553
- });
554
-
555
- runner.test("with error parent, no error match, and non-throwing convertErrorFunction", async (test: Test) =>
556
- {
557
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new PreConditionError("abc"));
558
- let counter: number = 0;
559
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(TypeError, (error: TypeError) =>
560
- {
561
- counter++;
562
- return new Error(`${error} - def`);
563
- });
564
- test.assertSame(counter, 0);
565
- for (let i = 0; i < 3; i++)
566
- {
567
- await test.assertThrowsAsync(convertErrorResult, new PreConditionError("abc"));
568
- test.assertSame(counter, 0);
569
- }
570
- });
571
-
572
- runner.test("with error parent, exact error match, and throwing convertErrorFunction", async (test: Test) =>
573
- {
574
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
575
- let counter: number = 0;
576
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(Error, (error: Error) =>
577
- {
578
- counter++;
579
- throw new Error(`${error.message} - def`);
580
- });
581
- test.assertSame(counter, 0);
582
- for (let i = 0; i < 3; i++)
583
- {
584
- await test.assertThrowsAsync(convertErrorResult, new Error("abc - def"));
585
- test.assertSame(counter, 1);
586
- }
587
- });
588
-
589
- runner.test("with error parent, super error match, and throwing convertErrorFunction", async (test: Test) =>
590
- {
591
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new TypeError("abc"));
592
- let counter: number = 0;
593
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(Error, (error: Error) =>
594
- {
595
- counter++;
596
- throw new Error(`${error.message} - def`);
597
- });
598
- test.assertSame(counter, 0);
599
- for (let i = 0; i < 3; i++)
600
- {
601
- await test.assertThrowsAsync(convertErrorResult, new Error("abc - def"));
602
- test.assertSame(counter, 1);
603
- }
604
- });
605
-
606
- runner.test("with error parent, no error match, and throwing convertErrorFunction", async (test: Test) =>
607
- {
608
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new TypeError("abc"));
609
- let counter: number = 0;
610
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.convertError(PreConditionError, () =>
611
- {
612
- counter++;
613
- throw new Error("def");
614
- });
615
- test.assertSame(counter, 0);
616
- for (let i = 0; i < 3; i++)
617
- {
618
- await test.assertThrowsAsync(convertErrorResult, new TypeError("abc"));
619
- test.assertSame(counter, 0);
620
- }
621
- });
622
- });
623
-
624
- runner.testFunction("finally()", () =>
625
- {
626
- runner.test("with successful parent and non-throwing onfinally function", async (test: Test) =>
627
- {
628
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
629
- let counter: number = 0;
630
- const finallyResult: PromiseAsyncResult<number> = parentResult.finally(() => { counter++; });
631
- test.assertSame(counter, 0);
632
- for (let i = 0; i < 3; i++)
633
- {
634
- test.assertSame(await finallyResult, 5);
635
- test.assertSame(counter, 1);
636
- }
637
- });
638
-
639
- runner.test("with successful parent and throwing onfinally function", async (test: Test) =>
640
- {
641
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.value(5);
642
- let counter: number = 0;
643
- const finallyResult: PromiseAsyncResult<number> = parentResult.finally(() =>
644
- {
645
- counter++;
646
- throw new RangeError("oops!");
647
- });
648
- test.assertSame(counter, 0);
649
- for (let i = 0; i < 3; i++)
650
- {
651
- await test.assertThrowsAsync(finallyResult, new RangeError("oops!"));
652
- test.assertSame(counter, 1);
653
- }
654
- });
655
-
656
- runner.test("with error parent and non-throwing onfinally function", async (test: Test) =>
657
- {
658
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
659
- let counter: number = 0;
660
- const finallyResult: PromiseAsyncResult<number> = parentResult.finally(() => { counter++; });
661
- test.assertSame(counter, 0);
662
- for (let i = 0; i < 3; i++)
663
- {
664
- await test.assertThrowsAsync(finallyResult, new Error("abc"));
665
- test.assertSame(counter, 1);
666
- }
667
- });
668
-
669
- runner.test("with error parent and throwing onfinally function", async (test: Test) =>
670
- {
671
- const parentResult: PromiseAsyncResult<number> = PromiseAsyncResult.error(new Error("abc"));
672
- let counter: number = 0;
673
- const convertErrorResult: PromiseAsyncResult<number> = parentResult.finally(() =>
674
- {
675
- counter++;
676
- throw new RangeError("def");
677
- });
678
- test.assertSame(counter, 0);
679
- for (let i = 0; i < 3; i++)
680
- {
681
- await test.assertThrowsAsync(convertErrorResult, new RangeError("def"));
682
- test.assertSame(counter, 1);
683
- }
684
- });
685
- });
686
- });
687
- });
688
- }