script-engine-lib 0.4.3 → 1.0.0-rc1
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/dist/index.d.mts +191 -0
- package/dist/index.d.ts +191 -5
- package/dist/index.js +21 -29
- package/dist/index.mjs +21 -0
- package/package.json +56 -52
- package/src/index.ts +10 -0
- package/dist/decorators/action-before-testing.d.ts +0 -2
- package/dist/decorators/action-before-testing.js +0 -23
- package/dist/decorators/action-before-testing.test.d.ts +0 -1
- package/dist/decorators/action-before-testing.test.js +0 -82
- package/dist/engine/script-engine.d.ts +0 -35
- package/dist/engine/script-engine.js +0 -175
- package/dist/engine/script-engine.test.d.ts +0 -1
- package/dist/engine/script-engine.test.js +0 -1277
- package/dist/engine/story-engine.d.ts +0 -35
- package/dist/engine/story-engine.js +0 -175
- package/dist/engine/story-engine.test.d.ts +0 -1
- package/dist/engine/story-engine.test.js +0 -1277
- package/dist/interfaces.d.ts +0 -51
- package/dist/interfaces.js +0 -27
- package/dist/simulator/decorators.d.ts +0 -2
- package/dist/simulator/decorators.js +0 -23
- package/dist/simulator/decorators.test.d.ts +0 -1
- package/dist/simulator/decorators.test.js +0 -81
- package/dist/simulator/event-branches-map.d.ts +0 -16
- package/dist/simulator/event-branches-map.js +0 -114
- package/dist/simulator/event-branches-map.test.d.ts +0 -1
- package/dist/simulator/event-branches-map.test.js +0 -120
- package/dist/simulator/event-test-simulator.d.ts +0 -42
- package/dist/simulator/event-test-simulator.js +0 -373
- package/dist/simulator/event-test-simulator.test.d.ts +0 -1
- package/dist/simulator/event-test-simulator.test.js +0 -1960
- package/dist/simulator/execution-history.d.ts +0 -6
- package/dist/simulator/execution-history.js +0 -22
- package/dist/simulator/helpers/event-branches-map.d.ts +0 -16
- package/dist/simulator/helpers/event-branches-map.js +0 -114
- package/dist/simulator/helpers/event-branches-map.test.d.ts +0 -1
- package/dist/simulator/helpers/event-branches-map.test.js +0 -120
- package/dist/simulator/helpers/execution-history.d.ts +0 -6
- package/dist/simulator/helpers/execution-history.js +0 -22
- package/dist/simulator/helpers/script-branches-map.d.ts +0 -16
- package/dist/simulator/helpers/script-branches-map.js +0 -114
- package/dist/simulator/helpers/script-branches-map.test.d.ts +0 -1
- package/dist/simulator/helpers/script-branches-map.test.js +0 -120
- package/dist/simulator/script-test-simulator.d.ts +0 -42
- package/dist/simulator/script-test-simulator.js +0 -373
- package/dist/simulator/script-test-simulator.test.d.ts +0 -1
- package/dist/simulator/script-test-simulator.test.js +0 -2013
- package/dist/structured-text/index.d.ts +0 -9
- package/dist/structured-text/index.js +0 -8
- package/dist/structured-text/rich-text-separator.d.ts +0 -48
- package/dist/structured-text/rich-text-separator.js +0 -146
- package/dist/structured-text/rich-text-separator.test.d.ts +0 -1
- package/dist/structured-text/rich-text-separator.test.js +0 -166
- package/dist/structured-text/rich-text-validator.d.ts +0 -19
- package/dist/structured-text/rich-text-validator.js +0 -73
- package/dist/structured-text/rich-text-validator.test.d.ts +0 -1
- package/dist/structured-text/rich-text-validator.test.js +0 -59
- package/dist/test.spec.d.ts +0 -0
- package/dist/test.spec.js +0 -7
- package/dist/test.test.d.ts +0 -1
- package/dist/test.test.js +0 -9
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ScriptTestSimulator = exports.ScriptEngineSimulatorFunctions = void 0;
|
|
4
|
-
const helpers_lib_1 = require("helpers-lib");
|
|
5
|
-
const action_before_testing_1 = require("../decorators/action-before-testing");
|
|
6
|
-
const interfaces_1 = require("../interfaces");
|
|
7
|
-
const structured_text_1 = require("../structured-text");
|
|
8
|
-
const execution_history_1 = require("./helpers/execution-history");
|
|
9
|
-
const script_branches_map_1 = require("./helpers/script-branches-map");
|
|
10
|
-
class ScriptEngineSimulatorFunctions {
|
|
11
|
-
}
|
|
12
|
-
exports.ScriptEngineSimulatorFunctions = ScriptEngineSimulatorFunctions;
|
|
13
|
-
const MAX_CALL_STACK_DEPTH = 100;
|
|
14
|
-
class ScriptTestSimulator {
|
|
15
|
-
constructor(scriptDefinitions, options = { prscriptTypeChanges: true, richTextTags: undefined }) {
|
|
16
|
-
this.scriptDefinitions = scriptDefinitions;
|
|
17
|
-
this.options = options;
|
|
18
|
-
this.visitedBranchStates = new Map();
|
|
19
|
-
this.scriptBranchesMap = new script_branches_map_1.ScriptBranchesMap(this.scriptDefinitions);
|
|
20
|
-
if (this.options.prscriptTypeChanges) {
|
|
21
|
-
this.globalNameSpace = new Map();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @throws SimulationError, ActionsBeforeTestingError, BranchingBeforeTestingError
|
|
26
|
-
*/
|
|
27
|
-
simulateScript(scriptDefinition, jsEngine, actionsBeforeTesting) {
|
|
28
|
-
if (this.options.prscriptTypeChanges) {
|
|
29
|
-
jsEngine.globalNameSpace = this.globalNameSpace;
|
|
30
|
-
}
|
|
31
|
-
let initialContext = {
|
|
32
|
-
executionHistory: new execution_history_1.ExecutionHistory(),
|
|
33
|
-
stack: new helpers_lib_1.Stack(),
|
|
34
|
-
jsEngine,
|
|
35
|
-
depth: 0,
|
|
36
|
-
lastExecutedAction: undefined
|
|
37
|
-
};
|
|
38
|
-
let allPossibleStates = [initialContext];
|
|
39
|
-
this.processActionsBeforeTesting(actionsBeforeTesting, allPossibleStates);
|
|
40
|
-
this.visitedBranchStates.clear();
|
|
41
|
-
this.executeScript(scriptDefinition, allPossibleStates);
|
|
42
|
-
this.visitedBranchStates.clear();
|
|
43
|
-
}
|
|
44
|
-
getUnvisitedBranchLocations() {
|
|
45
|
-
return this.scriptBranchesMap.getUnvisitedBranchLocations();
|
|
46
|
-
}
|
|
47
|
-
processActionsBeforeTesting(actionsBeforeTesting, allPossibleStates) {
|
|
48
|
-
actionsBeforeTesting.forEach((action, index) => {
|
|
49
|
-
switch (action.type) {
|
|
50
|
-
case 'command':
|
|
51
|
-
this.executeActionBeforeTesting(action, allPossibleStates, index);
|
|
52
|
-
break;
|
|
53
|
-
case 'runScript':
|
|
54
|
-
this.branchOutFromScript(action, allPossibleStates, index);
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
throw new Error(`Unknown action before testing type: ${action.type}`);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
executeActionBeforeTesting(action, allPossibleStates, index) {
|
|
62
|
-
try {
|
|
63
|
-
allPossibleStates.forEach(state => {
|
|
64
|
-
Reflect.defineMetadata(action_before_testing_1.ActionBeforeTestingFlag, true, state.jsEngine.functions);
|
|
65
|
-
state.jsEngine.execute(action.value);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, allPossibleStates[0].executionHistory);
|
|
70
|
-
throw new interfaces_1.ActionsBeforeTestingError(errorMessage, index);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
branchOutFromScript(action, allPossibleStates, index) {
|
|
74
|
-
let allPossibleEndings = [];
|
|
75
|
-
let targetScript = this.scriptBranchesMap.getScript(action.value);
|
|
76
|
-
if (!targetScript) {
|
|
77
|
-
throw new Error(`Target script is not found: ${action.value}`);
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
this.visitedBranchStates.clear();
|
|
81
|
-
allPossibleStates.forEach(state => {
|
|
82
|
-
state.executionHistory.addEntry(`Branching out from script: ${action.value}`);
|
|
83
|
-
state.depth = 0;
|
|
84
|
-
Reflect.defineMetadata(action_before_testing_1.ActionBeforeTestingFlag, false, state.jsEngine.functions);
|
|
85
|
-
let executionResult = this.executeBranch(targetScript, state, false);
|
|
86
|
-
if (!executionResult.exitFound) {
|
|
87
|
-
let errorMessage = this.prepareErrorMessage(`All possible paths are creating infinite loops, no exit found while executing: ${action.value}`, state.executionHistory);
|
|
88
|
-
throw new interfaces_1.SimulationError(errorMessage, this.scriptBranchesMap.getRootBranchLocation(targetScript));
|
|
89
|
-
}
|
|
90
|
-
executionResult.allEndings.forEach(ending => {
|
|
91
|
-
allPossibleEndings.push(ending);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
let uniqueEndings = this.removeDuplicateEndings(allPossibleEndings);
|
|
95
|
-
allPossibleStates.length = 0;
|
|
96
|
-
allPossibleStates.push(...uniqueEndings);
|
|
97
|
-
allPossibleStates.forEach(ending => {
|
|
98
|
-
ending.executionHistory
|
|
99
|
-
.addEntry(`${uniqueEndings.length} unique ending${uniqueEndings.length > 1 ? 's' : ''} generated.`)
|
|
100
|
-
.addEntry('');
|
|
101
|
-
if (!ending.lastExecutedAction) {
|
|
102
|
-
throw new Error('Script execution is ended without executing any command!');
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
try {
|
|
106
|
-
ending.jsEngine.functions.onScriptBranchingEnd();
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
let path = this.scriptBranchesMap.getActionLocation(ending.lastExecutedAction);
|
|
110
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, ending.executionHistory);
|
|
111
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
if (e instanceof interfaces_1.SimulationError) {
|
|
118
|
-
throw new interfaces_1.BranchingBeforeTestingError(`${e.message}`, index, e.location);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
throw e;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
executeScript(scriptDefinition, allPossibleStates) {
|
|
126
|
-
allPossibleStates.forEach(state => {
|
|
127
|
-
state.executionHistory.addEntry(`Running script: ${scriptDefinition.id}`);
|
|
128
|
-
state.depth = 0;
|
|
129
|
-
Reflect.defineMetadata(action_before_testing_1.ActionBeforeTestingFlag, false, state.jsEngine.functions);
|
|
130
|
-
let executionResult = this.executeBranch(scriptDefinition, state, true);
|
|
131
|
-
if (!executionResult.exitFound) {
|
|
132
|
-
let errorMessage = this.prepareErrorMessage(`All possible paths are creating infinite loops, no exit found while executing: ${scriptDefinition.id}`, state.executionHistory);
|
|
133
|
-
throw new interfaces_1.SimulationError(errorMessage, this.scriptBranchesMap.getRootBranchLocation(scriptDefinition));
|
|
134
|
-
}
|
|
135
|
-
executionResult.allEndings.forEach(ending => {
|
|
136
|
-
if (!ending.lastExecutedAction) {
|
|
137
|
-
throw new Error('Script execution is ended without executing any command!');
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
try {
|
|
141
|
-
ending.jsEngine.functions.onEnd();
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
let path = this.scriptBranchesMap.getActionLocation(ending.lastExecutedAction);
|
|
145
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, ending.executionHistory);
|
|
146
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
executeBranch(branch, context, registerVisitedBranches) {
|
|
153
|
-
if (!this.isBranchVisitedAndRegister(branch, context)) {
|
|
154
|
-
return {
|
|
155
|
-
allEndings: [],
|
|
156
|
-
exitFound: false
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
let allPossibleEndings = [];
|
|
160
|
-
let exitFound = true;
|
|
161
|
-
if (registerVisitedBranches) {
|
|
162
|
-
this.scriptBranchesMap.setVisited(branch);
|
|
163
|
-
}
|
|
164
|
-
context.depth++;
|
|
165
|
-
if (context.depth > MAX_CALL_STACK_DEPTH) {
|
|
166
|
-
let errorMessage = this.prepareErrorMessage(`Maximum depth "${MAX_CALL_STACK_DEPTH}" is reached. Try to reduce the script branching tree or check infinite loops with trivial state changes.`, context.executionHistory);
|
|
167
|
-
throw new interfaces_1.SimulationError(errorMessage, this.scriptBranchesMap.getRootBranchLocation(branch));
|
|
168
|
-
}
|
|
169
|
-
context.stack.add(...branch.actions);
|
|
170
|
-
while (!context.stack.isEmpty) {
|
|
171
|
-
let action = context.stack.pop();
|
|
172
|
-
let executionResult = this.executeAction(action, context, registerVisitedBranches);
|
|
173
|
-
if (context.stack.isEmpty) {
|
|
174
|
-
allPossibleEndings.push(...executionResult.allEndings);
|
|
175
|
-
exitFound = executionResult.exitFound && exitFound;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
allPossibleEndings = allPossibleEndings.length > 0 ? this.removeDuplicateEndings(allPossibleEndings) : [];
|
|
179
|
-
return {
|
|
180
|
-
allEndings: allPossibleEndings,
|
|
181
|
-
exitFound
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
executeAction(action, context, registerVisitedBranches) {
|
|
185
|
-
context.lastExecutedAction = action;
|
|
186
|
-
switch (action.type) {
|
|
187
|
-
case 'command':
|
|
188
|
-
return this.executeActionCommand(action, context);
|
|
189
|
-
case 'dialog':
|
|
190
|
-
return this.executeDialogCommand(action, context);
|
|
191
|
-
case 'jumpTo':
|
|
192
|
-
return this.executeActionjumpTo(action, context, registerVisitedBranches);
|
|
193
|
-
case 'branchByCondition':
|
|
194
|
-
return this.executeActionBranchByCondition(action, context, registerVisitedBranches);
|
|
195
|
-
case 'branchByChance':
|
|
196
|
-
return this.executeActionBranchByChance(action, context, registerVisitedBranches);
|
|
197
|
-
case 'branchByPlayerChoice':
|
|
198
|
-
return this.executeActionBranchByPlayerChoice(action, context, registerVisitedBranches);
|
|
199
|
-
default:
|
|
200
|
-
throw new Error(`Unknown action type: ${action.type}`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
executeActionCommand(action, context) {
|
|
204
|
-
try {
|
|
205
|
-
context.jsEngine.execute(action.value);
|
|
206
|
-
}
|
|
207
|
-
catch (e) {
|
|
208
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
209
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, context.executionHistory);
|
|
210
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
allEndings: [context],
|
|
214
|
-
exitFound: true
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
executeDialogCommand(action, context) {
|
|
218
|
-
let dialogItem = action.value;
|
|
219
|
-
let text;
|
|
220
|
-
try {
|
|
221
|
-
text = context.jsEngine.string(dialogItem.text);
|
|
222
|
-
this.options.richTextTags && structured_text_1.RichTextValidator.validate(text, this.options.richTextTags);
|
|
223
|
-
context.jsEngine.functions.onDialog(text, dialogItem.speaker);
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
227
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, context.executionHistory);
|
|
228
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
allEndings: [context],
|
|
232
|
-
exitFound: true
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
executeActionjumpTo(action, context, registerVisitedBranches) {
|
|
236
|
-
let targetScript = this.scriptBranchesMap.getScript(action.value);
|
|
237
|
-
context.executionHistory.addEntry(`Jumping to script: ${action.value}`);
|
|
238
|
-
return this.executeBranch(targetScript, context, registerVisitedBranches);
|
|
239
|
-
}
|
|
240
|
-
executeActionBranchByCondition(action, context, registerVisitedBranches) {
|
|
241
|
-
let subBranches = action.value;
|
|
242
|
-
let validBranch = subBranches.find(subBranch => this.checkBranchCondition(subBranch, context));
|
|
243
|
-
if (!validBranch) {
|
|
244
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
245
|
-
let errorMessage = this.prepareErrorMessage(`No option is fulfilled the condition during branching.`, context.executionHistory);
|
|
246
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
247
|
-
}
|
|
248
|
-
context.executionHistory.addEntry(`Branching by condition: ${validBranch.condition ? validBranch.condition : 'default'}`);
|
|
249
|
-
return this.executeBranch(validBranch, context, registerVisitedBranches);
|
|
250
|
-
}
|
|
251
|
-
executeActionBranchByChance(action, context, registerVisitedBranches) {
|
|
252
|
-
let subBranches = action.value;
|
|
253
|
-
let validItems = subBranches
|
|
254
|
-
.map((subBranch, index) => ({ index, subBranch }))
|
|
255
|
-
.filter(item => this.checkBranchCondition(item.subBranch, context));
|
|
256
|
-
if (validItems.length === 0) {
|
|
257
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
258
|
-
let errorMessage = this.prepareErrorMessage(`No option is fulfilled the condition during branching.`, context.executionHistory);
|
|
259
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
260
|
-
}
|
|
261
|
-
let allExecutionResults = validItems.map(item => {
|
|
262
|
-
try {
|
|
263
|
-
let weight = helpers_lib_1.Comparator.isString(item.subBranch.weight)
|
|
264
|
-
? context.jsEngine.number(item.subBranch.weight)
|
|
265
|
-
: item.subBranch.weight;
|
|
266
|
-
if (!helpers_lib_1.Comparator.isNumber(weight) || weight < 0) {
|
|
267
|
-
throw new Error(`Weight of branch ${item.index} is not a valid number: "${item.subBranch.weight}" -> ${weight}.`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
catch (e) {
|
|
271
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
272
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, context.executionHistory);
|
|
273
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
274
|
-
}
|
|
275
|
-
let newContext = this.duplicateContext(context);
|
|
276
|
-
newContext.executionHistory.addEntry(`Branching by chance: ${item.index}`);
|
|
277
|
-
return this.executeBranch(item.subBranch, newContext, registerVisitedBranches);
|
|
278
|
-
});
|
|
279
|
-
return {
|
|
280
|
-
allEndings: allExecutionResults.flatMap(result => result.allEndings),
|
|
281
|
-
exitFound: allExecutionResults.some(result => result.exitFound)
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
executeActionBranchByPlayerChoice(action, context, registerVisitedBranches) {
|
|
285
|
-
let subBranches = action.value;
|
|
286
|
-
let validBranches = subBranches.filter(subBranch => this.checkBranchCondition(subBranch, context));
|
|
287
|
-
if (validBranches.length === 0) {
|
|
288
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
289
|
-
let errorMessage = this.prepareErrorMessage(`No option is fulfilled the condition during branching.`, context.executionHistory);
|
|
290
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
291
|
-
}
|
|
292
|
-
try {
|
|
293
|
-
context.jsEngine.functions.onPlayerChoice(validBranches.map(branch => context.jsEngine.string(branch.text)));
|
|
294
|
-
}
|
|
295
|
-
catch (e) {
|
|
296
|
-
let path = this.scriptBranchesMap.getActionLocation(action);
|
|
297
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, context.executionHistory);
|
|
298
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
299
|
-
}
|
|
300
|
-
let allExecutionResults = validBranches.map(subBranch => {
|
|
301
|
-
let newContext = this.duplicateContext(context);
|
|
302
|
-
newContext.executionHistory.addEntry(`Player choice: ${subBranch.text}`);
|
|
303
|
-
return this.executeBranch(subBranch, newContext, registerVisitedBranches);
|
|
304
|
-
});
|
|
305
|
-
return {
|
|
306
|
-
allEndings: allExecutionResults.flatMap(result => result.allEndings),
|
|
307
|
-
exitFound: allExecutionResults.some(result => result.exitFound)
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
checkBranchCondition(branch, context) {
|
|
311
|
-
if (!branch.condition) {
|
|
312
|
-
return true;
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
try {
|
|
316
|
-
return context.jsEngine.boolean(branch.condition);
|
|
317
|
-
}
|
|
318
|
-
catch (e) {
|
|
319
|
-
let path = this.scriptBranchesMap.getBranchLocation(branch);
|
|
320
|
-
let errorMessage = this.prepareErrorMessage(`${e}`, context.executionHistory);
|
|
321
|
-
throw new interfaces_1.SimulationError(errorMessage, path);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
removeDuplicateEndings(allPossibleEndings) {
|
|
326
|
-
let uniqueEndings = [];
|
|
327
|
-
let processedEndings = allPossibleEndings.map(ending => ({
|
|
328
|
-
ending: ending,
|
|
329
|
-
variablesString: JSON.stringify(ending.jsEngine.variables),
|
|
330
|
-
functionsString: JSON.stringify(ending.jsEngine.functions)
|
|
331
|
-
}));
|
|
332
|
-
processedEndings.forEach(data => {
|
|
333
|
-
let isUnique = uniqueEndings.every(uniqueEnding => data.functionsString !== uniqueEnding.functionsString || data.variablesString !== uniqueEnding.variablesString);
|
|
334
|
-
if (isUnique) {
|
|
335
|
-
uniqueEndings.push({
|
|
336
|
-
ending: data.ending,
|
|
337
|
-
variablesString: data.variablesString,
|
|
338
|
-
functionsString: data.functionsString
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
return uniqueEndings.map(data => data.ending);
|
|
343
|
-
}
|
|
344
|
-
isBranchVisitedAndRegister(branch, context) {
|
|
345
|
-
let stateString = JSON.stringify(context.jsEngine.variables) + JSON.stringify(context.jsEngine.functions);
|
|
346
|
-
let branchStates = this.visitedBranchStates.get(branch);
|
|
347
|
-
if (!branchStates) {
|
|
348
|
-
branchStates = new Set();
|
|
349
|
-
this.visitedBranchStates.set(branch, branchStates);
|
|
350
|
-
}
|
|
351
|
-
if (branchStates.has(stateString)) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
branchStates.add(stateString);
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
duplicateContext(context) {
|
|
360
|
-
return {
|
|
361
|
-
executionHistory: context.executionHistory.duplicate(),
|
|
362
|
-
stack: context.stack.duplicate(),
|
|
363
|
-
jsEngine: context.jsEngine.duplicate(),
|
|
364
|
-
depth: context.depth,
|
|
365
|
-
lastExecutedAction: context.lastExecutedAction
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
prepareErrorMessage(errorMessage, executionHistory) {
|
|
369
|
-
return `${errorMessage}\n\n----Execution history----\n${executionHistory.toString()}`;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
exports.ScriptTestSimulator = ScriptTestSimulator;
|
|
373
|
-
//# sourceMappingURL=script-test-simulator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|