Fixed unit-tests of GCodeFindReplace

Follow-up to 7da4bebe7a
    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.
This commit is contained in:
Vojtech Bubnik 2022-01-28 11:02:06 +01:00
parent 7da4bebe7a
commit ba84240a85

View File

@ -15,7 +15,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; infill\n" "G1 X13 Y32 Z1; infill\n"
"G1 X13 Y32 Z1; wipe\n"; "G1 X13 Y32 Z1; wipe\n";
WHEN("Replace \"move up\" with \"move down\", case sensitive") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -25,7 +25,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move up\" with \"move down\", case insensitive") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -35,7 +35,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move UP\" with \"move down\", case insensitive") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -45,13 +45,13 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move up\" with \"move down\", case sensitive") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
// Whole word // Whole word
WHEN("Replace \"move up\" with \"move down\", 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -61,17 +61,17 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move u\" with \"move down\", whole word") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
WHEN("Replace \"ove up\" with \"move down\", whole word") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
// Multi-line replace // Multi-line replace
WHEN("Replace \"move up\\nG1 X0 \" with \"move down\\nG0 X1 \"") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -82,7 +82,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
} }
// Multi-line replace, whole word. // Multi-line replace, whole word.
WHEN("Replace \"move up\\nG1 X0\" with \"move down\\nG0 X1\", 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -93,7 +93,7 @@ SCENARIO("Find/Replace with plain text", "[GCodeFindReplace]") {
} }
// Multi-line replace, whole word, fails. // Multi-line replace, whole word, fails.
WHEN("Replace \"move up\\nG1 X\" with \"move down\\nG0 X\", whole word") { 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); 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 Z1.21; move up\n"
"G1 X0 Y.33 Z.431 E1.2; perimeter\n"; "G1 X0 Y.33 Z.431 E1.2; perimeter\n";
WHEN("Regular expression NOT processed in non-regex mode") { 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); 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; infill\n"
"G1 X13 Y32 Z1; wipe\n"; "G1 X13 Y32 Z1; wipe\n";
WHEN("Replace \"move up\" with \"move down\", case sensitive") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -129,7 +129,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move up\" with \"move down\", case insensitive") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -139,7 +139,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move UP\" with \"move down\", case insensitive") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -149,13 +149,13 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move up\" with \"move down\", case sensitive") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
// Whole word // Whole word
WHEN("Replace \"move up\" with \"move down\", 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -165,17 +165,17 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
"G1 X13 Y32 Z1; wipe\n"); "G1 X13 Y32 Z1; wipe\n");
} }
WHEN("Replace \"move u\" with \"move down\", whole word") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
WHEN("Replace \"ove up\" with \"move down\", whole word") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
// Multi-line replace // Multi-line replace
WHEN("Replace \"move up\\nG1 X0 \" with \"move down\\nG0 X1 \"") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -186,7 +186,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
} }
// Multi-line replace, whole word. // Multi-line replace, whole word.
WHEN("Replace \"move up\\nG1 X0\" with \"move down\\nG0 X1\", 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0; home\n" "G1 Z0; home\n"
// substituted // substituted
@ -197,7 +197,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
} }
// Multi-line replace, whole word, fails. // Multi-line replace, whole word, fails.
WHEN("Replace \"move up\\nG1 X\" with \"move down\\nG0 X\", whole word") { 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); REQUIRE(find_replace.process_layer(gcode) == gcode);
} }
} }
@ -208,7 +208,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
"G1 Z1.21; move up\n" "G1 Z1.21; move up\n"
"G1 X0 Y.33 Z.431 E1.2; perimeter\n"; "G1 X0 Y.33 Z.431 E1.2; perimeter\n";
WHEN("Missing zeros before dot filled in") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z0.123; home\n" "G1 Z0.123; home\n"
"G1 Z1.21; move up\n" "G1 Z1.21; move up\n"
@ -237,7 +237,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
";TYPE:External perimeter\n" ";TYPE:External perimeter\n"
"G1 X1 Y.3 Z.431 E0.1\n"; "G1 X1 Y.3 Z.431 E0.1\n";
WHEN("Change extrusion rate of top solid infill, single line modifier") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z1.21; move up\n" "G1 Z1.21; move up\n"
";TYPE:Infill\n" ";TYPE:Infill\n"
@ -262,7 +262,7 @@ SCENARIO("Find/Replace with regexp", "[GCodeFindReplace]") {
"G1 X1 Y.3 Z.431 E0.1\n"); "G1 X1 Y.3 Z.431 E0.1\n");
} }
WHEN("Change extrusion rate of top solid infill, no single line modifier (incorrect)") { 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) == REQUIRE(find_replace.process_layer(gcode) ==
"G1 Z1.21; move up\n" "G1 Z1.21; move up\n"
";TYPE:Infill\n" ";TYPE:Infill\n"