@everyonesoftware/common 2.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 +11 -2
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -36
  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
package/tests/testSkip.ts DELETED
@@ -1,34 +0,0 @@
1
- import { BasicTestSkip } from "./basicTestSkip";
2
-
3
- /**
4
- * A type that is used to mark that a test group or a test should be skipped.
5
- */
6
- export abstract class TestSkip
7
- {
8
- protected constructor()
9
- {
10
- }
11
-
12
- /**
13
- * Create a new {@link TestSkip} with the provided properties.
14
- * @param shouldSkip Whether the tests associated with the new {@link TestSkip}
15
- * should be skipped.
16
- * @param message The message that explains why the tests associated with this {@link TestSkip}
17
- * should be skipped.
18
- */
19
- public static create(shouldSkip?: boolean, message?: string): TestSkip
20
- {
21
- return BasicTestSkip.create(shouldSkip, message);
22
- }
23
-
24
- /**
25
- * Get whether the tests associated with this {@link TestSkip} should be skipped.
26
- */
27
- public abstract getShouldSkip(): boolean;
28
-
29
- /**
30
- * Get the message that explains why the tests associated with this {@link TestSkip}
31
- * should be skipped.
32
- */
33
- public abstract getMessage(): string;
34
- }
package/tests/tests.ts DELETED
@@ -1,103 +0,0 @@
1
- import { ConsoleTestRunner } from "./consoleTestRunner";
2
- import * as assertTestTests from "./assertTestTests";
3
- import * as byteListStreamTests from "./byteListStreamTests";
4
- import * as byteListTests from "./byteListTests";
5
- import * as byteTests from "./bytesTests";
6
- import * as characterListStreamTests from "./characterListStreamTests";
7
- import * as characterListTests from "./characterListTests";
8
- import * as comparerTests from "./comparerTests";
9
- import * as conditionTests from "./conditionTests";
10
- import * as consoleTestRunner2Tests from "./consoleTestRunnerTests";
11
- import * as dateTimeTests from "./dateTimeTests";
12
- import * as depthFirstSearchTests from "./depthFirstSearchTests";
13
- import * as disposableTests from "./disposableTests";
14
- import * as englishTests from "./englishTests";
15
- import * as equalFunctionsTests from "./equalFunctionsTests";
16
- import * as fetchHttpClientTests from "./fetchHttpClientTests";
17
- import * as generatorTests from "./generatorTests";
18
- import * as httpClientTests from "./httpClientTests";
19
- import * as inMemoryCharacterWriteStreamTests from "./inMemoryCharacterWriteStreamTests";
20
- import * as iterableTests from "./iterableTests";
21
- import * as iteratorTests from "./iteratorTests";
22
- import * as javascriptMapMapTests from "./javascriptMapMapTests";
23
- import * as listTests from "./listTests";
24
- import * as mapIteratorTests from "./mapIteratorTests";
25
- import * as mapTests from "./mapTests";
26
- import * as mutableConditionTests from "./mutableConditionTests";
27
- import * as mutableMapTests from "./mutableMapTests";
28
- import * as notFoundErrorTests from "./notFoundErrorTests";
29
- import * as postConditionErrorTests from "./postConditionErrorTests";
30
- import * as preConditionErrorTests from "./preConditionErrorTests";
31
- import * as promiseAsyncResultTests from "./promiseAsyncResultTests";
32
- import * as propertyTests from "./propertyTests";
33
- import * as queueTests from "./queueTests";
34
- import * as realHttpServerTests from "./nodeJSHttpServerTests";
35
- import * as recreationDotGovClientTests from "./recreationDotGovClientTests";
36
- import * as setTests from "./setTests";
37
- import * as stackTests from "./stackTests";
38
- import * as stringComparerTests from "./stringComparerTests";
39
- import * as stringIteratorTests from "./stringIteratorTests";
40
- import * as stringsTests from "./stringsTests";
41
- import * as syncResultTests from "./syncResultTests";
42
- import * as testActionTests from "./testActionTests";
43
- import * as testRunnerTests from "./testRunnerTests";
44
- import * as toStringFunctionsTests from "./toStringFunctionsTests";
45
- import * as typesTests from "./typesTests";
46
- import * as whereIteratorTests from "./whereIteratorTests";
47
- import * as wonderlandTrailClientTests from "./wonderlandTrailClientTests";
48
-
49
- export const hasNetworkAccess: boolean = true;
50
-
51
- async function tests(): Promise<void>
52
- {
53
- await ConsoleTestRunner.run([
54
- assertTestTests,
55
- promiseAsyncResultTests.test,
56
- byteTests.test,
57
- comparerTests,
58
- conditionTests,
59
- consoleTestRunner2Tests,
60
- dateTimeTests,
61
- disposableTests,
62
- englishTests,
63
- equalFunctionsTests.test,
64
- fetchHttpClientTests,
65
- generatorTests,
66
- httpClientTests,
67
- inMemoryCharacterWriteStreamTests,
68
- iterableTests,
69
- iteratorTests,
70
- javascriptMapMapTests,
71
- listTests,
72
- mapIteratorTests,
73
- mapTests,
74
- mutableConditionTests,
75
- mutableMapTests,
76
- notFoundErrorTests,
77
- postConditionErrorTests,
78
- preConditionErrorTests,
79
- propertyTests,
80
- queueTests,
81
- realHttpServerTests,
82
- recreationDotGovClientTests,
83
- stackTests,
84
- stringComparerTests,
85
- stringIteratorTests,
86
- stringsTests,
87
- syncResultTests,
88
- testActionTests,
89
- testRunnerTests,
90
- toStringFunctionsTests,
91
- typesTests,
92
- whereIteratorTests,
93
- wonderlandTrailClientTests,
94
- setTests,
95
- depthFirstSearchTests,
96
- byteListTests,
97
- byteListStreamTests,
98
- characterListTests,
99
- characterListStreamTests,
100
- ]);
101
- }
102
-
103
- tests();
@@ -1,55 +0,0 @@
1
- import { Comparison } from "../sources/comparison";
2
- import { Iterable } from "../sources/iterable";
3
- import { List } from "../sources/list";
4
- import { Map } from "../sources/map";
5
- import { ToStringFunctions } from "../sources/toStringFunctions";
6
- import { Test } from "./test";
7
- import { TestRunner } from "./testRunner";
8
-
9
- export function test(runner: TestRunner): void
10
- {
11
- runner.testFile("toStringFunctions.ts", () =>
12
- {
13
- runner.testType("ToStringFunctions", () =>
14
- {
15
- runner.testFunction("toString(unknown)", () =>
16
- {
17
- function toStringTest(value: unknown, expected: string)
18
- {
19
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
20
- {
21
- const functions: ToStringFunctions = ToStringFunctions.create();
22
- test.assertSame(functions.toString(value), expected);
23
- });
24
- }
25
-
26
- // toStringTest(undefined, "undefined");
27
- // toStringTest(null, "null");
28
- // toStringTest(false, "false");
29
- // toStringTest(true, "true");
30
- // toStringTest(50, "50");
31
- // toStringTest(NaN, "NaN");
32
- // toStringTest(Infinity, "Infinity");
33
- // toStringTest(-Infinity, "-Infinity");
34
- // toStringTest(1.2, "1.2");
35
- // toStringTest("hello\tthere\nfriend", `"hello\\tthere\\nfriend"`);
36
- // toStringTest({}, "{}");
37
- // toStringTest({1:"one", b: "two"}, `{"1":"one","b":"two"}`);
38
- // toStringTest([], "[]");
39
- // toStringTest([undefined, undefined], "[undefined,undefined]");
40
- // toStringTest([1, 2.3, false], "[1,2.3,false]");
41
- // toStringTest([[[]]], "[[[]]]");
42
- // toStringTest(Iterable.create(), `[]`);
43
- // toStringTest(Iterable.create<string>(["abc"]), `["abc"]`);
44
- // toStringTest(Iterable.create([1, 2, 3]), `[1,2,3]`);
45
- // toStringTest(List.create(), `[]`);
46
- // toStringTest(List.create<string>(["abc"]), `["abc"]`);
47
- // toStringTest(List.create([1, 2, 3]), `[1,2,3]`);
48
- toStringTest(Map.create(), `{}`);
49
- // toStringTest(Map.create<string,number>().set("a", 1), `{"a":1}`);
50
- // toStringTest(Map.create<string,number>().set("a", 1).set("b", 2), `{"a":1,"b":2}`);
51
- // toStringTest(Comparison.LessThan, "0");
52
- });
53
- });
54
- });
55
- }
@@ -1,257 +0,0 @@
1
- import { Iterable } from "../sources/iterable";
2
- import { List } from "../sources/list";
3
- import {
4
- asBoolean, hasFunction, hasProperty, isArray, isBoolean, isFunction, isNumber, isObject,
5
- isObjectOrArrayOrNull, isString
6
- } from "../sources/types";
7
- import { Test } from "./test";
8
- import { TestRunner } from "./testRunner";
9
-
10
- export function test(runner: TestRunner): void
11
- {
12
- runner.testFile("types.ts", () =>
13
- {
14
- runner.testFunction("isBoolean(unknown)", () =>
15
- {
16
- function isBooleanTest(value: unknown, expected: boolean): void
17
- {
18
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
19
- {
20
- test.assertSame(isBoolean(value), expected);
21
- });
22
- }
23
-
24
- isBooleanTest(undefined, false);
25
- isBooleanTest(null, false);
26
- isBooleanTest("", false);
27
- isBooleanTest("true", false);
28
- isBooleanTest(123, false);
29
- isBooleanTest({}, false);
30
- isBooleanTest([], false);
31
- isBooleanTest(true, true);
32
- isBooleanTest(false, true);
33
- });
34
-
35
- runner.testFunction("asBoolean(unknown)", () =>
36
- {
37
- function asBooleanTest(value: unknown, expected: boolean | undefined): void
38
- {
39
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
40
- {
41
- test.assertEqual(asBoolean(value), expected);
42
- });
43
- }
44
-
45
- asBooleanTest(undefined, undefined);
46
- asBooleanTest(null, undefined);
47
- asBooleanTest("", undefined);
48
- asBooleanTest("true", undefined);
49
- asBooleanTest(123, undefined);
50
- asBooleanTest({}, undefined);
51
- asBooleanTest([], undefined);
52
- asBooleanTest(true, true);
53
- asBooleanTest(false, false);
54
- asBooleanTest(() => false, undefined);
55
- asBooleanTest(() => true, undefined);
56
- });
57
-
58
- runner.testFunction("isNumber(unknown)", () =>
59
- {
60
- function isNumberTest(value: unknown, expected: boolean): void
61
- {
62
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
63
- {
64
- test.assertSame(isNumber(value), expected);
65
- });
66
- }
67
-
68
- isNumberTest(undefined, false);
69
- isNumberTest(null, false);
70
- isNumberTest("", false);
71
- isNumberTest("123", false);
72
- isNumberTest({}, false);
73
- isNumberTest([], false);
74
- isNumberTest(true, false);
75
- isNumberTest(false, false);
76
- isNumberTest(123, true);
77
- isNumberTest(Infinity, true);
78
- isNumberTest(-Infinity, true);
79
- isNumberTest(NaN, true);
80
- });
81
-
82
- runner.testFunction("isString(unknown)", () =>
83
- {
84
- function isStringTest(value: unknown, expected: boolean): void
85
- {
86
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
87
- {
88
- test.assertSame(isString(value), expected);
89
- });
90
- }
91
-
92
- isStringTest(undefined, false);
93
- isStringTest(null, false);
94
- isStringTest(50, false);
95
- isStringTest({}, false);
96
- isStringTest("", true);
97
- isStringTest("hello", true);
98
- });
99
-
100
- runner.testFunction("isFunction(unknown)", () =>
101
- {
102
- function isFunctionTest(value: unknown, expected: boolean): void
103
- {
104
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
105
- {
106
- test.assertSame(isFunction(value), expected);
107
- });
108
- }
109
-
110
- isFunctionTest(undefined, false);
111
- isFunctionTest(null, false);
112
- isFunctionTest(false, false);
113
- isFunctionTest(true, false);
114
- isFunctionTest(123, false);
115
- isFunctionTest("abc", false);
116
- isFunctionTest({}, false);
117
- isFunctionTest([], false);
118
-
119
- isFunctionTest(isArray, true);
120
- isFunctionTest(isFunction, true);
121
- isFunctionTest(() => 123, true);
122
- });
123
-
124
- runner.testFunction("isArray(unknown)", () =>
125
- {
126
- function isArrayTest(value: unknown, expected: boolean): void
127
- {
128
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
129
- {
130
- test.assertSame(isArray(value), expected);
131
- });
132
- }
133
-
134
- isArrayTest(undefined, false);
135
- isArrayTest(null, false);
136
- isArrayTest(50, false);
137
- isArrayTest({}, false);
138
- isArrayTest("", false);
139
- isArrayTest("hello", false);
140
- isArrayTest(Iterable.create(), false);
141
- isArrayTest(List.create(), false);
142
- isArrayTest(new Uint8Array(), false);
143
-
144
- isArrayTest([], true);
145
- isArrayTest(["a", "b"], true);
146
- isArrayTest(new Array(), true);
147
- isArrayTest(Array.from([1, 2]), true);
148
- });
149
-
150
- runner.testFunction("isObjectOrArrayOrNull(unknown)", () =>
151
- {
152
- function isObjectOrArrayOrNullTest(value: unknown, expected: boolean): void
153
- {
154
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
155
- {
156
- test.assertSame(isObjectOrArrayOrNull(value), expected);
157
- });
158
- }
159
-
160
- isObjectOrArrayOrNullTest(undefined, false);
161
- isObjectOrArrayOrNullTest(50, false);
162
- isObjectOrArrayOrNullTest("", false);
163
- isObjectOrArrayOrNullTest("hello", false);
164
-
165
- isObjectOrArrayOrNullTest({}, true);
166
- isObjectOrArrayOrNullTest(null, true);
167
- isObjectOrArrayOrNullTest([], true);
168
- isObjectOrArrayOrNullTest(["a", "b"], true);
169
- isObjectOrArrayOrNullTest(new Array(), true);
170
- isObjectOrArrayOrNullTest(Array.from([1, 2]), true);
171
- isObjectOrArrayOrNullTest(Iterable.create(), true);
172
- isObjectOrArrayOrNullTest(List.create(), true);
173
- });
174
-
175
- runner.testFunction("isObject(unknown)", () =>
176
- {
177
- function isObjectTest(value: unknown, expected: boolean): void
178
- {
179
- runner.test(`with ${runner.toString(value)}`, (test: Test) =>
180
- {
181
- test.assertSame(isObject(value), expected);
182
- });
183
- }
184
-
185
- isObjectTest(undefined, false);
186
- isObjectTest(50, false);
187
- isObjectTest("", false);
188
- isObjectTest("hello", false);
189
- isObjectTest(null, false);
190
- isObjectTest([], false);
191
- isObjectTest(["a", "b"], false);
192
- isObjectTest(new Array(), false);
193
- isObjectTest(Array.from([1, 2]), false);
194
-
195
- isObjectTest({}, true);
196
- isObjectTest(Iterable.create(), true);
197
- isObjectTest(List.create(), true);
198
- });
199
-
200
- runner.testFunction("hasProperty(TValue,TPropertyKey extends PropertyKey)", () =>
201
- {
202
- function hasPropertyTest<TPropertyKey extends PropertyKey>(value: unknown, propertyKey: TPropertyKey, expected: boolean): void
203
- {
204
- runner.test(`with ${runner.andList([value, propertyKey])}`, (test: Test) =>
205
- {
206
- const result: boolean = hasProperty(value, propertyKey);
207
- test.assertSame(result, expected);
208
- if (value !== undefined && value !== null)
209
- {
210
- if (result)
211
- {
212
- test.assertNotUndefined((value as any)[propertyKey]);
213
- }
214
- else
215
- {
216
- test.assertUndefined((value as any)[propertyKey]);
217
- }
218
- }
219
- });
220
- }
221
-
222
- hasPropertyTest(undefined, "spam", false);
223
- hasPropertyTest(null, "spam", false);
224
- hasPropertyTest([], "spam", false);
225
- hasPropertyTest([], "length", true);
226
- hasPropertyTest({}, "spam", false);
227
- hasPropertyTest("", "spam", false);
228
- hasPropertyTest("", "length", true);
229
- hasPropertyTest(5, "spam", false);
230
- hasPropertyTest(5, "toString", true);
231
- });
232
-
233
- runner.testFunction("hasFunction(TValue,TPropertyKey extends PropertyKey)", () =>
234
- {
235
- function hasFunctionTest<TPropertyKey extends PropertyKey>(value: unknown, propertyKey: TPropertyKey, expected: boolean): void
236
- {
237
- runner.test(`with ${runner.andList([value, propertyKey])}`, (test: Test) =>
238
- {
239
- test.assertSame(hasFunction(value, propertyKey), expected);
240
- });
241
- }
242
-
243
- hasFunctionTest(undefined, "spam", false);
244
- hasFunctionTest(null, "spam", false);
245
- hasFunctionTest([], "spam", false);
246
- hasFunctionTest([], "length", false);
247
- hasFunctionTest([], Symbol.iterator, true);
248
- hasFunctionTest({}, "spam", false);
249
- hasFunctionTest("", "spam", false);
250
- hasFunctionTest("", "length", false);
251
- hasFunctionTest("", "at", true);
252
- hasFunctionTest("", Symbol.iterator, true);
253
- hasFunctionTest(5, "spam", false);
254
- hasFunctionTest(5, "toString", true);
255
- });
256
- });
257
- }
@@ -1,77 +0,0 @@
1
- import { Iterator } from "../sources/iterator";
2
- import { PreConditionError } from "../sources/preConditionError";
3
- import { WhereIterator } from "../sources/whereIterator";
4
- import { iteratorTests } from "./iteratorTests";
5
- import { Test } from "./test";
6
- import { TestRunner } from "./testRunner";
7
-
8
- export function test(runner: TestRunner): void
9
- {
10
- runner.testFile("whereIterator.ts", () =>
11
- {
12
- runner.testType("WhereIterator<T>", () =>
13
- {
14
- iteratorTests(runner, () => WhereIterator.create(Iterator.create<number>([]), (_: number) => true));
15
-
16
- runner.testFunction("create(T[])", () =>
17
- {
18
- function createErrorTest<T>(testName: string, innerIterator: Iterator<T>, condition: (value: T) => boolean, expected: Error): void
19
- {
20
- runner.test(testName, (test: Test) =>
21
- {
22
- test.assertThrows(() => WhereIterator.create(innerIterator, condition), expected);
23
- });
24
- }
25
-
26
- createErrorTest(
27
- `with undefined innerIterator`,
28
- undefined!,
29
- (_: number) => true,
30
- new PreConditionError(
31
- "Expression: innerIterator",
32
- "Expected: not undefined and not null",
33
- "Actual: undefined",
34
- ),
35
- );
36
- createErrorTest(
37
- `with null innerIterator`,
38
- null!,
39
- (_: number) => true,
40
- new PreConditionError(
41
- "Expression: innerIterator",
42
- "Expected: not undefined and not null",
43
- "Actual: null",
44
- ),
45
- );
46
-
47
- function createTest<T>(testName: string, innerIterator: Iterator<T>, condition: (value: T) => boolean, expected: T[]): void
48
- {
49
- runner.test(testName, async (test: Test) =>
50
- {
51
- const iterator: WhereIterator<T> = WhereIterator.create(innerIterator, condition);
52
- test.assertEqual(await iterator.toArray(), expected);
53
- });
54
- }
55
-
56
- createTest(
57
- `with empty innerIterator`,
58
- Iterator.create<number>([]),
59
- (_: number) => true,
60
- [],
61
- );
62
- createTest(
63
- `with none of the iterator values match the condition`,
64
- Iterator.create([1, 2, 3]),
65
- (value: number) => value > 10,
66
- [],
67
- );
68
- createTest(
69
- `with some of the iterator values match the condition`,
70
- Iterator.create([1, 2, 3]),
71
- (value: number) => value % 2 == 1,
72
- [1, 3],
73
- );
74
- });
75
- });
76
- });
77
- }