Skip to content

Commit 6a5fb92

Browse files
committed
Support 2 operand $mul actions
1 parent 40aa513 commit 6a5fb92

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ export function handleActions<Context>(
349349
}
350350

351351
if (has("$mul")) {
352-
let reference = input["$mul"][2]
352+
// $mul can have 2 or 3 operands, 2 means multiply the context variable (1st operand) by the 2nd operand
353+
let reference = input["$mul"][input["$mul"].length === 3 ? 2 : 0]
353354

354355
const variableValue1 = findNamedChild(input["$mul"][0], context)
355356
const variableValue2 = findNamedChild(input["$mul"][1], context)

tests/math-actions.spec.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,24 @@ const data = {
7373
],
7474
Mul1: [
7575
{
76-
$mul: ["Context.Object", 5, "Context.Object"],
76+
$mul: ["Context.Object", 5, "Context.Output"],
7777
},
7878
{
7979
Context: {
8080
Object: 18,
8181
},
8282
},
8383
],
84+
Mul2: [
85+
{
86+
$mul: ["Context.Object", 10]
87+
},
88+
{
89+
Context: {
90+
Object: 42
91+
}
92+
}
93+
]
8494
}
8595

8696
describe("$inc", () => {
@@ -118,9 +128,15 @@ describe("$dec", () => {
118128
})
119129

120130
describe("$mul", () => {
121-
it("can multiply a context object", () => {
131+
it("can multiply a context object and store it in another", () => {
122132
const [sm, vars] = data.Mul1
123133
const r = handleActions(sm, vars)
124-
assert.strictEqual(r.Context.Object, 90)
134+
assert.strictEqual(r.Context.Output, 90)
135+
})
136+
137+
it("can multiply a context object and store it in that object", () => {
138+
const [sm, vars] = data.Mul2
139+
const r= handleActions(sm, vars)
140+
assert.strictEqual(r.Context.Object, 420)
125141
})
126142
})

0 commit comments

Comments
 (0)