@everyonesoftware/common 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/assertTest.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
|
|
3
|
-
import { PreCondition } from "../sources/preCondition";
|
|
4
|
-
import { isFunction, Type } from "../sources/types";
|
|
5
|
-
import { Test } from "./test";
|
|
6
|
-
import { SyncResult } from "../sources/syncResult";
|
|
7
|
-
import { PromiseAsyncResult } from "../sources/promiseAsyncResult";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A {@link Test} type that uses the standard "assert" module to make assertions.
|
|
11
|
-
*/
|
|
12
|
-
export class AssertTest implements Test
|
|
13
|
-
{
|
|
14
|
-
private readonly name: string;
|
|
15
|
-
|
|
16
|
-
protected constructor(name: string)
|
|
17
|
-
{
|
|
18
|
-
this.name = name;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Create a new {@link AssertTest} object.
|
|
23
|
-
*/
|
|
24
|
-
public static create(name: string): AssertTest
|
|
25
|
-
{
|
|
26
|
-
return new AssertTest(name);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public fail(message: string): never
|
|
30
|
-
{
|
|
31
|
-
PreCondition.assertNotEmpty(message, "message");
|
|
32
|
-
|
|
33
|
-
assert.fail(message);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public assertUndefined(value: unknown): asserts value is undefined
|
|
37
|
-
{
|
|
38
|
-
Test.assertUndefined(this, value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public assertNotUndefined<T>(value: T): asserts value is NonNullable<T>
|
|
42
|
-
{
|
|
43
|
-
Test.assertNotUndefined(this, value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public assertNull(value: unknown): asserts value is null
|
|
47
|
-
{
|
|
48
|
-
Test.assertNull(this, value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public assertNotNull<T>(value: T): asserts value is NonNullable<T>
|
|
52
|
-
{
|
|
53
|
-
Test.assertNotNull(this, value);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public assertNotUndefinedAndNotNull<T>(value: T): asserts value is NonNullable<T>
|
|
57
|
-
{
|
|
58
|
-
Test.assertNotUndefinedAndNotNull(this, value);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public assertSame<T>(left: T, right: T): void
|
|
62
|
-
{
|
|
63
|
-
assert.strictEqual(left, right);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public assertNotSame<T>(left: T, right: T): void
|
|
67
|
-
{
|
|
68
|
-
assert.notStrictEqual(left, right);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public assertEqual<T>(left: T, right: T, message?: string): void
|
|
72
|
-
{
|
|
73
|
-
assert.deepStrictEqual(left, right, message);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public assertNotEqual<T>(left: T, right: T): void
|
|
77
|
-
{
|
|
78
|
-
assert.notDeepStrictEqual(left, right);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public assertFalse(value: boolean): void
|
|
82
|
-
{
|
|
83
|
-
Test.assertFalse(this, value);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public assertTrue(value: boolean): void
|
|
87
|
-
{
|
|
88
|
-
Test.assertTrue(this, value);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public assertThrows(action: SyncResult<unknown> | (() => void), expectedError?: Error): void
|
|
92
|
-
{
|
|
93
|
-
if (!isFunction(action))
|
|
94
|
-
{
|
|
95
|
-
const syncResult: SyncResult<unknown> = action;
|
|
96
|
-
action = () => { syncResult.await(); };
|
|
97
|
-
}
|
|
98
|
-
assert.throws(action, expectedError);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public assertThrowsAsync(action: Promise<unknown> | (() => Promise<unknown>), expectedError: Error): PromiseAsyncResult<void>
|
|
102
|
-
{
|
|
103
|
-
const promiseOrAsyncAction = isFunction(action)
|
|
104
|
-
? async () => await action()
|
|
105
|
-
: action;
|
|
106
|
-
return PromiseAsyncResult.create(assert.rejects(promiseOrAsyncAction, expectedError));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public assertInstanceOf<T>(value: unknown, type: Type<T>, typeCheck?: (value: unknown) => value is T): asserts value is T
|
|
110
|
-
{
|
|
111
|
-
Test.assertInstanceOf(this, value, type, typeCheck);
|
|
112
|
-
}
|
|
113
|
-
}
|
package/tests/assertTestTests.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AssertionError } from "assert";
|
|
2
|
-
import { AssertTest } from "./assertTest";
|
|
3
|
-
import { Test } from "./test";
|
|
4
|
-
import { TestRunner } from "./testRunner";
|
|
5
|
-
|
|
6
|
-
export function test(runner: TestRunner): void
|
|
7
|
-
{
|
|
8
|
-
runner.testFile("assertTest.ts", () =>
|
|
9
|
-
{
|
|
10
|
-
runner.testType("AssertTest", () =>
|
|
11
|
-
{
|
|
12
|
-
runner.testFunction("assertThrows()", () =>
|
|
13
|
-
{
|
|
14
|
-
runner.test("with throwing action", (test: Test) =>
|
|
15
|
-
{
|
|
16
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
17
|
-
at.assertThrows(() => { throw new Error("abc"); }, new Error("abc"));
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
runner.test("with non-throwing action", (test: Test) =>
|
|
21
|
-
{
|
|
22
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
23
|
-
test.assertThrows(
|
|
24
|
-
() => at.assertThrows(() => {}, new Error("oops")),
|
|
25
|
-
new AssertionError({
|
|
26
|
-
message: "Missing expected exception (Error).",
|
|
27
|
-
operator: "throws",
|
|
28
|
-
expected: new Error("oops"),
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
runner.testFunction("assertThrowsAsync()", () =>
|
|
35
|
-
{
|
|
36
|
-
runner.test("with throwing sync action", async (test: Test) =>
|
|
37
|
-
{
|
|
38
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
39
|
-
await at.assertThrowsAsync(() => { throw new Error("abc"); }, new Error("abc"));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
runner.test("with throwing async action", async (test: Test) =>
|
|
43
|
-
{
|
|
44
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
45
|
-
await at.assertThrowsAsync(async () => { throw new Error("abc"); }, new Error("abc"));
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
runner.test("with rejected Promise", async (test: Test) =>
|
|
49
|
-
{
|
|
50
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
51
|
-
await at.assertThrowsAsync(Promise.reject(new Error("abc")), new Error("abc"));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
runner.test("with throwing action that returns a rejected Promise", async (test: Test) =>
|
|
55
|
-
{
|
|
56
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
57
|
-
await at.assertThrowsAsync(() => Promise.reject(new Error("abc")), new Error("abc"));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
runner.test("with non-throwing async action", async (test: Test) =>
|
|
61
|
-
{
|
|
62
|
-
const at: AssertTest = AssertTest.create("fake-test-name");
|
|
63
|
-
await test.assertThrowsAsync(
|
|
64
|
-
async () => await at.assertThrowsAsync(async () => {}, new Error("oops")),
|
|
65
|
-
new AssertionError({
|
|
66
|
-
message: "Missing expected rejection (Error).",
|
|
67
|
-
operator: "rejects",
|
|
68
|
-
expected: new Error("oops"),
|
|
69
|
-
}),
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
package/tests/basicTestSkip.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { PreCondition } from "../sources/preCondition";
|
|
2
|
-
import { TestSkip } from "./testSkip";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A type that is used to mark that a test group or a test should be skipped.
|
|
6
|
-
*/
|
|
7
|
-
export class BasicTestSkip implements TestSkip
|
|
8
|
-
{
|
|
9
|
-
private readonly shouldSkip: boolean;
|
|
10
|
-
private readonly message: string;
|
|
11
|
-
|
|
12
|
-
private constructor(shouldSkip: boolean, message: string)
|
|
13
|
-
{
|
|
14
|
-
PreCondition.assertNotUndefinedAndNotNull(message, "message");
|
|
15
|
-
|
|
16
|
-
this.shouldSkip = shouldSkip;
|
|
17
|
-
this.message = message;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Create a new {@link TestSkip} with the provided properties.
|
|
22
|
-
* @param shouldSkip Whether the tests associated with the new {@link TestSkip}
|
|
23
|
-
* should be skipped.
|
|
24
|
-
* @param message The message that explains why the tests associated with this {@link TestSkip}
|
|
25
|
-
* should be skipped.
|
|
26
|
-
*/
|
|
27
|
-
public static create(shouldSkip?: boolean, message?: string): BasicTestSkip
|
|
28
|
-
{
|
|
29
|
-
if (shouldSkip === undefined || shouldSkip === null)
|
|
30
|
-
{
|
|
31
|
-
shouldSkip = true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (message === undefined || message === null)
|
|
35
|
-
{
|
|
36
|
-
message = "";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return new BasicTestSkip(shouldSkip, message);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public getShouldSkip(): boolean
|
|
43
|
-
{
|
|
44
|
-
return this.shouldSkip;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public getMessage(): string
|
|
48
|
-
{
|
|
49
|
-
return this.message;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
import { ByteListStream } from "../sources/byteListStream";
|
|
2
|
-
import { EmptyError } from "../sources/emptyError";
|
|
3
|
-
import { PreConditionError } from "../sources/preConditionError";
|
|
4
|
-
import { Test } from "./test";
|
|
5
|
-
import { TestRunner } from "./testRunner";
|
|
6
|
-
|
|
7
|
-
export function test(runner: TestRunner): void
|
|
8
|
-
{
|
|
9
|
-
runner.testFile("byteListStream.ts", () =>
|
|
10
|
-
{
|
|
11
|
-
runner.testType("ByteListStream", () =>
|
|
12
|
-
{
|
|
13
|
-
runner.testFunction("create()", () =>
|
|
14
|
-
{
|
|
15
|
-
runner.test("with no arguments", (test: Test) =>
|
|
16
|
-
{
|
|
17
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
18
|
-
test.assertNotUndefinedAndNotNull(stream);
|
|
19
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
runner.test("with empty array", (test: Test) =>
|
|
23
|
-
{
|
|
24
|
-
const stream: ByteListStream = ByteListStream.create([]);
|
|
25
|
-
test.assertNotUndefinedAndNotNull(stream);
|
|
26
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
runner.test("with non-empty array", (test: Test) =>
|
|
30
|
-
{
|
|
31
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
32
|
-
test.assertNotUndefinedAndNotNull(stream);
|
|
33
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
runner.testFunction("writeBytes()", () =>
|
|
38
|
-
{
|
|
39
|
-
runner.test("with undefined bytes", (test: Test) =>
|
|
40
|
-
{
|
|
41
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
42
|
-
test.assertThrows(() => stream.writeBytes(undefined!), new PreConditionError(
|
|
43
|
-
"Expression: bytes",
|
|
44
|
-
"Expected: not undefined and not null",
|
|
45
|
-
"Actual: undefined",
|
|
46
|
-
));
|
|
47
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
runner.test("with null bytes", (test: Test) =>
|
|
51
|
-
{
|
|
52
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
53
|
-
test.assertThrows(() => stream.writeBytes(null!), new PreConditionError(
|
|
54
|
-
"Expression: bytes",
|
|
55
|
-
"Expected: not undefined and not null",
|
|
56
|
-
"Actual: null",
|
|
57
|
-
));
|
|
58
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
runner.test("with empty bytes", (test: Test) =>
|
|
62
|
-
{
|
|
63
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
64
|
-
test.assertEqual(0, stream.writeBytes([]).await());
|
|
65
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
runner.test("with non-empty bytes", (test: Test) =>
|
|
69
|
-
{
|
|
70
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
71
|
-
|
|
72
|
-
test.assertEqual(4, stream.writeBytes([1, 2, 3, 4]).await());
|
|
73
|
-
test.assertEqual(4, stream.getAvailableByteCount());
|
|
74
|
-
|
|
75
|
-
const bytes: Uint8Array = stream.readBytes(10).await();
|
|
76
|
-
test.assertNotUndefinedAndNotNull(bytes);
|
|
77
|
-
test.assertEqual(4, bytes.length);
|
|
78
|
-
test.assertEqual(new Uint8Array([1, 2, 3, 4]), bytes);
|
|
79
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
runner.test("with negative startIndex", (test: Test) =>
|
|
83
|
-
{
|
|
84
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
85
|
-
test.assertThrows(() => stream.writeBytes([1, 2], -1), new PreConditionError(
|
|
86
|
-
"Expression: startIndex",
|
|
87
|
-
"Expected: between 0 and 2",
|
|
88
|
-
"Actual: -1",
|
|
89
|
-
));
|
|
90
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
runner.test("with too large startIndex", (test: Test) =>
|
|
94
|
-
{
|
|
95
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
96
|
-
test.assertThrows(() => stream.writeBytes([1, 2], 3), new PreConditionError(
|
|
97
|
-
"Expression: startIndex",
|
|
98
|
-
"Expected: between 0 and 2",
|
|
99
|
-
"Actual: 3",
|
|
100
|
-
));
|
|
101
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
runner.test("with valid non-zero startIndex", (test: Test) =>
|
|
105
|
-
{
|
|
106
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
107
|
-
const writeBytesResult: number = stream.writeBytes([1, 2], 1).await();
|
|
108
|
-
test.assertEqual(1, writeBytesResult);
|
|
109
|
-
test.assertEqual(1, stream.getAvailableByteCount());
|
|
110
|
-
|
|
111
|
-
test.assertEqual(new Uint8Array([2]), stream.readBytes(5).await());
|
|
112
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
runner.test("with startIndex equal to bytes length", (test: Test) =>
|
|
116
|
-
{
|
|
117
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
118
|
-
const writeBytesResult: number = stream.writeBytes([1, 2], 2).await();
|
|
119
|
-
test.assertEqual(0, writeBytesResult);
|
|
120
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
runner.test("with negative length", (test: Test) =>
|
|
124
|
-
{
|
|
125
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
126
|
-
test.assertThrows(() => stream.writeBytes([1, 2], 0, -1), new PreConditionError(
|
|
127
|
-
"Expression: length",
|
|
128
|
-
"Expected: between 0 and 2",
|
|
129
|
-
"Actual: -1",
|
|
130
|
-
));
|
|
131
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
runner.test("with too large length", (test: Test) =>
|
|
135
|
-
{
|
|
136
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
137
|
-
test.assertThrows(() => stream.writeBytes([1, 2], 0, 3), new PreConditionError(
|
|
138
|
-
"Expression: length",
|
|
139
|
-
"Expected: between 0 and 2",
|
|
140
|
-
"Actual: 3",
|
|
141
|
-
));
|
|
142
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
runner.test("with valid startIndex and length values", (test: Test) =>
|
|
146
|
-
{
|
|
147
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
148
|
-
const writeBytesResult: number = stream.writeBytes([1, 2, 3, 4, 5], 2, 2).await();
|
|
149
|
-
test.assertEqual(2, writeBytesResult);
|
|
150
|
-
test.assertEqual(2, stream.getAvailableByteCount());
|
|
151
|
-
|
|
152
|
-
test.assertEqual(new Uint8Array([3, 4]), stream.readBytes(50).await());
|
|
153
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
runner.testFunction("readBytes()", () =>
|
|
158
|
-
{
|
|
159
|
-
runner.testGroup("with empty stream", () =>
|
|
160
|
-
{
|
|
161
|
-
runner.test("with negative count", (test: Test) =>
|
|
162
|
-
{
|
|
163
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
164
|
-
test.assertThrows(() => stream.readBytes(-1).await(), new PreConditionError(
|
|
165
|
-
"Expression: count",
|
|
166
|
-
"Expected: greater than or equal to 0",
|
|
167
|
-
"Actual: -1",
|
|
168
|
-
));
|
|
169
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
runner.test("with zero count", (test: Test) =>
|
|
173
|
-
{
|
|
174
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
175
|
-
test.assertThrows(() => stream.readBytes(0).await(), new EmptyError());
|
|
176
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
runner.test("with positive count", (test: Test) =>
|
|
180
|
-
{
|
|
181
|
-
const stream: ByteListStream = ByteListStream.create();
|
|
182
|
-
test.assertThrows(() => stream.readBytes(1).await(), new EmptyError());
|
|
183
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
runner.testGroup("with non-empty stream", () =>
|
|
188
|
-
{
|
|
189
|
-
runner.test("with negative count", (test: Test) =>
|
|
190
|
-
{
|
|
191
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
192
|
-
test.assertThrows(() => stream.readBytes(-1).await(), new PreConditionError(
|
|
193
|
-
"Expression: count",
|
|
194
|
-
"Expected: greater than or equal to 0",
|
|
195
|
-
"Actual: -1",
|
|
196
|
-
));
|
|
197
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
runner.test("with zero count", (test: Test) =>
|
|
201
|
-
{
|
|
202
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
203
|
-
const readBytesResult: Uint8Array = stream.readBytes(0).await();
|
|
204
|
-
test.assertEqual(new Uint8Array(), readBytesResult);
|
|
205
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
runner.test("with positive count less than bytes available", (test: Test) =>
|
|
209
|
-
{
|
|
210
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
211
|
-
const readBytesResult: Uint8Array = stream.readBytes(2).await();
|
|
212
|
-
test.assertEqual(new Uint8Array([1, 2]), readBytesResult);
|
|
213
|
-
test.assertEqual(1, stream.getAvailableByteCount());
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
runner.test("with positive count equal to bytes available", (test: Test) =>
|
|
217
|
-
{
|
|
218
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
219
|
-
const readBytesResult: Uint8Array = stream.readBytes(3).await();
|
|
220
|
-
test.assertEqual(new Uint8Array([1, 2, 3]), readBytesResult);
|
|
221
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
runner.test("with positive count greater than bytes available", (test: Test) =>
|
|
225
|
-
{
|
|
226
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
227
|
-
const readBytesResult: Uint8Array = stream.readBytes(4).await();
|
|
228
|
-
test.assertEqual(new Uint8Array([1, 2, 3]), readBytesResult);
|
|
229
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
runner.test("with undefined output", (test: Test) =>
|
|
233
|
-
{
|
|
234
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
235
|
-
test.assertThrows(() => stream.readBytes(undefined!), new PreConditionError(
|
|
236
|
-
"Expression: output",
|
|
237
|
-
"Expected: not undefined and not null",
|
|
238
|
-
"Actual: undefined",
|
|
239
|
-
));
|
|
240
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
runner.test("with null output", (test: Test) =>
|
|
244
|
-
{
|
|
245
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
246
|
-
test.assertThrows(() => stream.readBytes(null!), new PreConditionError(
|
|
247
|
-
"Expression: output",
|
|
248
|
-
"Expected: not undefined and not null",
|
|
249
|
-
"Actual: null",
|
|
250
|
-
));
|
|
251
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
runner.test("with empty output", (test: Test) =>
|
|
255
|
-
{
|
|
256
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
257
|
-
const output: Uint8Array = new Uint8Array();
|
|
258
|
-
const readBytesResult: number = stream.readBytes(output).await();
|
|
259
|
-
test.assertEqual(0, readBytesResult);
|
|
260
|
-
test.assertEqual(output, new Uint8Array());
|
|
261
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
runner.test("with output smaller than the available bytes", (test: Test) =>
|
|
265
|
-
{
|
|
266
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
267
|
-
const output: Uint8Array = new Uint8Array(1);
|
|
268
|
-
const readBytesResult: number = stream.readBytes(output).await();
|
|
269
|
-
test.assertEqual(1, readBytesResult);
|
|
270
|
-
test.assertEqual(output, new Uint8Array([1]));
|
|
271
|
-
test.assertEqual(2, stream.getAvailableByteCount());
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
runner.test("with output equal to the available bytes", (test: Test) =>
|
|
275
|
-
{
|
|
276
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
277
|
-
const output: Uint8Array = new Uint8Array(3);
|
|
278
|
-
const readBytesResult: number = stream.readBytes(output).await();
|
|
279
|
-
test.assertEqual(3, readBytesResult);
|
|
280
|
-
test.assertEqual(output, new Uint8Array([1, 2, 3]));
|
|
281
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
runner.test("with output larger than available bytes", (test: Test) =>
|
|
285
|
-
{
|
|
286
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
287
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
288
|
-
const readBytesResult: number = stream.readBytes(output).await();
|
|
289
|
-
test.assertEqual(3, readBytesResult);
|
|
290
|
-
test.assertEqual(output, new Uint8Array([1, 2, 3, 0, 0]));
|
|
291
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
runner.test("with negative startIndex", (test: Test) =>
|
|
295
|
-
{
|
|
296
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
297
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
298
|
-
test.assertThrows(() => stream.readBytes(output, -1), new PreConditionError(
|
|
299
|
-
"Expression: startIndex",
|
|
300
|
-
"Expected: between 0 and 5",
|
|
301
|
-
"Actual: -1",
|
|
302
|
-
));
|
|
303
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
runner.test("with too large startIndex", (test: Test) =>
|
|
307
|
-
{
|
|
308
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
309
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
310
|
-
test.assertThrows(() => stream.readBytes(output, 6), new PreConditionError(
|
|
311
|
-
"Expression: startIndex",
|
|
312
|
-
"Expected: between 0 and 5",
|
|
313
|
-
"Actual: 6",
|
|
314
|
-
));
|
|
315
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
runner.test("with startIndex with enough space to read the entire stream", (test: Test) =>
|
|
319
|
-
{
|
|
320
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
321
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
322
|
-
test.assertEqual(3, stream.readBytes(output, 2).await());
|
|
323
|
-
test.assertEqual(new Uint8Array([0, 0, 1, 2, 3]), output);
|
|
324
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
runner.test("with startIndex with not enough space to read the entire stream", (test: Test) =>
|
|
328
|
-
{
|
|
329
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
330
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
331
|
-
test.assertEqual(2, stream.readBytes(output, 3).await());
|
|
332
|
-
test.assertEqual(new Uint8Array([0, 0, 0, 1, 2]), output);
|
|
333
|
-
test.assertEqual(1, stream.getAvailableByteCount());
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
runner.test("with startIndex equal to output length", (test: Test) =>
|
|
337
|
-
{
|
|
338
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
339
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
340
|
-
test.assertEqual(0, stream.readBytes(output, 5).await());
|
|
341
|
-
test.assertEqual(new Uint8Array(5), output);
|
|
342
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
runner.test("with negative count", (test: Test) =>
|
|
346
|
-
{
|
|
347
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
348
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
349
|
-
test.assertThrows(() => stream.readBytes(output, 1, -1), new PreConditionError(
|
|
350
|
-
"Expression: count",
|
|
351
|
-
"Expected: between 0 and 4",
|
|
352
|
-
"Actual: -1",
|
|
353
|
-
));
|
|
354
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
runner.test("with count larger than output.length - startIndex", (test: Test) =>
|
|
358
|
-
{
|
|
359
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
360
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
361
|
-
test.assertThrows(() => stream.readBytes(output, 1, 5), new PreConditionError(
|
|
362
|
-
"Expression: count",
|
|
363
|
-
"Expected: between 0 and 4",
|
|
364
|
-
"Actual: 5",
|
|
365
|
-
));
|
|
366
|
-
test.assertEqual(3, stream.getAvailableByteCount());
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
runner.test("with startIndex with enough space to read the entire stream", (test: Test) =>
|
|
370
|
-
{
|
|
371
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
372
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
373
|
-
test.assertEqual(3, stream.readBytes(output, 2, 3).await());
|
|
374
|
-
test.assertEqual(new Uint8Array([0, 0, 1, 2, 3]), output);
|
|
375
|
-
test.assertEqual(0, stream.getAvailableByteCount());
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
runner.test("with startIndex with not enough space to read the entire stream", (test: Test) =>
|
|
379
|
-
{
|
|
380
|
-
const stream: ByteListStream = ByteListStream.create([1, 2, 3]);
|
|
381
|
-
const output: Uint8Array = new Uint8Array(5);
|
|
382
|
-
test.assertEqual(1, stream.readBytes(output, 3, 1).await());
|
|
383
|
-
test.assertEqual(new Uint8Array([0, 0, 0, 1, 0]), output);
|
|
384
|
-
test.assertEqual(2, stream.getAvailableByteCount());
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
}
|
package/tests/byteListTests.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ByteList } from "../sources/byteList";
|
|
2
|
-
import { EqualFunctions } from "../sources/equalFunctions";
|
|
3
|
-
import { NotFoundError } from "../sources/notFoundError";
|
|
4
|
-
import { PreConditionError } from "../sources/preConditionError";
|
|
5
|
-
import { isNumber } from "../sources/types";
|
|
6
|
-
import { Test } from "./test";
|
|
7
|
-
import { TestRunner } from "./testRunner";
|
|
8
|
-
|
|
9
|
-
export function test(runner: TestRunner): void
|
|
10
|
-
{
|
|
11
|
-
runner.testFile("byteList.ts", () =>
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
}
|