@everyonesoftware/common 2.0.0 → 3.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/.github/workflows/publish.yml +54 -36
- package/package.json +6 -2
- package/sources/asyncIterator.ts +436 -436
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
- package/sources/asyncResult.ts +95 -95
- package/sources/byteList.ts +201 -201
- package/sources/byteListStream.ts +120 -120
- package/sources/byteReadStream.ts +23 -23
- package/sources/byteWriteStream.ts +15 -15
- package/sources/characterList.ts +194 -194
- package/sources/characterListStream.ts +150 -150
- package/sources/characterReadStream.ts +80 -80
- package/sources/characterReadStreamIterator.ts +127 -127
- package/sources/concatenateIterable.ts +118 -118
- package/sources/concatenateIterator.ts +164 -164
- package/sources/currentProcess.ts +157 -157
- package/sources/dateTime.ts +129 -129
- package/sources/depthFirstSearch.ts +229 -229
- package/sources/flatMapIterable.ts +103 -103
- package/sources/flatMapIterator.ts +151 -151
- package/sources/generator.ts +250 -250
- package/sources/index.ts +1 -1
- package/sources/iterator.ts +480 -480
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
- package/sources/javascriptSetSet.ts +133 -133
- package/sources/listQueue.ts +61 -61
- package/sources/listStack.ts +61 -61
- package/sources/luxonDateTime.ts +108 -108
- package/sources/mapAsyncIterator.ts +140 -140
- package/sources/mutableMap.ts +291 -291
- package/sources/node.ts +36 -36
- package/sources/promiseAsyncResult.ts +173 -173
- package/sources/queue.ts +48 -48
- package/sources/recreationDotGovClient.ts +258 -258
- package/sources/searchControl.ts +41 -41
- package/sources/set.ts +243 -243
- package/sources/skipAsyncIterator.ts +144 -144
- package/sources/stack.ts +47 -47
- package/sources/syncResult.ts +299 -299
- package/sources/takeAsyncIterator.ts +140 -140
- package/sources/whereAsyncIterator.ts +142 -142
- package/sources/wonderlandTrailClient.ts +1502 -1502
- package/tests/assertTestTests.ts +74 -74
- package/tests/byteListStreamTests.ts +389 -389
- package/tests/byteListTests.ts +26 -26
- package/tests/characterListStreamTests.ts +390 -390
- package/tests/characterListTests.ts +249 -249
- package/tests/dateTimeTests.ts +29 -29
- package/tests/depthFirstSearchTests.ts +105 -105
- package/tests/generatorTests.ts +85 -85
- package/tests/mutableMapTests.ts +153 -153
- package/tests/promiseAsyncResultTests.ts +687 -687
- package/tests/queueTests.ts +28 -28
- package/tests/recreationDotGovClientTests.ts +190 -190
- package/tests/setTests.ts +139 -139
- package/tests/stackTests.ts +65 -65
- package/tests/syncResultTests.ts +1250 -1250
- package/tests/wonderlandTrailClientTests.ts +451 -451
- package/tsup.config.ts +12 -12
package/tests/mutableMapTests.ts
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import { Iterator } from "../sources/iterator";
|
|
2
|
-
import { JavascriptIterable } from "../sources/javascript";
|
|
3
|
-
import { isMap } from "../sources/map";
|
|
4
|
-
import { MutableMap } from "../sources/mutableMap";
|
|
5
|
-
import { NotFoundError } from "../sources/notFoundError";
|
|
6
|
-
import { mapTests } from "./mapTests";
|
|
7
|
-
import { Test } from "./test";
|
|
8
|
-
import { TestRunner } from "./testRunner";
|
|
9
|
-
|
|
10
|
-
export function test(runner: TestRunner): void
|
|
11
|
-
{
|
|
12
|
-
runner.testFile("mutableMap.ts", () =>
|
|
13
|
-
{
|
|
14
|
-
runner.testType("MutableMap<TKey,TValue>", () =>
|
|
15
|
-
{
|
|
16
|
-
runner.testFunction("create()", (test: Test) =>
|
|
17
|
-
{
|
|
18
|
-
const map: MutableMap<number,string> = MutableMap.create();
|
|
19
|
-
test.assertSame(map.getCount().await(), 0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
mutableMapTests(runner, MutableMap.create);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function mutableMapTests(runner: TestRunner, creator: () => MutableMap<number,string>): void
|
|
28
|
-
{
|
|
29
|
-
runner.testType("MutableMap<TKey,TValue>", () =>
|
|
30
|
-
{
|
|
31
|
-
mapTests(runner, creator);
|
|
32
|
-
|
|
33
|
-
runner.testFunction("creator()", (test: Test) =>
|
|
34
|
-
{
|
|
35
|
-
test.assertNotUndefinedAndNotNull(creator);
|
|
36
|
-
|
|
37
|
-
const map: MutableMap<number,string> = creator();
|
|
38
|
-
test.assertNotUndefinedAndNotNull(map);
|
|
39
|
-
test.assertEqual(map.getCount().await(), 0);
|
|
40
|
-
test.assertTrue(isMap(map));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
runner.testFunction("containsKey(TKey)", () =>
|
|
44
|
-
{
|
|
45
|
-
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
46
|
-
{
|
|
47
|
-
const map: MutableMap<number,string> = creator();
|
|
48
|
-
|
|
49
|
-
test.assertFalse(map.containsKey(50).await());
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
runner.test("when it contains the key", (test: Test) =>
|
|
53
|
-
{
|
|
54
|
-
const map: MutableMap<number,string> = creator().set(50, "fifty");
|
|
55
|
-
|
|
56
|
-
test.assertTrue(map.containsKey(50).await());
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
runner.testFunction("get(TKey)", () =>
|
|
61
|
-
{
|
|
62
|
-
runner.test("when it contains the key", (test: Test) =>
|
|
63
|
-
{
|
|
64
|
-
const map: MutableMap<number,string> = creator().set(1, "one");
|
|
65
|
-
test.assertEqual(map.getCount().await(), 1);
|
|
66
|
-
test.assertEqual(map.get(1).await(), "one");
|
|
67
|
-
test.assertEqual(map.getCount().await(), 1);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
71
|
-
{
|
|
72
|
-
const map: MutableMap<number,string> = creator();
|
|
73
|
-
|
|
74
|
-
test.assertThrows(() => map.get(1).await(),
|
|
75
|
-
new NotFoundError(
|
|
76
|
-
"The key 1 was not found in the map."));
|
|
77
|
-
test.assertEqual(map.getCount().await(), 0);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
runner.testFunction("set(TKey,TValue)", () =>
|
|
82
|
-
{
|
|
83
|
-
function setTest(map: MutableMap<number,string>, key: number, value: string): void
|
|
84
|
-
{
|
|
85
|
-
runner.test(`with ${runner.andList([map, key, value])}`, (test: Test) =>
|
|
86
|
-
{
|
|
87
|
-
const setResult: MutableMap<number,string> = map.set(key, value);
|
|
88
|
-
test.assertSame(setResult, map);
|
|
89
|
-
test.assertSame(map.get(key).await(), value);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
setTest(creator(), 0, "zero");
|
|
94
|
-
setTest(creator(), 1, "1");
|
|
95
|
-
setTest(creator(), -1, "negative one");
|
|
96
|
-
|
|
97
|
-
setTest(creator(), undefined!, "hello");
|
|
98
|
-
setTest(creator(), null!, "oops");
|
|
99
|
-
setTest(creator(), 10, undefined!);
|
|
100
|
-
setTest(creator(), 11, null!);
|
|
101
|
-
|
|
102
|
-
setTest(creator().set(1, "1"), 1, "one");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
runner.testFunction("toString()", () =>
|
|
106
|
-
{
|
|
107
|
-
function toStringTest(map: MutableMap<number,string>, expected: string): void
|
|
108
|
-
{
|
|
109
|
-
runner.test(`with ${runner.toString(map)}`, (test: Test) =>
|
|
110
|
-
{
|
|
111
|
-
test.assertEqual(map.toString(), expected);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
toStringTest(creator(), "{}");
|
|
116
|
-
toStringTest(creator().set(1, "one"), `{1:"one"}`);
|
|
117
|
-
toStringTest(creator().set(2, "2").set(1, "one"), `{2:"2",1:"one"}`);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
runner.testFunction("iterateKeys()", () =>
|
|
121
|
-
{
|
|
122
|
-
function iterateKeysTests(map: MutableMap<number,string>, expected: JavascriptIterable<number>): void
|
|
123
|
-
{
|
|
124
|
-
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
125
|
-
{
|
|
126
|
-
const keyIterator: Iterator<number> = map.iterateKeys();
|
|
127
|
-
test.assertEqual(await keyIterator.toArray(), [...expected]);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
iterateKeysTests(creator(), []);
|
|
132
|
-
iterateKeysTests(creator().set(5, "five"), [5]);
|
|
133
|
-
iterateKeysTests(creator().set(5, "five").set(6, "six"), [5, 6]);
|
|
134
|
-
iterateKeysTests(creator().set(5, "5").set(6, "6").set(7, "7"), [5, 6, 7]);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
runner.testFunction("iterateValues()", () =>
|
|
138
|
-
{
|
|
139
|
-
function iterateValuesTests(map: MutableMap<number,string>, expected: JavascriptIterable<string>): void
|
|
140
|
-
{
|
|
141
|
-
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
142
|
-
{
|
|
143
|
-
const valueIterator: Iterator<string> = map.iterateValues();
|
|
144
|
-
test.assertEqual(await valueIterator.toArray(), [...expected]);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
iterateValuesTests(creator(), []);
|
|
149
|
-
iterateValuesTests(creator().set(5, "five"), ["five"]);
|
|
150
|
-
iterateValuesTests(creator().set(5, "five").set(6, "six"), ["five", "six"]);
|
|
151
|
-
iterateValuesTests(creator().set(5, "5").set(6, "6").set(7, "7"), ["5", "6", "7"]);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
1
|
+
import { Iterator } from "../sources/iterator";
|
|
2
|
+
import { JavascriptIterable } from "../sources/javascript";
|
|
3
|
+
import { isMap } from "../sources/map";
|
|
4
|
+
import { MutableMap } from "../sources/mutableMap";
|
|
5
|
+
import { NotFoundError } from "../sources/notFoundError";
|
|
6
|
+
import { mapTests } from "./mapTests";
|
|
7
|
+
import { Test } from "./test";
|
|
8
|
+
import { TestRunner } from "./testRunner";
|
|
9
|
+
|
|
10
|
+
export function test(runner: TestRunner): void
|
|
11
|
+
{
|
|
12
|
+
runner.testFile("mutableMap.ts", () =>
|
|
13
|
+
{
|
|
14
|
+
runner.testType("MutableMap<TKey,TValue>", () =>
|
|
15
|
+
{
|
|
16
|
+
runner.testFunction("create()", (test: Test) =>
|
|
17
|
+
{
|
|
18
|
+
const map: MutableMap<number,string> = MutableMap.create();
|
|
19
|
+
test.assertSame(map.getCount().await(), 0);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
mutableMapTests(runner, MutableMap.create);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function mutableMapTests(runner: TestRunner, creator: () => MutableMap<number,string>): void
|
|
28
|
+
{
|
|
29
|
+
runner.testType("MutableMap<TKey,TValue>", () =>
|
|
30
|
+
{
|
|
31
|
+
mapTests(runner, creator);
|
|
32
|
+
|
|
33
|
+
runner.testFunction("creator()", (test: Test) =>
|
|
34
|
+
{
|
|
35
|
+
test.assertNotUndefinedAndNotNull(creator);
|
|
36
|
+
|
|
37
|
+
const map: MutableMap<number,string> = creator();
|
|
38
|
+
test.assertNotUndefinedAndNotNull(map);
|
|
39
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
40
|
+
test.assertTrue(isMap(map));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
runner.testFunction("containsKey(TKey)", () =>
|
|
44
|
+
{
|
|
45
|
+
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
46
|
+
{
|
|
47
|
+
const map: MutableMap<number,string> = creator();
|
|
48
|
+
|
|
49
|
+
test.assertFalse(map.containsKey(50).await());
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
runner.test("when it contains the key", (test: Test) =>
|
|
53
|
+
{
|
|
54
|
+
const map: MutableMap<number,string> = creator().set(50, "fifty");
|
|
55
|
+
|
|
56
|
+
test.assertTrue(map.containsKey(50).await());
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
runner.testFunction("get(TKey)", () =>
|
|
61
|
+
{
|
|
62
|
+
runner.test("when it contains the key", (test: Test) =>
|
|
63
|
+
{
|
|
64
|
+
const map: MutableMap<number,string> = creator().set(1, "one");
|
|
65
|
+
test.assertEqual(map.getCount().await(), 1);
|
|
66
|
+
test.assertEqual(map.get(1).await(), "one");
|
|
67
|
+
test.assertEqual(map.getCount().await(), 1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
71
|
+
{
|
|
72
|
+
const map: MutableMap<number,string> = creator();
|
|
73
|
+
|
|
74
|
+
test.assertThrows(() => map.get(1).await(),
|
|
75
|
+
new NotFoundError(
|
|
76
|
+
"The key 1 was not found in the map."));
|
|
77
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
runner.testFunction("set(TKey,TValue)", () =>
|
|
82
|
+
{
|
|
83
|
+
function setTest(map: MutableMap<number,string>, key: number, value: string): void
|
|
84
|
+
{
|
|
85
|
+
runner.test(`with ${runner.andList([map, key, value])}`, (test: Test) =>
|
|
86
|
+
{
|
|
87
|
+
const setResult: MutableMap<number,string> = map.set(key, value);
|
|
88
|
+
test.assertSame(setResult, map);
|
|
89
|
+
test.assertSame(map.get(key).await(), value);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setTest(creator(), 0, "zero");
|
|
94
|
+
setTest(creator(), 1, "1");
|
|
95
|
+
setTest(creator(), -1, "negative one");
|
|
96
|
+
|
|
97
|
+
setTest(creator(), undefined!, "hello");
|
|
98
|
+
setTest(creator(), null!, "oops");
|
|
99
|
+
setTest(creator(), 10, undefined!);
|
|
100
|
+
setTest(creator(), 11, null!);
|
|
101
|
+
|
|
102
|
+
setTest(creator().set(1, "1"), 1, "one");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
runner.testFunction("toString()", () =>
|
|
106
|
+
{
|
|
107
|
+
function toStringTest(map: MutableMap<number,string>, expected: string): void
|
|
108
|
+
{
|
|
109
|
+
runner.test(`with ${runner.toString(map)}`, (test: Test) =>
|
|
110
|
+
{
|
|
111
|
+
test.assertEqual(map.toString(), expected);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
toStringTest(creator(), "{}");
|
|
116
|
+
toStringTest(creator().set(1, "one"), `{1:"one"}`);
|
|
117
|
+
toStringTest(creator().set(2, "2").set(1, "one"), `{2:"2",1:"one"}`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
runner.testFunction("iterateKeys()", () =>
|
|
121
|
+
{
|
|
122
|
+
function iterateKeysTests(map: MutableMap<number,string>, expected: JavascriptIterable<number>): void
|
|
123
|
+
{
|
|
124
|
+
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
125
|
+
{
|
|
126
|
+
const keyIterator: Iterator<number> = map.iterateKeys();
|
|
127
|
+
test.assertEqual(await keyIterator.toArray(), [...expected]);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
iterateKeysTests(creator(), []);
|
|
132
|
+
iterateKeysTests(creator().set(5, "five"), [5]);
|
|
133
|
+
iterateKeysTests(creator().set(5, "five").set(6, "six"), [5, 6]);
|
|
134
|
+
iterateKeysTests(creator().set(5, "5").set(6, "6").set(7, "7"), [5, 6, 7]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
runner.testFunction("iterateValues()", () =>
|
|
138
|
+
{
|
|
139
|
+
function iterateValuesTests(map: MutableMap<number,string>, expected: JavascriptIterable<string>): void
|
|
140
|
+
{
|
|
141
|
+
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
142
|
+
{
|
|
143
|
+
const valueIterator: Iterator<string> = map.iterateValues();
|
|
144
|
+
test.assertEqual(await valueIterator.toArray(), [...expected]);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
iterateValuesTests(creator(), []);
|
|
149
|
+
iterateValuesTests(creator().set(5, "five"), ["five"]);
|
|
150
|
+
iterateValuesTests(creator().set(5, "five").set(6, "six"), ["five", "six"]);
|
|
151
|
+
iterateValuesTests(creator().set(5, "5").set(6, "6").set(7, "7"), ["5", "6", "7"]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
154
|
}
|