@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.
Files changed (163) hide show
  1. package/.c8rc.json +12 -0
  2. package/.github/workflows/publish.yml +38 -0
  3. package/.mocharc.json +9 -0
  4. package/README.md +9 -0
  5. package/package.json +36 -0
  6. package/sources/assertMessageParameters.ts +22 -0
  7. package/sources/asyncIterator.ts +437 -0
  8. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
  9. package/sources/asyncResult.ts +95 -0
  10. package/sources/basicDisposable.ts +57 -0
  11. package/sources/byteList.ts +202 -0
  12. package/sources/byteListStream.ts +121 -0
  13. package/sources/byteReadStream.ts +24 -0
  14. package/sources/byteWriteStream.ts +16 -0
  15. package/sources/bytes.ts +25 -0
  16. package/sources/characterList.ts +195 -0
  17. package/sources/characterListStream.ts +151 -0
  18. package/sources/characterReadStream.ts +81 -0
  19. package/sources/characterReadStreamIterator.ts +128 -0
  20. package/sources/characterWriteStream.ts +45 -0
  21. package/sources/commandLineParameter.ts +45 -0
  22. package/sources/commandLineParameters.ts +21 -0
  23. package/sources/comparable.ts +144 -0
  24. package/sources/comparer.ts +133 -0
  25. package/sources/comparison.ts +20 -0
  26. package/sources/concatenateIterable.ts +119 -0
  27. package/sources/concatenateIterator.ts +165 -0
  28. package/sources/condition.ts +329 -0
  29. package/sources/currentProcess.ts +158 -0
  30. package/sources/dateTime.ts +130 -0
  31. package/sources/depthFirstSearch.ts +230 -0
  32. package/sources/disposable.ts +31 -0
  33. package/sources/emptyError.ts +10 -0
  34. package/sources/english.ts +45 -0
  35. package/sources/equalFunctions.ts +123 -0
  36. package/sources/fetchHttpClient.ts +89 -0
  37. package/sources/fetchHttpResponse.ts +106 -0
  38. package/sources/flatMapIterable.ts +104 -0
  39. package/sources/flatMapIterator.ts +152 -0
  40. package/sources/generator.ts +251 -0
  41. package/sources/httpClient.ts +36 -0
  42. package/sources/httpHeader.ts +37 -0
  43. package/sources/httpHeaders.ts +216 -0
  44. package/sources/httpIncomingRequest.ts +30 -0
  45. package/sources/httpIncomingResponse.ts +19 -0
  46. package/sources/httpMethod.ts +164 -0
  47. package/sources/httpOutgoingRequest.ts +119 -0
  48. package/sources/httpOutgoingResponse.ts +113 -0
  49. package/sources/httpServer.ts +34 -0
  50. package/sources/inMemoryCharacterWriteStream.ts +78 -0
  51. package/sources/index.ts +101 -0
  52. package/sources/iterable.ts +345 -0
  53. package/sources/iterator.ts +481 -0
  54. package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
  55. package/sources/javascript.ts +59 -0
  56. package/sources/javascriptArrayList.ts +175 -0
  57. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
  58. package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
  59. package/sources/javascriptMapMap.ts +143 -0
  60. package/sources/javascriptSetSet.ts +134 -0
  61. package/sources/list.ts +330 -0
  62. package/sources/listQueue.ts +62 -0
  63. package/sources/listStack.ts +62 -0
  64. package/sources/luxonDateTime.ts +109 -0
  65. package/sources/map.ts +302 -0
  66. package/sources/mapAsyncIterator.ts +141 -0
  67. package/sources/mapIterable.ts +105 -0
  68. package/sources/mapIterator.ts +145 -0
  69. package/sources/mutableCondition.ts +451 -0
  70. package/sources/mutableHttpHeaders.ts +204 -0
  71. package/sources/mutableMap.ts +292 -0
  72. package/sources/network.ts +18 -0
  73. package/sources/node.ts +37 -0
  74. package/sources/nodeJSCharacterWriteStream.ts +42 -0
  75. package/sources/nodeJSHttpIncomingRequest.ts +132 -0
  76. package/sources/nodeJSHttpServer.ts +134 -0
  77. package/sources/notFoundError.ts +12 -0
  78. package/sources/postCondition.ts +284 -0
  79. package/sources/postConditionError.ts +12 -0
  80. package/sources/preCondition.ts +284 -0
  81. package/sources/preConditionError.ts +12 -0
  82. package/sources/promiseAsyncResult.ts +174 -0
  83. package/sources/property.ts +63 -0
  84. package/sources/queue.ts +49 -0
  85. package/sources/realNetwork.ts +28 -0
  86. package/sources/recreationDotGovClient.ts +259 -0
  87. package/sources/searchControl.ts +42 -0
  88. package/sources/set.ts +244 -0
  89. package/sources/skipAsyncIterator.ts +145 -0
  90. package/sources/skipIterator.ts +155 -0
  91. package/sources/stack.ts +48 -0
  92. package/sources/stringComparer.ts +33 -0
  93. package/sources/stringIterator.ts +149 -0
  94. package/sources/strings.ts +322 -0
  95. package/sources/syncResult.ts +300 -0
  96. package/sources/takeAsyncIterator.ts +141 -0
  97. package/sources/takeIterator.ts +151 -0
  98. package/sources/toStringFunctions.ts +185 -0
  99. package/sources/types.ts +371 -0
  100. package/sources/whereAsyncIterator.ts +143 -0
  101. package/sources/whereIterable.ts +108 -0
  102. package/sources/whereIterator.ts +157 -0
  103. package/sources/wonderlandTrailClient.ts +1503 -0
  104. package/tests/assertTest.ts +113 -0
  105. package/tests/assertTestTests.ts +75 -0
  106. package/tests/basicTestSkip.ts +51 -0
  107. package/tests/byteListStreamTests.ts +390 -0
  108. package/tests/byteListTests.ts +27 -0
  109. package/tests/bytesTests.ts +43 -0
  110. package/tests/characterListStreamTests.ts +391 -0
  111. package/tests/characterListTests.ts +250 -0
  112. package/tests/characterWriteStreamTests.ts +12 -0
  113. package/tests/comparerTests.ts +92 -0
  114. package/tests/conditionTests.ts +877 -0
  115. package/tests/consoleTestRunner.ts +404 -0
  116. package/tests/consoleTestRunnerTests.ts +651 -0
  117. package/tests/dateTimeTests.ts +30 -0
  118. package/tests/depthFirstSearchTests.ts +106 -0
  119. package/tests/disposableTests.ts +121 -0
  120. package/tests/englishTests.ts +103 -0
  121. package/tests/equalFunctionsTests.ts +223 -0
  122. package/tests/failedTest.ts +43 -0
  123. package/tests/fetchHttpClientTests.ts +33 -0
  124. package/tests/generatorTests.ts +86 -0
  125. package/tests/httpClientTests.ts +18 -0
  126. package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
  127. package/tests/iterableTests.ts +141 -0
  128. package/tests/iteratorTests.ts +1086 -0
  129. package/tests/javascriptMapMapTests.ts +21 -0
  130. package/tests/listTests.ts +338 -0
  131. package/tests/mapIteratorTests.ts +55 -0
  132. package/tests/mapTests.ts +104 -0
  133. package/tests/mutableConditionTests.ts +273 -0
  134. package/tests/mutableMapTests.ts +154 -0
  135. package/tests/nodeJSHttpServerTests.ts +75 -0
  136. package/tests/notFoundErrorTests.ts +24 -0
  137. package/tests/postConditionErrorTests.ts +24 -0
  138. package/tests/preConditionErrorTests.ts +24 -0
  139. package/tests/promiseAsyncResultTests.ts +688 -0
  140. package/tests/propertyTests.ts +63 -0
  141. package/tests/queueTests.ts +29 -0
  142. package/tests/recreationDotGovClientTests.ts +191 -0
  143. package/tests/setTests.ts +140 -0
  144. package/tests/skippedTest.ts +39 -0
  145. package/tests/stackTests.ts +66 -0
  146. package/tests/stringComparerTests.ts +60 -0
  147. package/tests/stringIteratorTests.ts +156 -0
  148. package/tests/stringsTests.ts +516 -0
  149. package/tests/syncResultTests.ts +1251 -0
  150. package/tests/test.ts +228 -0
  151. package/tests/testAction.ts +75 -0
  152. package/tests/testActionTests.ts +93 -0
  153. package/tests/testFailureTests.ts +12 -0
  154. package/tests/testRunner.ts +267 -0
  155. package/tests/testRunnerTests.ts +895 -0
  156. package/tests/testSkip.ts +34 -0
  157. package/tests/tests.ts +103 -0
  158. package/tests/toStringFunctionsTests.ts +55 -0
  159. package/tests/typesTests.ts +257 -0
  160. package/tests/whereIteratorTests.ts +77 -0
  161. package/tests/wonderlandTrailClientTests.ts +452 -0
  162. package/tsconfig.json +17 -0
  163. package/tsup.config.ts +13 -0
