@vnejs/plugins.scenario.random 0.1.16 → 0.2.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/dist/modules/random.d.ts +3 -1
- package/dist/modules/random.js +13 -2
- package/package.json +10 -7
- package/src/modules/random.ts +17 -2
- package/src/tests/random.test.ts +3 -2
package/dist/modules/random.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { ModuleCore } from "@vnejs/module.core";
|
|
|
2
2
|
import type { RandomPluginConstants, RandomPluginEvents, RandomPluginParams, RandomPluginSettings } from "../types.js";
|
|
3
3
|
export declare class Random extends ModuleCore<RandomPluginEvents, RandomPluginConstants, RandomPluginSettings, RandomPluginParams> {
|
|
4
4
|
name: string;
|
|
5
|
-
|
|
5
|
+
optionPrefix: string;
|
|
6
|
+
init: () => void;
|
|
6
7
|
onLineExec: () => Promise<void>;
|
|
8
|
+
onOptionLineExec: () => Promise<void>;
|
|
7
9
|
}
|
package/dist/modules/random.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { getOptionExecShift } from "@vnejs/helpers";
|
|
1
2
|
import { ModuleCore } from "@vnejs/module.core";
|
|
2
3
|
export class Random extends ModuleCore {
|
|
3
4
|
name = "random";
|
|
4
|
-
|
|
5
|
+
optionPrefix = `% ${this.name}.option`;
|
|
6
|
+
init = () => {
|
|
7
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.name, handler: this.onLineExec });
|
|
8
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: `${this.name}.option`, handler: this.onOptionLineExec });
|
|
9
|
+
};
|
|
5
10
|
onLineExec = async () => {
|
|
6
11
|
const { label, curLine } = this.globalState.scenario;
|
|
7
12
|
const options = [];
|
|
@@ -9,7 +14,7 @@ export class Random extends ModuleCore {
|
|
|
9
14
|
let indexShift = 1;
|
|
10
15
|
let curLineObj = lines[curLine + indexShift];
|
|
11
16
|
while (curLineObj && (curLineObj.indent ?? 0) > (lines[curLine].indent ?? 0)) {
|
|
12
|
-
if (curLineObj.line.startsWith(
|
|
17
|
+
if (curLineObj.line.startsWith(this.optionPrefix) && curLineObj.indent === (lines[curLine].indent ?? 0) + 2)
|
|
13
18
|
options.push(curLine + indexShift);
|
|
14
19
|
indexShift++;
|
|
15
20
|
curLineObj = lines[curLine + indexShift];
|
|
@@ -19,4 +24,10 @@ export class Random extends ModuleCore {
|
|
|
19
24
|
this.globalState.scenario.curLine = options[index] + 1;
|
|
20
25
|
this.emitNext();
|
|
21
26
|
};
|
|
27
|
+
onOptionLineExec = async () => {
|
|
28
|
+
const { label, curLine } = this.globalState.scenario;
|
|
29
|
+
const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label }));
|
|
30
|
+
this.globalState.scenario.curLine = curLine + getOptionExecShift(lines, curLine);
|
|
31
|
+
this.emitNext();
|
|
32
|
+
};
|
|
22
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.scenario.random",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,15 +30,18 @@
|
|
|
30
30
|
"author": "",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@vnejs/contracts.scenario.random": "~0.
|
|
33
|
+
"@vnejs/contracts.scenario.random": "~0.2.0",
|
|
34
|
+
"@vnejs/helpers": "~0.2.0"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
|
-
"@vnejs/
|
|
37
|
-
"@vnejs/
|
|
37
|
+
"@vnejs/helpers": "~0.2.0",
|
|
38
|
+
"@vnejs/module.core": "~0.2.0",
|
|
39
|
+
"@vnejs/shared": "~0.2.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@vnejs/configs.ts-common": "~0.
|
|
41
|
-
"@vnejs/configs.vitest": "~0.
|
|
42
|
-
"@vnejs/
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
43
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
44
|
+
"@vnejs/helpers": "~0.2.0",
|
|
45
|
+
"@vnejs/test-utils": "~0.2.0"
|
|
43
46
|
}
|
|
44
47
|
}
|
package/src/modules/random.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getOptionExecShift } from "@vnejs/helpers";
|
|
1
2
|
import { ModuleCore } from "@vnejs/module.core";
|
|
2
3
|
|
|
3
4
|
import type { RandomPluginConstants, RandomPluginEvents, RandomPluginParams, RandomPluginSettings } from "../types.js";
|
|
@@ -6,7 +7,12 @@ import type { ScenarioLine } from "../utils/random.js";
|
|
|
6
7
|
export class Random extends ModuleCore<RandomPluginEvents, RandomPluginConstants, RandomPluginSettings, RandomPluginParams> {
|
|
7
8
|
name = "random";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
optionPrefix = `% ${this.name}.option`;
|
|
11
|
+
|
|
12
|
+
init = () => {
|
|
13
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.name, handler: this.onLineExec });
|
|
14
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: `${this.name}.option`, handler: this.onOptionLineExec });
|
|
15
|
+
};
|
|
10
16
|
|
|
11
17
|
onLineExec = async () => {
|
|
12
18
|
const { label, curLine } = this.globalState.scenario;
|
|
@@ -17,7 +23,7 @@ export class Random extends ModuleCore<RandomPluginEvents, RandomPluginConstants
|
|
|
17
23
|
let curLineObj = lines[curLine + indexShift];
|
|
18
24
|
|
|
19
25
|
while (curLineObj && (curLineObj.indent ?? 0) > (lines[curLine].indent ?? 0)) {
|
|
20
|
-
if (curLineObj.line.startsWith(
|
|
26
|
+
if (curLineObj.line.startsWith(this.optionPrefix) && curLineObj.indent === (lines[curLine].indent ?? 0) + 2) options.push(curLine + indexShift);
|
|
21
27
|
|
|
22
28
|
indexShift++;
|
|
23
29
|
curLineObj = lines[curLine + indexShift];
|
|
@@ -31,4 +37,13 @@ export class Random extends ModuleCore<RandomPluginEvents, RandomPluginConstants
|
|
|
31
37
|
|
|
32
38
|
this.emitNext();
|
|
33
39
|
};
|
|
40
|
+
|
|
41
|
+
onOptionLineExec = async () => {
|
|
42
|
+
const { label, curLine } = this.globalState.scenario;
|
|
43
|
+
const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label })) as ScenarioLine[];
|
|
44
|
+
|
|
45
|
+
this.globalState.scenario.curLine = curLine + getOptionExecShift(lines, curLine);
|
|
46
|
+
|
|
47
|
+
this.emitNext();
|
|
48
|
+
};
|
|
34
49
|
}
|
package/src/tests/random.test.ts
CHANGED
|
@@ -18,8 +18,9 @@ describe("Random", () => {
|
|
|
18
18
|
|
|
19
19
|
stubEvent(observer, SCENARIO_EVENTS.LINES_GET, () => [
|
|
20
20
|
{ line: "% random", indent: 0 },
|
|
21
|
-
{ line: "% option A", indent: 2 },
|
|
22
|
-
{ line: "% option B", indent: 2 },
|
|
21
|
+
{ line: "% random.option A", indent: 2 },
|
|
22
|
+
{ line: "% random.option B", indent: 2 },
|
|
23
|
+
|
|
23
24
|
{ line: "next", indent: 0 },
|
|
24
25
|
]);
|
|
25
26
|
|