diff --git a/src/node/api.mjs b/src/node/api.mjs index 11dd6e49..1af668ac 100644 --- a/src/node/api.mjs +++ b/src/node/api.mjs @@ -75,9 +75,13 @@ function transformArgs(originalArgs, newArgs) { if (index > -1) { const argument = allArgs[index]; - if (["toggleString"].indexOf(argument.type) > -1) { - argument.string = newArgs[key].string; - argument.option = newArgs[key].option; + if (argument.type === "toggleString") { + if (typeof newArgs[key] === "string") { + argument.string = newArgs[key]; + } else { + argument.string = newArgs[key].string; + argument.option = newArgs[key].option; + } } else if (argument.type === "editableOption") { // takes key: "option", key: {name, val: "string"}, key: {name, val: [...]} argument.value = typeof newArgs[key] === "string" ? newArgs[key]: newArgs[key].value; diff --git a/test/tests/nodeApi/ops.mjs b/test/tests/nodeApi/ops.mjs index 589826df..e0793295 100644 --- a/test/tests/nodeApi/ops.mjs +++ b/test/tests/nodeApi/ops.mjs @@ -48,6 +48,14 @@ TestRegister.addApiTests([ assert.equal(result.toString(), "aO[^ZS\u000eW\\^cb"); }), + + it("ADD: default option toggleString argument", () => { + const result = chef.ADD(3, { + key: "4", + }); + assert.strictEqual(result.toString(), "7"); + }), + it("addLineNumbers: No arguments", () => { const result = addLineNumbers("sample input"); assert.equal(result.toString(), "1 sample input"); @@ -921,6 +929,23 @@ smothering ampersand abreast `); }), + it("XOR: toggleString with default option", () => { + assert.strictEqual(chef.XOR("fe023da5", { + key: "73 6f 6d 65" + }).toString(), + "\u0015\n]W@\u000b\fP"); + }), + + it("XOR: toggleString with custom option", () => { + assert.strictEqual(chef.XOR("fe023da5", { + key: { + string: "73 6f 6d 65", + option: "utf8", + } + }).toString(), + "QV\u0010\u0004UDWQ"); + }), + it("XPath expression", () => { assert.strictEqual( chef.XPathExpression("abc", {xPath: "contact-info/company"}).toString(),