risei 1.0.4 → 1.1.1

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 (78) hide show
  1. package/README.md +236 -339
  2. package/index.js +8 -8
  3. package/package.json +23 -9
  4. package/{public/javascript → system}/ASpoofingFixture.js +1 -1
  5. package/{public/javascript → system}/ChosenTestFinder.js +4 -3
  6. package/{public/javascript → system}/SpoofClassMethodsFixture.js +38 -22
  7. package/system/SpoofObjectMethodsFixture.js +58 -0
  8. package/{public/javascript → system}/SpoofTuple.js +14 -1
  9. package/{public/javascript → system}/TerminalReporter.js +249 -222
  10. package/system/TestFrame.js +187 -0
  11. package/system/TestFrameChooser.js +54 -0
  12. package/system/TestFrames.js +232 -0
  13. package/system/TestResult.js +187 -0
  14. package/system/TestRunner.js +280 -0
  15. package/system/TestStages.js +278 -0
  16. package/{public/javascript → system}/TestTuple.js +132 -13
  17. package/{public/javascript → system}/TotalComparer.js +12 -0
  18. package/system/TotalCopier.js +79 -0
  19. package/system/TotalDisplayer.js +143 -0
  20. package/system/TypeAnalyzer.js +103 -0
  21. package/system/TypeIdentifier.js +70 -0
  22. package/system/Types.js +17 -0
  23. package/tests/other-tests/ASpoofingFixture.tests.js +242 -0
  24. package/tests/other-tests/SpoofClassesFixture.tests.js +130 -0
  25. package/tests/other-tests/SpoofObjectsFixture.tests.js +95 -0
  26. package/tests/other-tests/SpoofTuple.tests.js +93 -0
  27. package/tests/other-tests/TotalComparer.tests.js +920 -0
  28. package/tests/other-tests/package.json +7 -0
  29. package/tests/risei-tests/ASpoofingFixtureTests.rt.js +51 -0
  30. package/tests/risei-tests/MomentTests.rt.js +103 -0
  31. package/tests/risei-tests/SpoofTupleTests.rt.js +274 -0
  32. package/tests/risei-tests/TestFrameChooserTests.rt.js +74 -0
  33. package/tests/risei-tests/TestFrameTests.rt.js +84 -0
  34. package/tests/risei-tests/TestStagesTests.rt.js +99 -0
  35. package/tests/risei-tests/TestTupleTests.rt.js +140 -0
  36. package/tests/risei-tests/TotalComparerTests.rt.js +184 -0
  37. package/tests/risei-tests/TotalCopierTests.rt.js +74 -0
  38. package/tests/risei-tests/TotalDisplayerTests.rt.js +186 -0
  39. package/tests/risei-tests/TypeAnalyzerTests.rt.js +29 -0
  40. package/tests/risei-tests/TypeIdentifierTests.rt.js +44 -0
  41. package/tests/self-tests/SelfTests.outward-rt.js +583 -0
  42. package/tests/target-objects/CompositionModel.js +38 -0
  43. package/tests/target-objects/ConditionalThrowModel.js +11 -0
  44. package/tests/target-objects/CountModel.js +46 -0
  45. package/tests/target-objects/DomModel.js +37 -0
  46. package/tests/target-objects/MixedContents.js +33 -0
  47. package/tests/target-objects/MutationModel.js +27 -0
  48. package/tests/target-objects/ObjectCompositionModel.js +34 -0
  49. package/tests/target-objects/PolySpoofableInner.js +30 -0
  50. package/tests/target-objects/PolySpoofableOuter.js +52 -0
  51. package/tests/target-objects/PropertiesModel.js +47 -0
  52. package/tests/target-objects/Returner.js +9 -0
  53. package/tests/target-objects/SearchModel.js +25 -0
  54. package/tests/target-objects/SortModel.js +91 -0
  55. package/tests/target-objects/SpoofCaller.js +24 -0
  56. package/tests/target-objects/Spoofable.js +36 -0
  57. package/tests/target-objects/SpoofableArgsCaller.js +33 -0
  58. package/tests/target-objects/StateModel.js +34 -0
  59. package/tests/target-objects/StaticModel.js +17 -0
  60. package/tests/target-objects/TestableModel.js +47 -0
  61. package/tests/topic-tests/TopicTests.outward-rt.js +354 -0
  62. package/public/javascript/SpoofObjectMethodsFixture.js +0 -52
  63. package/public/javascript/TestResult.js +0 -338
  64. package/public/javascript/TestRunner.js +0 -476
  65. /package/{public/javascript → system}/AComparer.js +0 -0
  66. /package/{public/javascript → system}/ATestCaller.js +0 -0
  67. /package/{public/javascript → system}/ATestFinder.js +0 -0
  68. /package/{public/javascript → system}/ATestFixture.js +0 -0
  69. /package/{public/javascript → system}/ATestReporter.js +0 -0
  70. /package/{public/javascript → system}/ATestSource.js +0 -0
  71. /package/{public/javascript → system}/ClassTestGroup.js +0 -0
  72. /package/{public/javascript → system}/LocalCaller.js +0 -0
  73. /package/{public/javascript → system}/MethodTestGroup.js +0 -0
  74. /package/{public/javascript → system}/Moment.js +0 -0
  75. /package/{public/javascript → system}/Risei.js +0 -0
  76. /package/{public/javascript → system}/TestFinder.js +0 -0
  77. /package/{public/javascript → system}/TestGroup.js +0 -0
  78. /package/{public/javascript → system}/TestSummary.js +0 -0
