Browse Source

toggleString args now additionally accept just input value, taking first option as default.

d98762625 6 years ago
parent
commit
7c9ebafd00
2 changed files with 32 additions and 3 deletions
  1. 7 3
      src/node/api.mjs
  2. 25 0
      test/tests/nodeApi/ops.mjs

+ 7 - 3
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;

+ 25 - 0
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
 </contact-info>`);
     }),
 
+    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("<contact-info><company>abc</company></contact-info>", {xPath: "contact-info/company"}).toString(),