@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,34 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
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();
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
}
|