@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.
- package/.c8rc.json +12 -0
- package/.github/workflows/publish.yml +38 -0
- package/.mocharc.json +9 -0
- package/README.md +9 -0
- package/package.json +36 -0
- package/sources/assertMessageParameters.ts +22 -0
- package/sources/asyncIterator.ts +437 -0
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
- package/sources/asyncResult.ts +95 -0
- package/sources/basicDisposable.ts +57 -0
- package/sources/byteList.ts +202 -0
- package/sources/byteListStream.ts +121 -0
- package/sources/byteReadStream.ts +24 -0
- package/sources/byteWriteStream.ts +16 -0
- package/sources/bytes.ts +25 -0
- package/sources/characterList.ts +195 -0
- package/sources/characterListStream.ts +151 -0
- package/sources/characterReadStream.ts +81 -0
- package/sources/characterReadStreamIterator.ts +128 -0
- package/sources/characterWriteStream.ts +45 -0
- package/sources/commandLineParameter.ts +45 -0
- package/sources/commandLineParameters.ts +21 -0
- package/sources/comparable.ts +144 -0
- package/sources/comparer.ts +133 -0
- package/sources/comparison.ts +20 -0
- package/sources/concatenateIterable.ts +119 -0
- package/sources/concatenateIterator.ts +165 -0
- package/sources/condition.ts +329 -0
- package/sources/currentProcess.ts +158 -0
- package/sources/dateTime.ts +130 -0
- package/sources/depthFirstSearch.ts +230 -0
- package/sources/disposable.ts +31 -0
- package/sources/emptyError.ts +10 -0
- package/sources/english.ts +45 -0
- package/sources/equalFunctions.ts +123 -0
- package/sources/fetchHttpClient.ts +89 -0
- package/sources/fetchHttpResponse.ts +106 -0
- package/sources/flatMapIterable.ts +104 -0
- package/sources/flatMapIterator.ts +152 -0
- package/sources/generator.ts +251 -0
- package/sources/httpClient.ts +36 -0
- package/sources/httpHeader.ts +37 -0
- package/sources/httpHeaders.ts +216 -0
- package/sources/httpIncomingRequest.ts +30 -0
- package/sources/httpIncomingResponse.ts +19 -0
- package/sources/httpMethod.ts +164 -0
- package/sources/httpOutgoingRequest.ts +119 -0
- package/sources/httpOutgoingResponse.ts +113 -0
- package/sources/httpServer.ts +34 -0
- package/sources/inMemoryCharacterWriteStream.ts +78 -0
- package/sources/index.ts +101 -0
- package/sources/iterable.ts +345 -0
- package/sources/iterator.ts +481 -0
- package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
- package/sources/javascript.ts +59 -0
- package/sources/javascriptArrayList.ts +175 -0
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
- package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
- package/sources/javascriptMapMap.ts +143 -0
- package/sources/javascriptSetSet.ts +134 -0
- package/sources/list.ts +330 -0
- package/sources/listQueue.ts +62 -0
- package/sources/listStack.ts +62 -0
- package/sources/luxonDateTime.ts +109 -0
- package/sources/map.ts +302 -0
- package/sources/mapAsyncIterator.ts +141 -0
- package/sources/mapIterable.ts +105 -0
- package/sources/mapIterator.ts +145 -0
- package/sources/mutableCondition.ts +451 -0
- package/sources/mutableHttpHeaders.ts +204 -0
- package/sources/mutableMap.ts +292 -0
- package/sources/network.ts +18 -0
- package/sources/node.ts +37 -0
- package/sources/nodeJSCharacterWriteStream.ts +42 -0
- package/sources/nodeJSHttpIncomingRequest.ts +132 -0
- package/sources/nodeJSHttpServer.ts +134 -0
- package/sources/notFoundError.ts +12 -0
- package/sources/postCondition.ts +284 -0
- package/sources/postConditionError.ts +12 -0
- package/sources/preCondition.ts +284 -0
- package/sources/preConditionError.ts +12 -0
- package/sources/promiseAsyncResult.ts +174 -0
- package/sources/property.ts +63 -0
- package/sources/queue.ts +49 -0
- package/sources/realNetwork.ts +28 -0
- package/sources/recreationDotGovClient.ts +259 -0
- package/sources/searchControl.ts +42 -0
- package/sources/set.ts +244 -0
- package/sources/skipAsyncIterator.ts +145 -0
- package/sources/skipIterator.ts +155 -0
- package/sources/stack.ts +48 -0
- package/sources/stringComparer.ts +33 -0
- package/sources/stringIterator.ts +149 -0
- package/sources/strings.ts +322 -0
- package/sources/syncResult.ts +300 -0
- package/sources/takeAsyncIterator.ts +141 -0
- package/sources/takeIterator.ts +151 -0
- package/sources/toStringFunctions.ts +185 -0
- package/sources/types.ts +371 -0
- package/sources/whereAsyncIterator.ts +143 -0
- package/sources/whereIterable.ts +108 -0
- package/sources/whereIterator.ts +157 -0
- package/sources/wonderlandTrailClient.ts +1503 -0
- package/tests/assertTest.ts +113 -0
- package/tests/assertTestTests.ts +75 -0
- package/tests/basicTestSkip.ts +51 -0
- package/tests/byteListStreamTests.ts +390 -0
- package/tests/byteListTests.ts +27 -0
- package/tests/bytesTests.ts +43 -0
- package/tests/characterListStreamTests.ts +391 -0
- package/tests/characterListTests.ts +250 -0
- package/tests/characterWriteStreamTests.ts +12 -0
- package/tests/comparerTests.ts +92 -0
- package/tests/conditionTests.ts +877 -0
- package/tests/consoleTestRunner.ts +404 -0
- package/tests/consoleTestRunnerTests.ts +651 -0
- package/tests/dateTimeTests.ts +30 -0
- package/tests/depthFirstSearchTests.ts +106 -0
- package/tests/disposableTests.ts +121 -0
- package/tests/englishTests.ts +103 -0
- package/tests/equalFunctionsTests.ts +223 -0
- package/tests/failedTest.ts +43 -0
- package/tests/fetchHttpClientTests.ts +33 -0
- package/tests/generatorTests.ts +86 -0
- package/tests/httpClientTests.ts +18 -0
- package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
- package/tests/iterableTests.ts +141 -0
- package/tests/iteratorTests.ts +1086 -0
- package/tests/javascriptMapMapTests.ts +21 -0
- package/tests/listTests.ts +338 -0
- package/tests/mapIteratorTests.ts +55 -0
- package/tests/mapTests.ts +104 -0
- package/tests/mutableConditionTests.ts +273 -0
- package/tests/mutableMapTests.ts +154 -0
- package/tests/nodeJSHttpServerTests.ts +75 -0
- package/tests/notFoundErrorTests.ts +24 -0
- package/tests/postConditionErrorTests.ts +24 -0
- package/tests/preConditionErrorTests.ts +24 -0
- package/tests/promiseAsyncResultTests.ts +688 -0
- package/tests/propertyTests.ts +63 -0
- package/tests/queueTests.ts +29 -0
- package/tests/recreationDotGovClientTests.ts +191 -0
- package/tests/setTests.ts +140 -0
- package/tests/skippedTest.ts +39 -0
- package/tests/stackTests.ts +66 -0
- package/tests/stringComparerTests.ts +60 -0
- package/tests/stringIteratorTests.ts +156 -0
- package/tests/stringsTests.ts +516 -0
- package/tests/syncResultTests.ts +1251 -0
- package/tests/test.ts +228 -0
- package/tests/testAction.ts +75 -0
- package/tests/testActionTests.ts +93 -0
- package/tests/testFailureTests.ts +12 -0
- package/tests/testRunner.ts +267 -0
- package/tests/testRunnerTests.ts +895 -0
- package/tests/testSkip.ts +34 -0
- package/tests/tests.ts +103 -0
- package/tests/toStringFunctionsTests.ts +55 -0
- package/tests/typesTests.ts +257 -0
- package/tests/whereIteratorTests.ts +77 -0
- package/tests/wonderlandTrailClientTests.ts +452 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { EqualFunctions } from "../sources/equalFunctions";
|
|
4
|
+
import { MutableCondition } from "../sources/mutableCondition";
|
|
5
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
6
|
+
import { join } from "../sources/strings";
|
|
7
|
+
import { ToStringFunctions } from "../sources/toStringFunctions";
|
|
8
|
+
import { isNumber, isString } from "../sources/types";
|
|
9
|
+
import { Test } from "./test";
|
|
10
|
+
import { TestRunner } from "./testRunner";
|
|
11
|
+
|
|
12
|
+
export function test(runner: TestRunner): void
|
|
13
|
+
{
|
|
14
|
+
runner.testFile("mutableCondition.ts", () =>
|
|
15
|
+
{
|
|
16
|
+
runner.testType("MutableCondition", () =>
|
|
17
|
+
{
|
|
18
|
+
runner.testFunction("create()", (test: Test) =>
|
|
19
|
+
{
|
|
20
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
21
|
+
test.assertNotUndefinedAndNotNull(mc);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
runner.testFunction("setToStringFunctions()", () =>
|
|
25
|
+
{
|
|
26
|
+
function setToStringFunctionsErrorTest(testName: string, toStringFunctions: ToStringFunctions, expected: Error): void
|
|
27
|
+
{
|
|
28
|
+
runner.test(testName, (test: Test) =>
|
|
29
|
+
{
|
|
30
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
31
|
+
test.assertThrows(() => mc.setToStringFunctions(toStringFunctions), expected);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setToStringFunctionsErrorTest("with undefined", undefined!, new PreConditionError(
|
|
36
|
+
"Expression: toStringFunctions",
|
|
37
|
+
"Expected: not undefined and not null",
|
|
38
|
+
"Actual: undefined",
|
|
39
|
+
));
|
|
40
|
+
setToStringFunctionsErrorTest("with null", null!, new PreConditionError(
|
|
41
|
+
"Expression: toStringFunctions",
|
|
42
|
+
"Expected: not undefined and not null",
|
|
43
|
+
"Actual: null",
|
|
44
|
+
));
|
|
45
|
+
|
|
46
|
+
runner.test("with valid value", (test: Test) =>
|
|
47
|
+
{
|
|
48
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
49
|
+
test.assertEqual(`"hello"`, mc.toValueString("hello"));
|
|
50
|
+
|
|
51
|
+
mc.setToStringFunctions(
|
|
52
|
+
ToStringFunctions.create()
|
|
53
|
+
.add(isString, (value: string) => `---${value}---`),
|
|
54
|
+
);
|
|
55
|
+
test.assertEqual(`---hello---`, mc.toValueString("hello"));
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
runner.testFunction("setEqualFunctions()", () =>
|
|
60
|
+
{
|
|
61
|
+
function setEqualFunctionsErrorTest(testName: string, equalFunctions: EqualFunctions, expected: Error): void
|
|
62
|
+
{
|
|
63
|
+
runner.test(testName, (test: Test) =>
|
|
64
|
+
{
|
|
65
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
66
|
+
test.assertThrows(() => mc.setEqualFunctions(equalFunctions), expected);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setEqualFunctionsErrorTest("with undefined", undefined!, new PreConditionError(
|
|
71
|
+
"Expression: equalFunctions",
|
|
72
|
+
"Expected: not undefined and not null",
|
|
73
|
+
"Actual: undefined",
|
|
74
|
+
));
|
|
75
|
+
setEqualFunctionsErrorTest("with null", null!, new PreConditionError(
|
|
76
|
+
"Expression: equalFunctions",
|
|
77
|
+
"Expected: not undefined and not null",
|
|
78
|
+
"Actual: null",
|
|
79
|
+
));
|
|
80
|
+
|
|
81
|
+
runner.test("with valid value", (test: Test) =>
|
|
82
|
+
{
|
|
83
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
84
|
+
test.assertFalse(mc.areEqual(3, 5));
|
|
85
|
+
test.assertFalse(mc.areEqual(3, 4));
|
|
86
|
+
test.assertTrue(mc.areEqual(4, 4));
|
|
87
|
+
|
|
88
|
+
mc.setEqualFunctions(
|
|
89
|
+
EqualFunctions.create()
|
|
90
|
+
.add((left: unknown, right: unknown) =>
|
|
91
|
+
{
|
|
92
|
+
return isNumber(left) && isNumber(right)
|
|
93
|
+
? left % 2 === right % 2
|
|
94
|
+
: undefined;
|
|
95
|
+
})
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
test.assertTrue(mc.areEqual(3, 5));
|
|
99
|
+
test.assertFalse(mc.areEqual(3, 4));
|
|
100
|
+
test.assertTrue(mc.areEqual(4, 4));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
runner.testFunction("setCreateErrorFunction()", () =>
|
|
105
|
+
{
|
|
106
|
+
function setCreateErrorFunctionErrorTest(testName: string, createErrorFunction: ((message: string) => Error), expected: Error): void
|
|
107
|
+
{
|
|
108
|
+
runner.test(testName, (test: Test) =>
|
|
109
|
+
{
|
|
110
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
111
|
+
test.assertThrows(() => mc.setCreateErrorFunction(createErrorFunction), expected);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setCreateErrorFunctionErrorTest("with undefined", undefined!, new PreConditionError(
|
|
116
|
+
"Expression: createErrorFunction",
|
|
117
|
+
"Expected: not undefined and not null",
|
|
118
|
+
"Actual: undefined",
|
|
119
|
+
));
|
|
120
|
+
setCreateErrorFunctionErrorTest("with null", null!, new PreConditionError(
|
|
121
|
+
"Expression: createErrorFunction",
|
|
122
|
+
"Expected: not undefined and not null",
|
|
123
|
+
"Actual: null",
|
|
124
|
+
));
|
|
125
|
+
|
|
126
|
+
runner.test("with valid function", (test: Test) =>
|
|
127
|
+
{
|
|
128
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
129
|
+
test.assertThrows(() => mc.assertEqual(1, 2));
|
|
130
|
+
|
|
131
|
+
mc.setCreateErrorFunction((message: string) =>
|
|
132
|
+
{
|
|
133
|
+
return Error(`fake '${message}' fake`);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
mc.setEqualFunctions(
|
|
137
|
+
EqualFunctions.create()
|
|
138
|
+
.add((left: unknown, right: unknown) =>
|
|
139
|
+
{
|
|
140
|
+
return isNumber(left) && isNumber(right)
|
|
141
|
+
? left % 2 === right % 2
|
|
142
|
+
: undefined;
|
|
143
|
+
})
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
test.assertTrue(mc.areEqual(3, 5));
|
|
147
|
+
test.assertFalse(mc.areEqual(3, 4));
|
|
148
|
+
test.assertTrue(mc.areEqual(4, 4));
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
runner.testFunction("assertUndefined()", () =>
|
|
153
|
+
{
|
|
154
|
+
runner.test("with undefined", (test: Test) =>
|
|
155
|
+
{
|
|
156
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
157
|
+
mc.assertUndefined(undefined);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
function assertUndefinedErrorTest(value: unknown, expected: Error): void
|
|
161
|
+
{
|
|
162
|
+
runner.test(`with ${runner.toString(value)}`, (test: Test) =>
|
|
163
|
+
{
|
|
164
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
165
|
+
test.assertThrows(() => mc.assertUndefined(value), expected);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
assertUndefinedErrorTest(null, new Error(join("\n", [
|
|
170
|
+
"Expected: undefined",
|
|
171
|
+
"Actual: null",
|
|
172
|
+
])));
|
|
173
|
+
assertUndefinedErrorTest(false, new Error(join("\n", [
|
|
174
|
+
"Expected: undefined",
|
|
175
|
+
"Actual: false",
|
|
176
|
+
])));
|
|
177
|
+
assertUndefinedErrorTest("abc", new Error(join("\n", [
|
|
178
|
+
"Expected: undefined",
|
|
179
|
+
"Actual: \"abc\"",
|
|
180
|
+
])));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
runner.testFunction("assertNotUndefined()", () =>
|
|
184
|
+
{
|
|
185
|
+
runner.test("with undefined", (test: Test) =>
|
|
186
|
+
{
|
|
187
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
188
|
+
test.assertThrows(
|
|
189
|
+
() => mc.assertNotUndefined(undefined),
|
|
190
|
+
new Error(join("\n", [
|
|
191
|
+
"Expected: not undefined",
|
|
192
|
+
"Actual: undefined",
|
|
193
|
+
])),
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
function assertNotUndefinedTest(value: unknown): void
|
|
198
|
+
{
|
|
199
|
+
runner.test(`with ${runner.toString(value)}`, (test: Test) =>
|
|
200
|
+
{
|
|
201
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
202
|
+
mc.assertNotUndefined(value);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
assertNotUndefinedTest(null);
|
|
207
|
+
assertNotUndefinedTest("");
|
|
208
|
+
assertNotUndefinedTest(false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
runner.testFunction("areEqual()", () =>
|
|
212
|
+
{
|
|
213
|
+
function areEqualTest(left: unknown, right: unknown, expected: boolean): void
|
|
214
|
+
{
|
|
215
|
+
runner.test(`with ${runner.andList([left, right])}`, (test: Test) =>
|
|
216
|
+
{
|
|
217
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
218
|
+
test.assertEqual(mc.areEqual(left, right), expected);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
areEqualTest(undefined, undefined, true);
|
|
223
|
+
areEqualTest(5, 5, true);
|
|
224
|
+
areEqualTest(true, true, true);
|
|
225
|
+
areEqualTest({}, {}, true);
|
|
226
|
+
|
|
227
|
+
areEqualTest(undefined, "", false);
|
|
228
|
+
areEqualTest(1, 2, false);
|
|
229
|
+
areEqualTest(false, true, false);
|
|
230
|
+
areEqualTest({a:1}, {a:2}, false);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
runner.testFunction("toValueString()", () =>
|
|
234
|
+
{
|
|
235
|
+
function toValueStringTest(value: unknown, expected: string): void
|
|
236
|
+
{
|
|
237
|
+
runner.test(`with ${runner.toString(value)}`, (test: Test) =>
|
|
238
|
+
{
|
|
239
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
240
|
+
test.assertEqual(expected, mc.toValueString(value));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
toValueStringTest(undefined, "undefined");
|
|
245
|
+
toValueStringTest(null, "null");
|
|
246
|
+
toValueStringTest(0, "0");
|
|
247
|
+
toValueStringTest("abc", `"abc"`);
|
|
248
|
+
toValueStringTest({}, "{}");
|
|
249
|
+
toValueStringTest({a:"a"}, `{"a":"a"}`);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
runner.testFunction("createError()", () =>
|
|
253
|
+
{
|
|
254
|
+
runner.test("with all properties", (test: Test) =>
|
|
255
|
+
{
|
|
256
|
+
const mc: MutableCondition = MutableCondition.create();
|
|
257
|
+
const error: Error = mc.createError({
|
|
258
|
+
actual: "fake-actual",
|
|
259
|
+
expected: "fake-expected",
|
|
260
|
+
expression: "fake-expression",
|
|
261
|
+
message: "fake-message",
|
|
262
|
+
});
|
|
263
|
+
test.assertEqual(error, new Error(join("\n", [
|
|
264
|
+
"Message: fake-message",
|
|
265
|
+
"Expression: fake-expression",
|
|
266
|
+
"Expected: fake-expected",
|
|
267
|
+
"Actual: fake-actual",
|
|
268
|
+
])));
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Iterator } from "../sources/iterator";
|
|
2
|
+
import { JavascriptIterable } from "../sources/javascript";
|
|
3
|
+
import { isMap } from "../sources/map";
|
|
4
|
+
import { MutableMap } from "../sources/mutableMap";
|
|
5
|
+
import { NotFoundError } from "../sources/notFoundError";
|
|
6
|
+
import { mapTests } from "./mapTests";
|
|
7
|
+
import { Test } from "./test";
|
|
8
|
+
import { TestRunner } from "./testRunner";
|
|
9
|
+
|
|
10
|
+
export function test(runner: TestRunner): void
|
|
11
|
+
{
|
|
12
|
+
runner.testFile("mutableMap.ts", () =>
|
|
13
|
+
{
|
|
14
|
+
runner.testType("MutableMap<TKey,TValue>", () =>
|
|
15
|
+
{
|
|
16
|
+
runner.testFunction("create()", (test: Test) =>
|
|
17
|
+
{
|
|
18
|
+
const map: MutableMap<number,string> = MutableMap.create();
|
|
19
|
+
test.assertSame(map.getCount().await(), 0);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
mutableMapTests(runner, MutableMap.create);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function mutableMapTests(runner: TestRunner, creator: () => MutableMap<number,string>): void
|
|
28
|
+
{
|
|
29
|
+
runner.testType("MutableMap<TKey,TValue>", () =>
|
|
30
|
+
{
|
|
31
|
+
mapTests(runner, creator);
|
|
32
|
+
|
|
33
|
+
runner.testFunction("creator()", (test: Test) =>
|
|
34
|
+
{
|
|
35
|
+
test.assertNotUndefinedAndNotNull(creator);
|
|
36
|
+
|
|
37
|
+
const map: MutableMap<number,string> = creator();
|
|
38
|
+
test.assertNotUndefinedAndNotNull(map);
|
|
39
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
40
|
+
test.assertTrue(isMap(map));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
runner.testFunction("containsKey(TKey)", () =>
|
|
44
|
+
{
|
|
45
|
+
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
46
|
+
{
|
|
47
|
+
const map: MutableMap<number,string> = creator();
|
|
48
|
+
|
|
49
|
+
test.assertFalse(map.containsKey(50).await());
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
runner.test("when it contains the key", (test: Test) =>
|
|
53
|
+
{
|
|
54
|
+
const map: MutableMap<number,string> = creator().set(50, "fifty");
|
|
55
|
+
|
|
56
|
+
test.assertTrue(map.containsKey(50).await());
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
runner.testFunction("get(TKey)", () =>
|
|
61
|
+
{
|
|
62
|
+
runner.test("when it contains the key", (test: Test) =>
|
|
63
|
+
{
|
|
64
|
+
const map: MutableMap<number,string> = creator().set(1, "one");
|
|
65
|
+
test.assertEqual(map.getCount().await(), 1);
|
|
66
|
+
test.assertEqual(map.get(1).await(), "one");
|
|
67
|
+
test.assertEqual(map.getCount().await(), 1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
71
|
+
{
|
|
72
|
+
const map: MutableMap<number,string> = creator();
|
|
73
|
+
|
|
74
|
+
test.assertThrows(() => map.get(1).await(),
|
|
75
|
+
new NotFoundError(
|
|
76
|
+
"The key 1 was not found in the map."));
|
|
77
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
runner.testFunction("set(TKey,TValue)", () =>
|
|
82
|
+
{
|
|
83
|
+
function setTest(map: MutableMap<number,string>, key: number, value: string): void
|
|
84
|
+
{
|
|
85
|
+
runner.test(`with ${runner.andList([map, key, value])}`, (test: Test) =>
|
|
86
|
+
{
|
|
87
|
+
const setResult: MutableMap<number,string> = map.set(key, value);
|
|
88
|
+
test.assertSame(setResult, map);
|
|
89
|
+
test.assertSame(map.get(key).await(), value);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setTest(creator(), 0, "zero");
|
|
94
|
+
setTest(creator(), 1, "1");
|
|
95
|
+
setTest(creator(), -1, "negative one");
|
|
96
|
+
|
|
97
|
+
setTest(creator(), undefined!, "hello");
|
|
98
|
+
setTest(creator(), null!, "oops");
|
|
99
|
+
setTest(creator(), 10, undefined!);
|
|
100
|
+
setTest(creator(), 11, null!);
|
|
101
|
+
|
|
102
|
+
setTest(creator().set(1, "1"), 1, "one");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
runner.testFunction("toString()", () =>
|
|
106
|
+
{
|
|
107
|
+
function toStringTest(map: MutableMap<number,string>, expected: string): void
|
|
108
|
+
{
|
|
109
|
+
runner.test(`with ${runner.toString(map)}`, (test: Test) =>
|
|
110
|
+
{
|
|
111
|
+
test.assertEqual(map.toString(), expected);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
toStringTest(creator(), "{}");
|
|
116
|
+
toStringTest(creator().set(1, "one"), `{1:"one"}`);
|
|
117
|
+
toStringTest(creator().set(2, "2").set(1, "one"), `{2:"2",1:"one"}`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
runner.testFunction("iterateKeys()", () =>
|
|
121
|
+
{
|
|
122
|
+
function iterateKeysTests(map: MutableMap<number,string>, expected: JavascriptIterable<number>): void
|
|
123
|
+
{
|
|
124
|
+
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
125
|
+
{
|
|
126
|
+
const keyIterator: Iterator<number> = map.iterateKeys();
|
|
127
|
+
test.assertEqual(await keyIterator.toArray(), [...expected]);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
iterateKeysTests(creator(), []);
|
|
132
|
+
iterateKeysTests(creator().set(5, "five"), [5]);
|
|
133
|
+
iterateKeysTests(creator().set(5, "five").set(6, "six"), [5, 6]);
|
|
134
|
+
iterateKeysTests(creator().set(5, "5").set(6, "6").set(7, "7"), [5, 6, 7]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
runner.testFunction("iterateValues()", () =>
|
|
138
|
+
{
|
|
139
|
+
function iterateValuesTests(map: MutableMap<number,string>, expected: JavascriptIterable<string>): void
|
|
140
|
+
{
|
|
141
|
+
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
142
|
+
{
|
|
143
|
+
const valueIterator: Iterator<string> = map.iterateValues();
|
|
144
|
+
test.assertEqual(await valueIterator.toArray(), [...expected]);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
iterateValuesTests(creator(), []);
|
|
149
|
+
iterateValuesTests(creator().set(5, "five"), ["five"]);
|
|
150
|
+
iterateValuesTests(creator().set(5, "five").set(6, "six"), ["five", "six"]);
|
|
151
|
+
iterateValuesTests(creator().set(5, "5").set(6, "6").set(7, "7"), ["5", "6", "7"]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { FetchHttpClient } from "../sources/fetchHttpClient";
|
|
2
|
+
import { FetchHttpIncomingResponse } from "../sources/fetchHttpResponse";
|
|
3
|
+
import { NodeJSHttpServer as NodeJSHttpServer } from "../sources/nodeJSHttpServer";
|
|
4
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
5
|
+
import { Test } from "./test";
|
|
6
|
+
import { TestRunner } from "./testRunner";
|
|
7
|
+
|
|
8
|
+
export function test(runner: TestRunner): void
|
|
9
|
+
{
|
|
10
|
+
runner.testFile("nodeJSHttpServer.ts", () =>
|
|
11
|
+
{
|
|
12
|
+
runner.testType("NodeJSHttpServer", () =>
|
|
13
|
+
{
|
|
14
|
+
runner.testFunction("create()", (test: Test) =>
|
|
15
|
+
{
|
|
16
|
+
const httpServer: NodeJSHttpServer = NodeJSHttpServer.create();
|
|
17
|
+
test.assertNotUndefinedAndNotNull(httpServer);
|
|
18
|
+
test.assertFalse(httpServer.isDisposed());
|
|
19
|
+
test.assertFalse(httpServer.isStarted());
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
runner.testFunction("dispose()", async (test: Test) =>
|
|
23
|
+
{
|
|
24
|
+
const httpServer: NodeJSHttpServer = NodeJSHttpServer.create();
|
|
25
|
+
|
|
26
|
+
test.assertTrue(await httpServer.dispose());
|
|
27
|
+
test.assertTrue(httpServer.isDisposed());
|
|
28
|
+
test.assertFalse(httpServer.isStarted());
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < 3; i++)
|
|
31
|
+
{
|
|
32
|
+
test.assertFalse(await httpServer.dispose());
|
|
33
|
+
test.assertTrue(httpServer.isDisposed());
|
|
34
|
+
test.assertFalse(httpServer.isStarted());
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
runner.testFunction("start()", () =>
|
|
39
|
+
{
|
|
40
|
+
runner.test("when disposed", async (test: Test) =>
|
|
41
|
+
{
|
|
42
|
+
const httpServer: NodeJSHttpServer = NodeJSHttpServer.create();
|
|
43
|
+
test.assertTrue(await httpServer.dispose());
|
|
44
|
+
|
|
45
|
+
test.assertThrows(() => httpServer.start(3000), new PreConditionError(
|
|
46
|
+
"Expression: this.isDisposed()",
|
|
47
|
+
"Expected: false",
|
|
48
|
+
"Actual: true",
|
|
49
|
+
));
|
|
50
|
+
test.assertTrue(httpServer.isDisposed());
|
|
51
|
+
test.assertFalse(httpServer.isStarted());
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
runner.test("simple scenario", async (test: Test) =>
|
|
55
|
+
{
|
|
56
|
+
const httpServer: NodeJSHttpServer = NodeJSHttpServer.create();
|
|
57
|
+
|
|
58
|
+
httpServer.start(3000);
|
|
59
|
+
try
|
|
60
|
+
{
|
|
61
|
+
const httpClient: FetchHttpClient = FetchHttpClient.create();
|
|
62
|
+
const response: FetchHttpIncomingResponse = await httpClient.sendGetRequest("http://localhost:3000");
|
|
63
|
+
|
|
64
|
+
test.assertNotUndefinedAndNotNull(response);
|
|
65
|
+
test.assertEqual(200, response.getStatusCode());
|
|
66
|
+
}
|
|
67
|
+
finally
|
|
68
|
+
{
|
|
69
|
+
await httpServer.dispose();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NotFoundError } from "../sources/notFoundError";
|
|
2
|
+
import { Test } from "./test";
|
|
3
|
+
import { TestRunner } from "./testRunner";
|
|
4
|
+
|
|
5
|
+
export function test(runner: TestRunner): void
|
|
6
|
+
{
|
|
7
|
+
runner.testFile("notFoundError.ts", () =>
|
|
8
|
+
{
|
|
9
|
+
runner.testType("NotFoundError", () =>
|
|
10
|
+
{
|
|
11
|
+
runner.testFunction("constructor(...string[])", () =>
|
|
12
|
+
{
|
|
13
|
+
runner.test("with no arguments", (test: Test) =>
|
|
14
|
+
{
|
|
15
|
+
const error: NotFoundError = new NotFoundError();
|
|
16
|
+
test.assertNotUndefinedAndNotNull(error);
|
|
17
|
+
test.assertEqual(error.name, "Error");
|
|
18
|
+
test.assertEqual(error.message, "");
|
|
19
|
+
test.assertNotUndefinedAndNotNull(error.stack);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PostConditionError } from "../sources/postConditionError";
|
|
2
|
+
import { Test } from "./test";
|
|
3
|
+
import { TestRunner } from "./testRunner";
|
|
4
|
+
|
|
5
|
+
export function test(runner: TestRunner): void
|
|
6
|
+
{
|
|
7
|
+
runner.testFile("postConditionError.ts", () =>
|
|
8
|
+
{
|
|
9
|
+
runner.testType(PostConditionError.name, () =>
|
|
10
|
+
{
|
|
11
|
+
runner.testFunction("constructor(string|undefined)", () =>
|
|
12
|
+
{
|
|
13
|
+
runner.test("with no arguments", (test: Test) =>
|
|
14
|
+
{
|
|
15
|
+
const error: PostConditionError = new PostConditionError();
|
|
16
|
+
test.assertNotUndefinedAndNotNull(error);
|
|
17
|
+
test.assertEqual(error.name, "Error");
|
|
18
|
+
test.assertEqual(error.message, "");
|
|
19
|
+
test.assertNotUndefinedAndNotNull(error.stack);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
2
|
+
import { Test } from "./test";
|
|
3
|
+
import { TestRunner } from "./testRunner";
|
|
4
|
+
|
|
5
|
+
export function test(runner: TestRunner): void
|
|
6
|
+
{
|
|
7
|
+
runner.testFile("preConditionError.ts", () =>
|
|
8
|
+
{
|
|
9
|
+
runner.testType("PreConditionError", () =>
|
|
10
|
+
{
|
|
11
|
+
runner.testFunction("constructor(string|undefined)", () =>
|
|
12
|
+
{
|
|
13
|
+
runner.test("with no arguments", (test: Test) =>
|
|
14
|
+
{
|
|
15
|
+
const error: PreConditionError = new PreConditionError();
|
|
16
|
+
test.assertNotUndefinedAndNotNull(error);
|
|
17
|
+
test.assertEqual(error.name, "Error");
|
|
18
|
+
test.assertEqual(error.message, "");
|
|
19
|
+
test.assertNotUndefinedAndNotNull(error.stack);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|