From 8c3f351ab616a7a3ab88e451f7a7f0ae01a708cc Mon Sep 17 00:00:00 2001 From: toby Date: Wed, 1 Mar 2017 21:14:14 -0500 Subject: [PATCH] Add Jump and Conditional Jump tests --- test/tests/operations/FlowControl.js | 180 ++++++++++++++++++++++++++- 1 file changed, 179 insertions(+), 1 deletion(-) diff --git a/test/tests/operations/FlowControl.js b/test/tests/operations/FlowControl.js index 59c7f965..45399c21 100644 --- a/test/tests/operations/FlowControl.js +++ b/test/tests/operations/FlowControl.js @@ -64,6 +64,107 @@ TestRegister.addTests([ {"op":"To Base64", "args":["A-Za-z0-9+/="]} ] }, + { + name: "Jump: skips 0", + input: [ + "should be changed", + ].join("\n"), + expectedOutput: [ + "should be changed was changed", + ].join("\n"), + recipeConfig: [ + { + op: "Jump", + args: [0, 10], + }, + { + op: "Find / Replace", + args: [ + { + "option": "Regex", + "string": "should be changed" + }, + "should be changed was changed", + true, + true, + true, + ], + }, + ], + }, + { + name: "Jump: skips 1", + input: [ + "shouldnt be changed", + ].join("\n"), + expectedOutput: [ + "shouldnt be changed", + ].join("\n"), + recipeConfig: [ + { + op: "Jump", + args: [1, 10], + }, + { + op: "Find / Replace", + args: [ + { + "option": "Regex", + "string": "shouldnt be changed" + }, + "shouldnt be changed was changed", + true, + true, + true, + ], + }, + ], + }, + { + name: "Jump: skips negatively", + input: [ + "should be changed", + ].join("\n"), + expectedOutput: [ + "should be changed was changed", + ].join("\n"), + recipeConfig: [ + { + op: "Jump", + args: [2, 10], + }, + { + // Initially bypassed, until Jump(-3,_) + op: "Find / Replace", + args: [ + { + "option": "Regex", + "string": "should be changed" + }, + "should be changed was changed", + true, + true, + true, + ], + }, + { + // Initially bypassed + op: "Jump", + args: [1, 10], + }, + { + op: "Jump", + // -1 skips itself + // -2 skips the one before + // -3 skips the one before that + args: [-3, 10], + }, + { + op: "Wait", + args: [1], + }, + ], + }, { name: "Conditional Jump: Skips 0", input: [ @@ -79,7 +180,7 @@ TestRegister.addTests([ recipeConfig: [ { op: "Conditional Jump", - args: ["match", 0, 0], + args: ["match", 0, 10], }, { op: "Find / Replace", @@ -109,4 +210,81 @@ TestRegister.addTests([ }, ], }, + { + name: "Conditional Jump: Skips 1", + input: [ + "match", + "should not be changed", + "should be changed", + ].join("\n"), + expectedOutput: [ + "match", + "should not be changed", + "should be changed was changed" + ].join("\n"), + recipeConfig: [ + { + op: "Conditional Jump", + args: ["match", 1, 10], + }, + { + op: "Find / Replace", + args: [ + { + "option": "Regex", + "string": "should not be changed" + }, + "should not be changed was changed", + true, + true, + true, + ], + }, + { + op: "Find / Replace", + args: [ + { + "option": "Regex", + "string": "should be changed" + }, + "should be changed was changed", + true, + true, + true, + ], + }, + ], + }, + { + name: "Conditional Jump: Skips negatively", + input: [ + "match", + ].join("\n"), + expectedOutput: [ + "replaced", + ].join("\n"), + recipeConfig: [ + { + op: "Jump", + args: [1], + }, + { + op: "Find / Replace", + args: [ + { + "option": "Regex", + "string": "match" + }, + "replaced", + true, + true, + true, + ], + }, + { + op: "Conditional Jump", + args: ["match", -2, 10], + }, + ], + }, ]);