@@ -0,0 +1,156 @@
1
+ import { PreConditionError } from "../sources/preConditionError";
2
+ import { StringIterator } from "../sources/stringIterator";
3
+ import { iteratorTests } from "./iteratorTests";
4
+ import { Test } from "./test";
5
+ import { TestRunner } from "./testRunner";
6
+
7
+ export function test(runner: TestRunner): void
8
+ {
9
+ runner.testFile("stringIterator.ts", () =>
10
+ {
11
+ runner.testType("StringIterator", () =>
12
+ {
13
+ iteratorTests(runner, () => StringIterator.create(""));
14
+
15
+ runner.testFunction("create(string)", () =>
16
+ {
17
+ function createErrorTest(value: string | undefined | null, expectedError: Error): void
18
+ {
19
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
20
+ {
21
+ test.assertThrows(() => StringIterator.create(value!),
22
+ expectedError);
23
+ });
24
+ }
25
+
26
+ createErrorTest(
27
+ undefined,
28
+ new PreConditionError(
29
+ "Expression: value",
30
+ "Expected: not undefined and not null",
31
+ "Actual: undefined",
32
+ ));
33
+ createErrorTest(
34
+ null,
35
+ new PreConditionError(
36
+ "Expression: value",
37
+ "Expected: not undefined and not null",
38
+ "Actual: null",
39
+ ));
40
+
41
+ function createTest(value: string): void
42
+ {
43
+ runner.test(`with "${runner.toString(value)}"`, (test: Test) =>
44
+ {
45
+ const iterator: StringIterator = StringIterator.create(value);
46
+ test.assertFalse(iterator.hasStarted());
47
+ test.assertFalse(iterator.hasCurrent());
48
+ test.assertThrows(() => iterator.getCurrentIndex(),
49
+ new PreConditionError(
50
+ "Expression: this.hasCurrent()",
51
+ "Expected: true",
52
+ "Actual: false",
53
+ ));
54
+ test.assertThrows(() => iterator.getCurrent(),
55
+ new PreConditionError(
56
+ "Expression: this.hasCurrent()",
57
+ "Expected: true",
58
+ "Actual: false",
59
+ ));
60
+ });
61
+ }
62
+
63
+ createTest("");
64
+ createTest("abc");
65
+ });
66
+
67
+ runner.testFunction("next()", () =>
68
+ {
69
+ function nextTest(value: string): void
70
+ {
71
+ runner.test(`with "${runner.toString(value)}"`, async (test: Test) =>
72
+ {
73
+ const iterator: StringIterator = StringIterator.create(value);
74
+
75
+ for (let i = 0; i < value.length; i++)
76
+ {
77
+ test.assertTrue(await iterator.next());
78
+ test.assertTrue(iterator.hasStarted());
79
+ test.assertTrue(iterator.hasCurrent());
80
+ test.assertSame(iterator.getCurrentIndex(), i);
81
+ test.assertSame(iterator.getCurrent(), value[i]);
82
+ }
83
+
84
+ for (let i = 0; i < 2; i++)
85
+ {
86
+ test.assertFalse(await iterator.next());
87
+ test.assertTrue(iterator.hasStarted());
88
+ test.assertFalse(iterator.hasCurrent());
89
+ test.assertThrows(() => iterator.getCurrentIndex(),
90
+ new PreConditionError(
91
+ "Expression: this.hasCurrent()",
92
+ "Expected: true",
93
+ "Actual: false",
94
+ ));
95
+ test.assertThrows(() => iterator.getCurrent(),
96
+ new PreConditionError(
97
+ "Expression: this.hasCurrent()",
98
+ "Expected: true",
99
+ "Actual: false",
100
+ ));
101
+ }
102
+ });
103
+ }
104
+
105
+ nextTest("");
106
+ nextTest("a");
107
+ nextTest("abc");
108
+ });
109
+
110
+ runner.testGroup("for...of", () =>
111
+ {
112
+ function forOfTest(value: string): void
113
+ {
114
+ runner.test(`with "${runner.toString(value)}"`, async (test: Test) =>
115
+ {
116
+ const iterator: StringIterator = StringIterator.create(value);
117
+
118
+ let expectedIndex: number = 0;
119
+ for (const c of iterator)
120
+ {
121
+ test.assertTrue(iterator.hasStarted());
122
+ test.assertTrue(iterator.hasCurrent());
123
+ test.assertSame(iterator.getCurrentIndex(), expectedIndex);
124
+ test.assertSame(iterator.getCurrent(), value[expectedIndex]);
125
+ test.assertSame(c, value[expectedIndex]);
126
+ expectedIndex++;
127
+ }
128
+
129
+ for (let i = 0; i < 2; i++)
130
+ {
131
+ test.assertFalse(await iterator.next());
132
+ test.assertTrue(iterator.hasStarted());
133
+ test.assertFalse(iterator.hasCurrent());
134
+ test.assertThrows(() => iterator.getCurrentIndex(),
135
+ new PreConditionError(
136
+ "Expression: this.hasCurrent()",
137
+ "Expected: true",
138
+ "Actual: false",
139
+ ));
140
+ test.assertThrows(() => iterator.getCurrent(),
141
+ new PreConditionError(
142
+ "Expression: this.hasCurrent()",
143
+ "Expected: true",
144
+ "Actual: false",
145
+ ));
146
+ }
147
+ });
148
+ }
149
+
150
+ forOfTest("");
151
+ forOfTest("a");
152
+ forOfTest("abc");
153
+ });
154
+ });
155
+ });
156
+ }
@@ -0,0 +1,516 @@
1
+ import { PreConditionError } from "../sources/preConditionError";
2
+ import {
3
+ escape, escapeAndQuote, getLength, isDigit, isLetter, isLetterOrDigit, isLowercasedLetter,
4
+ isUppercasedLetter, isWhitespace, join, quote
5
+ } from "../sources/strings";
6
+ import { Test } from "./test";
7
+ import { TestRunner } from "./testRunner";
8
+
9
+ export function test(runner: TestRunner): void
10
+ {
11
+ runner.testFile("strings.ts", () =>
12
+ {
13
+ runner.testFunction("getLength(string | undefined | null)", () =>
14
+ {
15
+ function getLengthTest(value: string | undefined | null, expected: number): void
16
+ {
17
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
18
+ {
19
+ test.assertSame(getLength(value), expected);
20
+ });
21
+ }
22
+
23
+ getLengthTest(undefined, 0);
24
+ getLengthTest(null, 0);
25
+ getLengthTest("", 0);
26
+ getLengthTest("a", 1);
27
+ getLengthTest("abc", 3);
28
+ });
29
+
30
+ runner.testFunction("join(string, string[])", () =>
31
+ {
32
+ function joinErrorTest(separator: string, values: string[], expected: Error): void
33
+ {
34
+ runner.test(`with ${runner.andList([separator, values.map(v => runner.toString(v))])}`, (test: Test) =>
35
+ {
36
+ test.assertThrows(() => join(separator, values), expected);
37
+ });
38
+ }
39
+
40
+ joinErrorTest(undefined!, [],
41
+ new PreConditionError(
42
+ "Expression: separator",
43
+ "Expected: not undefined and not null",
44
+ "Actual: undefined"));
45
+ joinErrorTest(undefined!, ["a"],
46
+ new PreConditionError(
47
+ "Expression: separator",
48
+ "Expected: not undefined and not null",
49
+ "Actual: undefined"));
50
+ joinErrorTest(undefined!, ["a", "b"],
51
+ new PreConditionError(
52
+ "Expression: separator",
53
+ "Expected: not undefined and not null",
54
+ "Actual: undefined"));
55
+ joinErrorTest(undefined!, ["a", "b", "c"],
56
+ new PreConditionError(
57
+ "Expression: separator",
58
+ "Expected: not undefined and not null",
59
+ "Actual: undefined"));
60
+
61
+ joinErrorTest(null!, [],
62
+ new PreConditionError(
63
+ "Expression: separator",
64
+ "Expected: not undefined and not null",
65
+ "Actual: null"));
66
+ joinErrorTest(null!, ["a"],
67
+ new PreConditionError(
68
+ "Expression: separator",
69
+ "Expected: not undefined and not null",
70
+ "Actual: null"));
71
+ joinErrorTest(null!, ["a", "b"],
72
+ new PreConditionError(
73
+ "Expression: separator",
74
+ "Expected: not undefined and not null",
75
+ "Actual: null"));
76
+ joinErrorTest(null!, ["a", "b", "c"],
77
+ new PreConditionError(
78
+ "Expression: separator",
79
+ "Expected: not undefined and not null",
80
+ "Actual: null"));
81
+
82
+ function joinTest(separator: string, values: string[], expected: string): void
83
+ {
84
+ runner.test(`with ${runner.andList([separator, values.map(v => runner.toString(v))])}`, (test: Test) =>
85
+ {
86
+ test.assertSame(join(separator, values), expected);
87
+ });
88
+ }
89
+
90
+
91
+
92
+ joinTest("", [], "");
93
+ joinTest("", ["a"], "a");
94
+ joinTest("", ["a", "b"], "ab");
95
+ joinTest("", ["a", "b", "c"], "abc");
96
+
97
+ joinTest(" ", [], "");
98
+ joinTest(" ", ["a"], "a");
99
+ joinTest(" ", ["a", "b"], "a b");
100
+ joinTest(" ", ["a", "b", "c"], "a b c");
101
+
102
+ joinTest(" _ ", [], "");
103
+ joinTest(" _ ", ["a"], "a");
104
+ joinTest(" _ ", ["a", "b"], "a _ b");
105
+ joinTest(" _ ", ["a", "b", "c"], "a _ b _ c");
106
+ });
107
+
108
+ runner.testFunction("escape(string|undefined|null,string[]|undefined)", () =>
109
+ {
110
+ function escapeTest(value: string | undefined | null, dontEscape: string[] | undefined, expected: string): void
111
+ {
112
+ runner.test(`with ${runner.andList([value, dontEscape?.map((value: string) => runner.toString(value))])}`, (test: Test) =>
113
+ {
114
+ const result: string = escape(value, dontEscape);
115
+ test.assertSame(result, expected);
116
+ });
117
+ }
118
+
119
+ escapeTest(undefined, undefined, "undefined");
120
+ escapeTest(null, undefined, "null");
121
+ escapeTest("", undefined, "");
122
+ escapeTest("a", undefined, "a");
123
+ escapeTest("A", undefined, "A");
124
+ escapeTest("abc", undefined, "abc");
125
+ escapeTest("\t", undefined, "\\t");
126
+ escapeTest("\n", undefined, "\\n");
127
+ escapeTest("\r", undefined, "\\r");
128
+ escapeTest("'", undefined, "\\'");
129
+ escapeTest("\"", undefined, "\\\"");
130
+ escapeTest("&", undefined, "&");
131
+ escapeTest(" \r\n \t ", undefined, " \\r\\n \\t ");
132
+ escapeTest("\t", [], "\\t");
133
+ escapeTest("\t", ["\n"], "\\t");
134
+ escapeTest("\t", ["\t"], "\t");
135
+ });
136
+
137
+ runner.testFunction("quote(string|undefined|null)", () =>
138
+ {
139
+ function quoteTest(value: string | undefined | null, quoteString: string | undefined, expected: string): void
140
+ {
141
+ runner.test(`with ${runner.andList([value, quoteString])}`, (test: Test) =>
142
+ {
143
+ const result: string = quote(value, quoteString);
144
+ test.assertSame(result, expected);
145
+ });
146
+ }
147
+
148
+ quoteTest(undefined, undefined, "undefined");
149
+ quoteTest(null, undefined, "null");
150
+ quoteTest("", undefined, `""`);
151
+ quoteTest("a", undefined, `"a"`);
152
+ quoteTest("A", undefined, `"A"`);
153
+ quoteTest("abc", undefined, `"abc"`);
154
+ quoteTest("abc", "'", `'abc'`);
155
+ });
156
+
157
+ runner.testFunction("escapeAndQuote(string|undefined|null,string|undefined,string[]|undefined)", () =>
158
+ {
159
+ function escapeAndQuoteTest(value: string | undefined | null, quote: string | undefined, dontEscape: string[] | undefined, expected: string): void
160
+ {
161
+ runner.test(`with ${runner.andList([value, quote, dontEscape?.map(x => runner.toString(x))])}`, (test: Test) =>
162
+ {
163
+ const result: string = escapeAndQuote(value, quote, dontEscape);
164
+ test.assertSame(result, expected);
165
+ });
166
+ }
167
+
168
+ escapeAndQuoteTest(undefined, undefined, undefined, "undefined");
169
+ escapeAndQuoteTest(null, undefined, undefined, "null");
170
+ escapeAndQuoteTest("", undefined, undefined, `""`);
171
+ escapeAndQuoteTest("a", undefined, undefined, `"a"`);
172
+ escapeAndQuoteTest("A", undefined, undefined, `"A"`);
173
+ escapeAndQuoteTest("abc", undefined, undefined, `"abc"`);
174
+ escapeAndQuoteTest("\t", undefined, undefined, `"\\t"`);
175
+ escapeAndQuoteTest("\n", undefined, undefined, `"\\n"`);
176
+ escapeAndQuoteTest("\r", undefined, undefined, `"\\r"`);
177
+ escapeAndQuoteTest("'", undefined, undefined, `"\\'"`);
178
+ escapeAndQuoteTest("\"", undefined, undefined, `"\\\""`);
179
+ escapeAndQuoteTest("&", undefined, undefined, `"&"`);
180
+ escapeAndQuoteTest(" \r\n \t ", undefined, undefined, `" \\r\\n \\t "`);
181
+ escapeAndQuoteTest("\t", undefined, [], `"\\t"`);
182
+ escapeAndQuoteTest("\t", undefined, ["\n"], `"\\t"`);
183
+ escapeAndQuoteTest("\t", undefined, ["\t"], `"\t"`);
184
+ });
185
+
186
+ runner.testFunction("isWhitespace(string)", () =>
187
+ {
188
+ function isWhitespaceErrorTest(value: string | undefined | null, expectedError: Error): void
189
+ {
190
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
191
+ {
192
+ test.assertThrows(() => isWhitespace(value!), expectedError);
193
+ });
194
+ }
195
+
196
+ isWhitespaceErrorTest(undefined, new PreConditionError(join("\n", [
197
+ "Expression: value",
198
+ "Expected: not undefined and not null",
199
+ "Actual: undefined",
200
+ ])));
201
+ isWhitespaceErrorTest(null, new PreConditionError(join("\n", [
202
+ "Expression: value",
203
+ "Expected: not undefined and not null",
204
+ "Actual: null",
205
+ ])));
206
+ isWhitespaceErrorTest("", new PreConditionError(join("\n", [
207
+ "Expression: value.length",
208
+ "Expected: 1",
209
+ "Actual: 0",
210
+ ])));
211
+ isWhitespaceErrorTest(" ", new PreConditionError(join("\n", [
212
+ "Expression: value.length",
213
+ "Expected: 1",
214
+ "Actual: 2",
215
+ ])));
216
+
217
+ function isWhitespaceTest(value: string, expected: boolean): void
218
+ {
219
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
220
+ {
221
+ test.assertSame(isWhitespace(value), expected);
222
+ });
223
+ }
224
+
225
+ isWhitespaceTest(" ", true);
226
+ isWhitespaceTest("\n", true);
227
+ isWhitespaceTest("\r", true);
228
+ isWhitespaceTest("\t", true);
229
+
230
+ isWhitespaceTest("a", false);
231
+ isWhitespaceTest("_", false);
232
+ isWhitespaceTest("-", false);
233
+ });
234
+
235
+ runner.testFunction("isLetter(string)", () =>
236
+ {
237
+ function isLetterErrorTest(value: string | undefined | null, expectedError: Error): void
238
+ {
239
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
240
+ {
241
+ test.assertThrows(() => isLetter(value!), expectedError);
242
+ });
243
+ }
244
+
245
+ isLetterErrorTest(undefined, new PreConditionError(join("\n", [
246
+ "Expression: value",
247
+ "Expected: not undefined and not null",
248
+ "Actual: undefined",
249
+ ])));
250
+ isLetterErrorTest(null, new PreConditionError(join("\n", [
251
+ "Expression: value",
252
+ "Expected: not undefined and not null",
253
+ "Actual: null",
254
+ ])));
255
+ isLetterErrorTest("", new PreConditionError(join("\n", [
256
+ "Expression: value.length",
257
+ "Expected: 1",
258
+ "Actual: 0",
259
+ ])));
260
+ isLetterErrorTest(" ", new PreConditionError(join("\n", [
261
+ "Expression: value.length",
262
+ "Expected: 1",
263
+ "Actual: 2",
264
+ ])));
265
+
266
+ function isLetterTest(value: string, expected: boolean): void
267
+ {
268
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
269
+ {
270
+ test.assertSame(isLetter(value), expected);
271
+ });
272
+ }
273
+
274
+ isLetterTest("a", true);
275
+ isLetterTest("m", true);
276
+ isLetterTest("z", true);
277
+ isLetterTest("A", true);
278
+ isLetterTest("N", true);
279
+ isLetterTest("Z", true);
280
+
281
+ isLetterTest(" ", false);
282
+ isLetterTest("\n", false);
283
+ isLetterTest("\r", false);
284
+ isLetterTest("\t", false);
285
+ isLetterTest("_", false);
286
+ isLetterTest("-", false);
287
+ isLetterTest("5", false);
288
+ });
289
+
290
+ runner.testFunction("isLowercasedLetter(string)", () =>
291
+ {
292
+ function isLowercasedLetterErrorTest(value: string | undefined | null, expectedError: Error): void
293
+ {
294
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
295
+ {
296
+ test.assertThrows(() => isLowercasedLetter(value!), expectedError);
297
+ });
298
+ }
299
+
300
+ isLowercasedLetterErrorTest(undefined, new PreConditionError(join("\n", [
301
+ "Expression: value",
302
+ "Expected: not undefined and not null",
303
+ "Actual: undefined",
304
+ ])));
305
+ isLowercasedLetterErrorTest(null, new PreConditionError(join("\n", [
306
+ "Expression: value",
307
+ "Expected: not undefined and not null",
308
+ "Actual: null",
309
+ ])));
310
+ isLowercasedLetterErrorTest("", new PreConditionError(join("\n", [
311
+ "Expression: value.length",
312
+ "Expected: 1",
313
+ "Actual: 0",
314
+ ])));
315
+ isLowercasedLetterErrorTest(" ", new PreConditionError(join("\n", [
316
+ "Expression: value.length",
317
+ "Expected: 1",
318
+ "Actual: 2",
319
+ ])));
320
+
321
+ function isLowercasedLetterTest(value: string, expected: boolean): void
322
+ {
323
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
324
+ {
325
+ test.assertSame(isLowercasedLetter(value), expected);
326
+ });
327
+ }
328
+
329
+ isLowercasedLetterTest("a", true);
330
+ isLowercasedLetterTest("m", true);
331
+ isLowercasedLetterTest("z", true);
332
+
333
+ isLowercasedLetterTest("A", false);
334
+ isLowercasedLetterTest("N", false);
335
+ isLowercasedLetterTest("Z", false);
336
+ isLowercasedLetterTest(" ", false);
337
+ isLowercasedLetterTest("\n", false);
338
+ isLowercasedLetterTest("\r", false);
339
+ isLowercasedLetterTest("\t", false);
340
+ isLowercasedLetterTest("_", false);
341
+ isLowercasedLetterTest("-", false);
342
+ isLowercasedLetterTest("5", false);
343
+ });
344
+
345
+ runner.testFunction("isUppercasedLetter(string)", () =>
346
+ {
347
+ function isUppercasedLetterErrorTest(value: string | undefined | null, expectedError: Error): void
348
+ {
349
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
350
+ {
351
+ test.assertThrows(() => isUppercasedLetter(value!), expectedError);
352
+ });
353
+ }
354
+
355
+ isUppercasedLetterErrorTest(undefined, new PreConditionError(join("\n", [
356
+ "Expression: value",
357
+ "Expected: not undefined and not null",
358
+ "Actual: undefined",
359
+ ])));
360
+ isUppercasedLetterErrorTest(null, new PreConditionError(join("\n", [
361
+ "Expression: value",
362
+ "Expected: not undefined and not null",
363
+ "Actual: null",
364
+ ])));
365
+ isUppercasedLetterErrorTest("", new PreConditionError(join("\n", [
366
+ "Expression: value.length",
367
+ "Expected: 1",
368
+ "Actual: 0",
369
+ ])));
370
+ isUppercasedLetterErrorTest(" ", new PreConditionError(join("\n", [
371
+ "Expression: value.length",
372
+ "Expected: 1",
373
+ "Actual: 2",
374
+ ])));
375
+
376
+ function isUppercasedLetterTest(value: string, expected: boolean): void
377
+ {
378
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
379
+ {
380
+ test.assertSame(isUppercasedLetter(value), expected);
381
+ });
382
+ }
383
+
384
+ isUppercasedLetterTest("A", true);
385
+ isUppercasedLetterTest("N", true);
386
+ isUppercasedLetterTest("Z", true);
387
+
388
+ isUppercasedLetterTest("a", false);
389
+ isUppercasedLetterTest("m", false);
390
+ isUppercasedLetterTest("z", false);
391
+ isUppercasedLetterTest(" ", false);
392
+ isUppercasedLetterTest("\n", false);
393
+ isUppercasedLetterTest("\r", false);
394
+ isUppercasedLetterTest("\t", false);
395
+ isUppercasedLetterTest("_", false);
396
+ isUppercasedLetterTest("-", false);
397
+ isUppercasedLetterTest("5", false);
398
+ });
399
+
400
+ runner.testFunction("isDigit(string)", () =>
401
+ {
402
+ function isDigitErrorTest(value: string | undefined | null, expectedError: Error): void
403
+ {
404
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
405
+ {
406
+ test.assertThrows(() => isDigit(value!), expectedError);
407
+ });
408
+ }
409
+
410
+ isDigitErrorTest(undefined, new PreConditionError(join("\n", [
411
+ "Expression: value",
412
+ "Expected: not undefined and not null",
413
+ "Actual: undefined",
414
+ ])));
415
+ isDigitErrorTest(null, new PreConditionError(join("\n", [
416
+ "Expression: value",
417
+ "Expected: not undefined and not null",
418
+ "Actual: null",
419
+ ])));
420
+ isDigitErrorTest("", new PreConditionError(join("\n", [
421
+ "Expression: value.length",
422
+ "Expected: 1",
423
+ "Actual: 0",
424
+ ])));
425
+ isDigitErrorTest(" ", new PreConditionError(join("\n", [
426
+ "Expression: value.length",
427
+ "Expected: 1",
428
+ "Actual: 2",
429
+ ])));
430
+
431
+ function isDigitTest(value: string, expected: boolean): void
432
+ {
433
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
434
+ {
435
+ test.assertSame(isDigit(value), expected);
436
+ });
437
+ }
438
+
439
+ isDigitTest("0", true);
440
+ isDigitTest("5", true);
441
+ isDigitTest("9", true);
442
+
443
+ isDigitTest(".", false);
444
+ isDigitTest("a", false);
445
+ isDigitTest("m", false);
446
+ isDigitTest("z", false);
447
+ isDigitTest("A", false);
448
+ isDigitTest("N", false);
449
+ isDigitTest("Z", false);
450
+ isDigitTest(" ", false);
451
+ isDigitTest("\n", false);
452
+ isDigitTest("\r", false);
453
+ isDigitTest("\t", false);
454
+ isDigitTest("_", false);
455
+ isDigitTest("-", false);
456
+ });
457
+
458
+ runner.testFunction("isLetterOrDigit(string)", () =>
459
+ {
460
+ function isLetterOrDigitErrorTest(value: string | undefined | null, expectedError: Error): void
461
+ {
462
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
463
+ {
464
+ test.assertThrows(() => isLetterOrDigit(value!), expectedError);
465
+ });
466
+ }
467
+
468
+ isLetterOrDigitErrorTest(undefined, new PreConditionError(join("\n", [
469
+ "Expression: value",
470
+ "Expected: not undefined and not null",
471
+ "Actual: undefined",
472
+ ])));
473
+ isLetterOrDigitErrorTest(null, new PreConditionError(join("\n", [
474
+ "Expression: value",
475
+ "Expected: not undefined and not null",
476
+ "Actual: null",
477
+ ])));
478
+ isLetterOrDigitErrorTest("", new PreConditionError(join("\n", [
479
+ "Expression: value.length",
480
+ "Expected: 1",
481
+ "Actual: 0",
482
+ ])));
483
+ isLetterOrDigitErrorTest("ab", new PreConditionError(join("\n", [
484
+ "Expression: value.length",
485
+ "Expected: 1",
486
+ "Actual: 2",
487
+ ])));
488
+
489
+ function isLetterOrDigitTest(value: string, expected: boolean): void
490
+ {
491
+ runner.test(`with ${runner.toString(value)}`, (test: Test) =>
492
+ {
493
+ test.assertSame(isLetterOrDigit(value), expected);
494
+ });
495
+ }
496
+
497
+ isLetterOrDigitTest("0", true);
498
+ isLetterOrDigitTest("5", true);
499
+ isLetterOrDigitTest("9", true);
500
+ isLetterOrDigitTest("a", true);
501
+ isLetterOrDigitTest("m", true);
502
+ isLetterOrDigitTest("z", true);
503
+ isLetterOrDigitTest("A", true);
504
+ isLetterOrDigitTest("N", true);
505
+ isLetterOrDigitTest("Z", true);
506
+
507
+ isLetterOrDigitTest(".", false);
508
+ isLetterOrDigitTest(" ", false);
509
+ isLetterOrDigitTest("\n", false);
510
+ isLetterOrDigitTest("\r", false);
511
+ isLetterOrDigitTest("\t", false);
512
+ isLetterOrDigitTest("_", false);
513
+ isLetterOrDigitTest("-", false);
514
+ });
515
+ });
516
+ }