@everyonesoftware/common 3.0.0 → 5.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/outputs/chunk-AY3YWKOM.js +7741 -0
- package/outputs/chunk-AY3YWKOM.js.map +1 -0
- package/outputs/sources.cjs +9007 -0
- package/outputs/sources.cjs.map +1 -0
- package/outputs/sources.d.cts +4082 -0
- package/outputs/sources.d.ts +4082 -0
- package/outputs/sources.js +1370 -0
- package/outputs/sources.js.map +1 -0
- package/outputs/tests.cjs +17208 -0
- package/outputs/tests.cjs.map +1 -0
- package/outputs/tests.d.cts +3 -0
- package/outputs/tests.d.ts +3 -0
- package/outputs/tests.js +9798 -0
- package/outputs/tests.js.map +1 -0
- package/package.json +6 -1
- package/.c8rc.json +0 -12
- package/.github/workflows/publish.yml +0 -54
- package/.mocharc.json +0 -9
- package/sources/assertMessageParameters.ts +0 -22
- package/sources/asyncIterator.ts +0 -437
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
- package/sources/asyncResult.ts +0 -95
- package/sources/basicDisposable.ts +0 -57
- package/sources/byteList.ts +0 -202
- package/sources/byteListStream.ts +0 -121
- package/sources/byteReadStream.ts +0 -24
- package/sources/byteWriteStream.ts +0 -16
- package/sources/bytes.ts +0 -25
- package/sources/characterList.ts +0 -195
- package/sources/characterListStream.ts +0 -151
- package/sources/characterReadStream.ts +0 -81
- package/sources/characterReadStreamIterator.ts +0 -128
- package/sources/characterWriteStream.ts +0 -45
- package/sources/commandLineParameter.ts +0 -45
- package/sources/commandLineParameters.ts +0 -21
- package/sources/comparable.ts +0 -144
- package/sources/comparer.ts +0 -133
- package/sources/comparison.ts +0 -20
- package/sources/concatenateIterable.ts +0 -119
- package/sources/concatenateIterator.ts +0 -165
- package/sources/condition.ts +0 -329
- package/sources/currentProcess.ts +0 -158
- package/sources/dateTime.ts +0 -130
- package/sources/depthFirstSearch.ts +0 -230
- package/sources/disposable.ts +0 -31
- package/sources/emptyError.ts +0 -10
- package/sources/english.ts +0 -45
- package/sources/equalFunctions.ts +0 -123
- package/sources/fetchHttpClient.ts +0 -89
- package/sources/fetchHttpResponse.ts +0 -106
- package/sources/flatMapIterable.ts +0 -104
- package/sources/flatMapIterator.ts +0 -152
- package/sources/generator.ts +0 -251
- package/sources/httpClient.ts +0 -36
- package/sources/httpHeader.ts +0 -37
- package/sources/httpHeaders.ts +0 -216
- package/sources/httpIncomingRequest.ts +0 -30
- package/sources/httpIncomingResponse.ts +0 -19
- package/sources/httpMethod.ts +0 -164
- package/sources/httpOutgoingRequest.ts +0 -119
- package/sources/httpOutgoingResponse.ts +0 -113
- package/sources/httpServer.ts +0 -34
- package/sources/inMemoryCharacterWriteStream.ts +0 -78
- package/sources/index.ts +0 -101
- package/sources/iterable.ts +0 -345
- package/sources/iterator.ts +0 -481
- package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
- package/sources/javascript.ts +0 -59
- package/sources/javascriptArrayList.ts +0 -175
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
- package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
- package/sources/javascriptMapMap.ts +0 -143
- package/sources/javascriptSetSet.ts +0 -134
- package/sources/list.ts +0 -330
- package/sources/listQueue.ts +0 -62
- package/sources/listStack.ts +0 -62
- package/sources/luxonDateTime.ts +0 -109
- package/sources/map.ts +0 -302
- package/sources/mapAsyncIterator.ts +0 -141
- package/sources/mapIterable.ts +0 -105
- package/sources/mapIterator.ts +0 -145
- package/sources/mutableCondition.ts +0 -451
- package/sources/mutableHttpHeaders.ts +0 -204
- package/sources/mutableMap.ts +0 -292
- package/sources/network.ts +0 -18
- package/sources/node.ts +0 -37
- package/sources/nodeJSCharacterWriteStream.ts +0 -42
- package/sources/nodeJSHttpIncomingRequest.ts +0 -132
- package/sources/nodeJSHttpServer.ts +0 -134
- package/sources/notFoundError.ts +0 -12
- package/sources/postCondition.ts +0 -284
- package/sources/postConditionError.ts +0 -12
- package/sources/preCondition.ts +0 -284
- package/sources/preConditionError.ts +0 -12
- package/sources/promiseAsyncResult.ts +0 -174
- package/sources/property.ts +0 -63
- package/sources/queue.ts +0 -49
- package/sources/realNetwork.ts +0 -28
- package/sources/recreationDotGovClient.ts +0 -259
- package/sources/searchControl.ts +0 -42
- package/sources/set.ts +0 -244
- package/sources/skipAsyncIterator.ts +0 -145
- package/sources/skipIterator.ts +0 -155
- package/sources/stack.ts +0 -48
- package/sources/stringComparer.ts +0 -33
- package/sources/stringIterator.ts +0 -149
- package/sources/strings.ts +0 -322
- package/sources/syncResult.ts +0 -300
- package/sources/takeAsyncIterator.ts +0 -141
- package/sources/takeIterator.ts +0 -151
- package/sources/toStringFunctions.ts +0 -185
- package/sources/types.ts +0 -371
- package/sources/whereAsyncIterator.ts +0 -143
- package/sources/whereIterable.ts +0 -108
- package/sources/whereIterator.ts +0 -157
- package/sources/wonderlandTrailClient.ts +0 -1503
- package/tests/assertTest.ts +0 -113
- package/tests/assertTestTests.ts +0 -75
- package/tests/basicTestSkip.ts +0 -51
- package/tests/byteListStreamTests.ts +0 -390
- package/tests/byteListTests.ts +0 -27
- package/tests/bytesTests.ts +0 -43
- package/tests/characterListStreamTests.ts +0 -391
- package/tests/characterListTests.ts +0 -250
- package/tests/characterWriteStreamTests.ts +0 -12
- package/tests/comparerTests.ts +0 -92
- package/tests/conditionTests.ts +0 -877
- package/tests/consoleTestRunner.ts +0 -404
- package/tests/consoleTestRunnerTests.ts +0 -651
- package/tests/dateTimeTests.ts +0 -30
- package/tests/depthFirstSearchTests.ts +0 -106
- package/tests/disposableTests.ts +0 -121
- package/tests/englishTests.ts +0 -103
- package/tests/equalFunctionsTests.ts +0 -223
- package/tests/failedTest.ts +0 -43
- package/tests/fetchHttpClientTests.ts +0 -33
- package/tests/generatorTests.ts +0 -86
- package/tests/httpClientTests.ts +0 -18
- package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
- package/tests/iterableTests.ts +0 -141
- package/tests/iteratorTests.ts +0 -1086
- package/tests/javascriptMapMapTests.ts +0 -21
- package/tests/listTests.ts +0 -338
- package/tests/mapIteratorTests.ts +0 -55
- package/tests/mapTests.ts +0 -104
- package/tests/mutableConditionTests.ts +0 -273
- package/tests/mutableMapTests.ts +0 -154
- package/tests/nodeJSHttpServerTests.ts +0 -75
- package/tests/notFoundErrorTests.ts +0 -24
- package/tests/postConditionErrorTests.ts +0 -24
- package/tests/preConditionErrorTests.ts +0 -24
- package/tests/promiseAsyncResultTests.ts +0 -688
- package/tests/propertyTests.ts +0 -63
- package/tests/queueTests.ts +0 -29
- package/tests/recreationDotGovClientTests.ts +0 -191
- package/tests/setTests.ts +0 -140
- package/tests/skippedTest.ts +0 -39
- package/tests/stackTests.ts +0 -66
- package/tests/stringComparerTests.ts +0 -60
- package/tests/stringIteratorTests.ts +0 -156
- package/tests/stringsTests.ts +0 -516
- package/tests/syncResultTests.ts +0 -1251
- package/tests/test.ts +0 -228
- package/tests/testAction.ts +0 -75
- package/tests/testActionTests.ts +0 -93
- package/tests/testFailureTests.ts +0 -12
- package/tests/testRunner.ts +0 -267
- package/tests/testRunnerTests.ts +0 -895
- package/tests/testSkip.ts +0 -34
- package/tests/tests.ts +0 -103
- package/tests/toStringFunctionsTests.ts +0 -55
- package/tests/typesTests.ts +0 -257
- package/tests/whereIteratorTests.ts +0 -77
- package/tests/wonderlandTrailClientTests.ts +0 -452
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -13
package/tests/conditionTests.ts
DELETED
|
@@ -1,877 +0,0 @@
|
|
|
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
|
-
}
|