From ba84240a85561dba940b50c4f80cdbf77438d17a Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Fri, 28 Jan 2022 11:02:06 +0100 Subject: [PATCH] Fixed unit-tests of GCodeFindReplace Follow-up to 7da4bebe7a3653136eebb0dbd7557a8b5ddcbe91 WIP GCode substitutions: Changed the format of gcode_substitutions by adding an empty comment as a fourth parameter to each substitution. In the future, we will provide a UI to show / edit the comment. --- tests/fff_print/test_gcodefindreplace.cpp | 48 +++++++++++------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/fff_print/test_gcodefindreplace.cpp b/tests/fff_print/test_gcodefindreplace.cpp index e8a69bee2..1d714d1c3 100644 --- a/tests/fff_print/test_gcodefindreplace.cpp +++ b/tests/fff_print/test_gcodefindreplace.cpp @@ -15,7 +15,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; infill\n" "G1 X13 Y32 Z1; wipe\n"; WHEN("Replace \"move up\" with \"move down\", case sensitive") { - GCodeFindReplace find_replace({ "move up", "move down", "" }); + GCodeFindReplace find_replace({ "move up", "move down", "", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -25,7 +25,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move up\" with \"move down\", case insensitive") { - GCodeFindReplace find_replace({ "move up", "move down", "i" }); + GCodeFindReplace find_replace({ "move up", "move down", "i", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -35,7 +35,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move UP\" with \"move down\", case insensitive") { - GCodeFindReplace find_replace({ "move UP", "move down", "i" }); + GCodeFindReplace find_replace({ "move UP", "move down", "i", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -45,13 +45,13 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move up\" with \"move down\", case sensitive") { - GCodeFindReplace find_replace({ "move UP", "move down", "" }); + GCodeFindReplace find_replace({ "move UP", "move down", "", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } // Whole word WHEN("Replace \"move up\" with \"move down\", whole word") { - GCodeFindReplace find_replace({ "move up", "move down", "w" }); + GCodeFindReplace find_replace({ "move up", "move down", "w", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -61,17 +61,17 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move u\" with \"move down\", whole word") { - GCodeFindReplace find_replace({ "move u", "move down", "w" }); + GCodeFindReplace find_replace({ "move u", "move down", "w", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } WHEN("Replace \"ove up\" with \"move down\", whole word") { - GCodeFindReplace find_replace({ "move u", "move down", "w" }); + GCodeFindReplace find_replace({ "move u", "move down", "w", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } // Multi-line replace WHEN("Replace \"move up\\nG1 X0 \" with \"move down\\nG0 X1 \"") { - GCodeFindReplace find_replace({ "move up\\nG1 X0 ", "move down\\nG0 X1 ", "" }); + GCodeFindReplace find_replace({ "move up\\nG1 X0 ", "move down\\nG0 X1 ", "", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -82,7 +82,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { } // Multi-line replace, whole word. WHEN("Replace \"move up\\nG1 X0\" with \"move down\\nG0 X1\", whole word") { - GCodeFindReplace find_replace({ "move up\\nG1 X0", "move down\\nG0 X1", "w" }); + GCodeFindReplace find_replace({ "move up\\nG1 X0", "move down\\nG0 X1", "w", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -93,7 +93,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { } // Multi-line replace, whole word, fails. WHEN("Replace \"move up\\nG1 X\" with \"move down\\nG0 X\", whole word") { - GCodeFindReplace find_replace({ "move up\\nG1 X", "move down\\nG0 X", "w" }); + GCodeFindReplace find_replace({ "move up\\nG1 X", "move down\\nG0 X", "w", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } } @@ -104,7 +104,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") { "G1 Z1.21; move up\n" "G1 X0 Y.33 Z.431 E1.2; perimeter\n"; WHEN("Regular expression NOT processed in non-regex mode") { - GCodeFindReplace find_replace({ "( [XYZEF]-?)\\.([0-9]+)", "\\10.\\2", "" }); + GCodeFindReplace find_replace({ "( [XYZEF]-?)\\.([0-9]+)", "\\10.\\2", "", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } } @@ -119,7 +119,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; infill\n" "G1 X13 Y32 Z1; wipe\n"; WHEN("Replace \"move up\" with \"move down\", case sensitive") { - GCodeFindReplace find_replace({ "move up", "move down", "r" }); + GCodeFindReplace find_replace({ "move up", "move down", "r", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -129,7 +129,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move up\" with \"move down\", case insensitive") { - GCodeFindReplace find_replace({ "move up", "move down", "ri" }); + GCodeFindReplace find_replace({ "move up", "move down", "ri", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -139,7 +139,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move UP\" with \"move down\", case insensitive") { - GCodeFindReplace find_replace({ "move UP", "move down", "ri" }); + GCodeFindReplace find_replace({ "move UP", "move down", "ri", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -149,13 +149,13 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move up\" with \"move down\", case sensitive") { - GCodeFindReplace find_replace({ "move UP", "move down", "r" }); + GCodeFindReplace find_replace({ "move UP", "move down", "r", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } // Whole word WHEN("Replace \"move up\" with \"move down\", whole word") { - GCodeFindReplace find_replace({ "move up", "move down", "rw" }); + GCodeFindReplace find_replace({ "move up", "move down", "rw", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -165,17 +165,17 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 X13 Y32 Z1; wipe\n"); } WHEN("Replace \"move u\" with \"move down\", whole word") { - GCodeFindReplace find_replace({ "move u", "move down", "rw" }); + GCodeFindReplace find_replace({ "move u", "move down", "rw", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } WHEN("Replace \"ove up\" with \"move down\", whole word") { - GCodeFindReplace find_replace({ "move u", "move down", "rw" }); + GCodeFindReplace find_replace({ "move u", "move down", "rw", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } // Multi-line replace WHEN("Replace \"move up\\nG1 X0 \" with \"move down\\nG0 X1 \"") { - GCodeFindReplace find_replace({ "move up\\nG1 X0 ", "move down\\nG0 X1 ", "r" }); + GCodeFindReplace find_replace({ "move up\\nG1 X0 ", "move down\\nG0 X1 ", "r", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -186,7 +186,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { } // Multi-line replace, whole word. WHEN("Replace \"move up\\nG1 X0\" with \"move down\\nG0 X1\", whole word") { - GCodeFindReplace find_replace({ "move up\\nG1 X0", "move down\\nG0 X1", "rw" }); + GCodeFindReplace find_replace({ "move up\\nG1 X0", "move down\\nG0 X1", "rw", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0; home\n" // substituted @@ -197,7 +197,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { } // Multi-line replace, whole word, fails. WHEN("Replace \"move up\\nG1 X\" with \"move down\\nG0 X\", whole word") { - GCodeFindReplace find_replace({ "move up\\nG1 X", "move down\\nG0 X", "rw" }); + GCodeFindReplace find_replace({ "move up\\nG1 X", "move down\\nG0 X", "rw", "" }); REQUIRE(find_replace.process_layer(gcode) == gcode); } } @@ -208,7 +208,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 Z1.21; move up\n" "G1 X0 Y.33 Z.431 E1.2; perimeter\n"; WHEN("Missing zeros before dot filled in") { - GCodeFindReplace find_replace({ "( [XYZEF]-?)\\.([0-9]+)", "\\10.\\2", "r" }); + GCodeFindReplace find_replace({ "( [XYZEF]-?)\\.([0-9]+)", "\\10.\\2", "r", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z0.123; home\n" "G1 Z1.21; move up\n" @@ -237,7 +237,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { ";TYPE:External perimeter\n" "G1 X1 Y.3 Z.431 E0.1\n"; WHEN("Change extrusion rate of top solid infill, single line modifier") { - GCodeFindReplace find_replace({ "(;TYPE:Top solid infill\\n)(.*?)(;TYPE:[^T][^o][^p][^ ][^s]|$)", "${1}M221 S98\\n${2}M221 S95\\n${3}", "rs" }); + GCodeFindReplace find_replace({ "(;TYPE:Top solid infill\\n)(.*?)(;TYPE:[^T][^o][^p][^ ][^s]|$)", "${1}M221 S98\\n${2}M221 S95\\n${3}", "rs", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z1.21; move up\n" ";TYPE:Infill\n" @@ -262,7 +262,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") { "G1 X1 Y.3 Z.431 E0.1\n"); } WHEN("Change extrusion rate of top solid infill, no single line modifier (incorrect)") { - GCodeFindReplace find_replace({ "(;TYPE:Top solid infill\\n)(.*?)(;TYPE:[^T][^o][^p][^ ][^s]|$)", "${1}M221 S98\\n${2}\\nM221 S95${3}", "r" }); + GCodeFindReplace find_replace({ "(;TYPE:Top solid infill\\n)(.*?)(;TYPE:[^T][^o][^p][^ ][^s]|$)", "${1}M221 S98\\n${2}\\nM221 S95${3}", "r", "" }); REQUIRE(find_replace.process_layer(gcode) == "G1 Z1.21; move up\n" ";TYPE:Infill\n"