@@ -0,0 +1,54 @@
1
+ /**/
2
+
3
+ export class TestFrameChooser {
4
+ // Used for special test cases.
5
+ constructorName = "constructor";
6
+ staticName = "static";
7
+ throwName = "throw";
8
+
9
+ frames;
10
+
11
+ constructor(frameSource) /* verified */ {
12
+ this.frames = frameSource;
13
+ }
14
+
15
+ supplyTestFrame(test) /* passed */ {
16
+ // If `.and` includes "static", a call of a static member
17
+ // is made, and the actual is its return value.
18
+ if (test.isStaticTest) {
19
+ if (test.isThrowTest) {
20
+ return this.frames.testThrowResultAfterStaticCall;
21
+ }
22
+
23
+ // If .from, a static call is made, then the actual is
24
+ // retrieved from a named code element or custom code.
25
+ if (test.isRetrievalTest) {
26
+ return this.frames.testCodeElementAfterStaticCall;
27
+ }
28
+
29
+ // Otherwise, the return value
30
+ // of the static call is used.
31
+ return this.frames.testReturnValueOfStaticCall;
32
+ }
33
+
34
+ // Constructors are a special case; no second call should
35
+ // be made, and actual must be retrieved from property.
36
+ if (test.isConstructorTest) {
37
+ return this.frames.testCodeElementAfterConstruction;
38
+ }
39
+
40
+ if (test.isThrowTest) {
41
+ return this.frames.testThrowResultAfterCall;
42
+ }
43
+
44
+ // If .from, a call of the target is made, then the actual
45
+ // is retrieved from a named code element or custom code.
46
+ if (test.isRetrievalTest) {
47
+ return this.frames.testCodeElementAfterCall;
48
+ }
49
+
50
+ // The most common case: the target is called,
51
+ // and the actual is its return value.
52
+ return this.frames.testReturnValueOfCall;
53
+ }
54
+ }
@@ -0,0 +1,232 @@
1
+ /**/
2
+
3
+ import { AComparer } from "./AComparer.js";
4
+ import { TotalComparer } from "./TotalComparer.js";
5
+
6
+ export class TestFrames {
7
+ /* &cruft : refactor to merge with same on TestFrameChooser */
8
+ // Used for special test cases.
9
+ constructorName = "constructor";
10
+ staticName = "static";
11
+
12
+ /* &cruft : probably refactor comparing usage */
13
+ /* Each test frame is bound to the calling instance of TestRunner,
14
+ for now at least. TestRunner includes #compare() for now. */
15
+
16
+ #comparer;
17
+
18
+ constructor() {
19
+ // Comparer is inited once for all tests, since compare() is reentrant.
20
+ this.#comparer = new TotalComparer();
21
+ }
22
+
23
+ // The most basic test: whether a call of
24
+ // a method returns the expected value.
25
+ testReturnValueOfCall(test) {
26
+ /* Groundwork. */
27
+ let prototype = test.on.prototype;
28
+ let target = new prototype.constructor(...test.with); // Must use `...`.
29
+
30
+ this.#anyPropertySetting(target, test.settables);
31
+
32
+ /* Exercising the code. */
33
+ test.actual = target[test.of](...test.in); // Must use `...`.
34
+
35
+ /* Comparing. */
36
+ test.didPass = this.#compare(test.out, test.actual);
37
+ }
38
+
39
+ testReturnValueOfStaticCall(test) {
40
+ /* Groundwork. */
41
+ /* No instance is constructed. */
42
+
43
+ let unsettables = this.#anyOriginalPropertyGetting(test.type, test.settables);
44
+ this.#anyPropertySetting(test.type, test.settables);
45
+
46
+ /* Exercising the code. */
47
+ test.actual = test.on[test.of](...test.in); // Must use `...`.
48
+
49
+ this.#anyPropertyUnsetting(test.type, unsettables);
50
+
51
+ /* Comparing. */
52
+ test.didPass = this.#compare(test.out, test.actual);
53
+ }
54
+
55
+ // The second-most basic test: whether a property
56
+ // has the expected value after a method call.
57
+ testCodeElementAfterCall(test) {
58
+ /* Groundwork. */
59
+ let prototype = test.on.prototype;
60
+ let target = new prototype.constructor(...test.with); // Must use `...`.
61
+
62
+ /* Exercising the code. */
63
+ target[test.of](...test.in); // Must use `...`.
64
+
65
+ /* Retrieving. */
66
+ // The `actual` is a property or other code element somewhere.
67
+ test.actual = this.#supplyNonReturnActual(test, target);
68
+
69
+ /* Comparing. */
70
+ test.didPass = this.#compare(test.out, test.actual);
71
+ }
72
+
73
+ testCodeElementAfterStaticCall(test) {
74
+ /* Groundwork. */
75
+ /* No instance is constructed. */
76
+
77
+ /* Exercising the code. */
78
+ test.on[test.of](...test.in); // Must use `...`.
79
+
80
+ /* Retrieving. */
81
+ test.actual = this.#supplyNonReturnActual(test); // No `target` here.
82
+
83
+ /* Comparing. */
84
+ test.didPass = this.#compare(test.out, test.actual);
85
+ }
86
+
87
+ // The third-most basic test: whether a property has
88
+ // the expected value after an object is constructed.
89
+ testCodeElementAfterConstruction(test) {
90
+ /* Groundwork. */
91
+ // For definition consistency, initing with test.in, not test.with.
92
+ let prototype = test.on.prototype;
93
+
94
+ /* Exercising the code. */
95
+ let target = new prototype.constructor(...test.in); // Must use `...`.
96
+
97
+ /* Retrieving. */
98
+ // The `actual` is a property or other code element somewhere.
99
+ test.actual = this.#supplyNonReturnActual(test, target);
100
+
101
+ /* Comparing. */
102
+ test.didPass = this.#compare(test.out, test.actual);
103
+ }
104
+
105
+ testThrowResultAfterCall(test) {
106
+ /* Groundwork. */
107
+ let prototype = test.on.prototype;
108
+ let target = new prototype.constructor(...test.with); // Must use `...`.
109
+
110
+ /* Exercising the code. */
111
+ try {
112
+ target[test.of](...test.in); // Must use `...`.
113
+ }
114
+ /* Retrieving. */
115
+ catch (thrown) {
116
+ test.actual = thrown.message;
117
+ }
118
+
119
+ /* Comparing. */
120
+ test.didPass = this.#compare(test.out, test.actual);
121
+ }
122
+
123
+ testThrowResultAfterStaticCall(test) {
124
+ /* Groundwork. */
125
+ /* No instance is constructed. */
126
+
127
+ /* Exercising the code. */
128
+ try {
129
+ test.on[test.of](...test.in) // Must use `...`.
130
+ }
131
+ catch (thrown) {
132
+ test.actual = thrown.message;
133
+ }
134
+
135
+ /* Comparing. */
136
+ test.didPass = this.#compare(test.out, test.actual);
137
+ }
138
+
139
+ // region Dependencies of test frames
140
+
141
+ #anyOriginalPropertyGetting(target, settables) {
142
+ if (!Array.isArray(settables)) {
143
+ return;
144
+ }
145
+
146
+ let unsettables = [ ];
147
+
148
+ for (let settable of settables) {
149
+ // Not a setter tuple.
150
+ if (!settable.of) {
151
+ continue;
152
+ }
153
+
154
+ // Retaining original.
155
+ let original = target[settable.of];
156
+ let unsettable = { of: settable.of, as: original };
157
+ unsettables.push(unsettable);
158
+ }
159
+
160
+ return unsettables;
161
+ }
162
+
163
+ #anyPropertySetting(target, settables) {
164
+ // No properties to set.
165
+ if (!Array.isArray(settables)) {
166
+ return;
167
+ }
168
+
169
+ for (let settable of settables) {
170
+ // Not a setter tuple.
171
+ if (!settable.of) {
172
+ continue;
173
+ }
174
+
175
+ // Actually setting property.
176
+ target[settable.of] = settable.as;
177
+ }
178
+ }
179
+
180
+ #anyPropertyUnsetting(target, unsettables) {
181
+ // Unsetting is the same as setting,
182
+ // but with tuples of original values.
183
+ return this.#anyPropertySetting(target, unsettables);
184
+ }
185
+
186
+ #compare(expected, actual) {
187
+ return this.#comparer.compare(expected, actual);
188
+ }
189
+
190
+ #supplyNonReturnActual(test, target) {
191
+ // When there is a .from that's a string,
192
+ // the actual is the named target member.
193
+ if (typeof test.from === "string") {
194
+ // Common member host;
195
+ // undefined if static.
196
+ let host = target;
197
+
198
+ // When .and defines static.
199
+ if (this.#doesAddressStatics(test)) {
200
+ host = test.on;
201
+ }
202
+
203
+ return host[test.from];
204
+ }
205
+
206
+ // When there is a .from that's a function,
207
+ // the actual is the result of calling it,
208
+ // given everything that might be needed.
209
+ if (test.from instanceof Function) {
210
+ return test.from(target, test);
211
+ }
212
+
213
+ // When there is any other .from, the actual is the
214
+ // value of the code element provided as .from.
215
+ return test.from;
216
+ }
217
+
218
+ /* &cruft : refactor to merge with same on TestFrameChooser */
219
+ #doesAddressStatics(test) {
220
+ if (typeof test.and === "string") {
221
+ if (test.and.includes(this.staticName)) {
222
+ return true;
223
+ }
224
+ }
225
+
226
+ return false;
227
+ }
228
+
229
+ // endregion Dependencies of test frames
230
+
231
+
232
+ }
@@ -0,0 +1,187 @@
1
+ /**/
2
+
3
+ import { TotalDisplayer } from "./TotalDisplayer.js";
4
+
5
+ export class TestResult {
6
+ // region Components
7
+
8
+ #displayer;
9
+
10
+ // endregion Components
11
+
12
+ // region Fields
13
+
14
+ #test;
15
+
16
+ #identityText;
17
+ #initorsText;
18
+ #inputsText;
19
+ #expectedText;
20
+ #actualText;
21
+
22
+ #didPass;
23
+ #actual;
24
+ #thrown;
25
+
26
+ // endregion Fields
27
+
28
+ // region Source properties
29
+
30
+ get test() {
31
+ return this.#test;
32
+ }
33
+
34
+ set test(value) {
35
+ this.#test = value;
36
+ }
37
+
38
+ // endregion Source properties
39
+
40
+ // region Nature properties
41
+
42
+ get identityText() {
43
+ return this.#identityText;
44
+ }
45
+
46
+ set identityText(value) {
47
+ this.#identityText = value;
48
+ }
49
+
50
+ get initorsText() {
51
+ return this.#initorsText;
52
+ }
53
+
54
+ set initorsText(value) {
55
+ this.#initorsText = value;
56
+ }
57
+
58
+ get inputsText() {
59
+ return this.#inputsText;
60
+ }
61
+
62
+ set inputsText(value) {
63
+ this.#inputsText = value;
64
+ }
65
+
66
+ get expectedText() {
67
+ return this.#expectedText;
68
+ }
69
+
70
+ set expectedText(value) {
71
+ this.#expectedText = value;
72
+ }
73
+
74
+ // endregion Nature properties
75
+
76
+ // region Outcome properties
77
+
78
+ get actualText() {
79
+ return this.#actualText;
80
+ }
81
+
82
+ set actualText(value) {
83
+ this.#actualText = value;
84
+ }
85
+
86
+ get didPass() {
87
+ return this.#didPass;
88
+ }
89
+
90
+ set didPass(value) {
91
+ this.#didPass = value;
92
+ }
93
+
94
+ get anyThrow() {
95
+ return this.#thrown;
96
+ }
97
+
98
+ set anyThrow(value) {
99
+ this.#thrown = value;
100
+ }
101
+
102
+ // endregion Outcome properties
103
+
104
+ // region Construction
105
+
106
+ constructor(test) {
107
+ this.#test = test;
108
+ this.#displayer = new TotalDisplayer();
109
+ }
110
+
111
+ // endregion Construction
112
+
113
+ // region Before run: setNature() and dependencies
114
+
115
+ setNature() {
116
+ this.#identityText = this.#calculateIdentityText();
117
+ this.#initorsText = this.#calculateInitorsText();
118
+ this.#inputsText = this.#calculateInputsText();
119
+ this.#expectedText = this.#calculateExpectedText();
120
+ }
121
+
122
+ #calculateIdentityText() {
123
+ let text = `${ this.test.for } `;
124
+ return text;
125
+ }
126
+
127
+ #calculateInitorsText() {
128
+ let text = this.#displayItemRow(this.test.with);
129
+ text = `Initors: ${ text }. `;
130
+ return text;
131
+ }
132
+
133
+ #calculateInputsText() {
134
+ let text = this.#displayItemRow(this.test.in);
135
+ text = `Inputs: ${ text }. `;
136
+ return text;
137
+ }
138
+
139
+ #calculateExpectedText() {
140
+ let text = this.#displaySingleItem(this.test.out);
141
+ text = `Expected: ${ text }. `;
142
+ return text;
143
+ }
144
+
145
+ // endregion Before run: setNature() and dependencies
146
+
147
+ // region After run: setResults() and dependencies
148
+
149
+ setResults() {
150
+ // Direct results.
151
+ this.#didPass = this.test.didPass;
152
+ this.#actual = this.test.actual;
153
+ this.#thrown = this.test.anyThrow;
154
+
155
+ // Derived displayable results.
156
+ this.#actualText = this.#calculateActualText();
157
+ }
158
+
159
+ #calculateActualText() {
160
+ let text = this.#displaySingleItem(this.test.actual);
161
+ text = `Actual: ${ text }. `;
162
+ return text;
163
+ }
164
+
165
+ // endregion After run: setResults() and dependencies
166
+
167
+ // region Displaying test args
168
+
169
+ #displaySingleItem(item) /* verified */ {
170
+ return this.#displayer.display(item);
171
+ }
172
+
173
+ #displayItemRow(row) /* verified */ {
174
+ let items = row.map(
175
+ x => this.#displayer.display(x)
176
+ );
177
+
178
+ if (items.length === 0) {
179
+ return [ "\u2014" ];
180
+ }
181
+
182
+ return items.join(`, `);
183
+ }
184
+
185
+ // endregion Displaying test args
186
+
187
+ }