Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2020-01-21 14:10:02 +0300
committerbubnikv <bubnikv@gmail.com>2020-01-21 14:10:09 +0300
commit05ea01bdcccb3d8bc5d46b71c20a30e25352cea8 (patch)
tree9e2f7e15d95d4e0d596c7aa0fea84a980803670e /tests
parent6eaf48ebd8cc9f6436ccd9a4e1b24899c87e7e5e (diff)
Ported PlaceholderParser unit tests to C++.
Diffstat (limited to 'tests')
-rw-r--r--tests/libslic3r/CMakeLists.txt1
-rw-r--r--tests/libslic3r/test_placeholder_parser.cpp74
2 files changed, 75 insertions, 0 deletions
diff --git a/tests/libslic3r/CMakeLists.txt b/tests/libslic3r/CMakeLists.txt
index 02764589b..e34a40f34 100644
--- a/tests/libslic3r/CMakeLists.txt
+++ b/tests/libslic3r/CMakeLists.txt
@@ -7,6 +7,7 @@ add_executable(${_TEST_NAME}_tests
test_config.cpp
test_elephant_foot_compensation.cpp
test_geometry.cpp
+ test_placeholder_parser.cpp
test_polygon.cpp
test_stl.cpp
)
diff --git a/tests/libslic3r/test_placeholder_parser.cpp b/tests/libslic3r/test_placeholder_parser.cpp
new file mode 100644
index 000000000..5802862b7
--- /dev/null
+++ b/tests/libslic3r/test_placeholder_parser.cpp
@@ -0,0 +1,74 @@
+#include <catch2/catch.hpp>
+
+#include "libslic3r/PlaceholderParser.hpp"
+#include "libslic3r/PrintConfig.hpp"
+
+using namespace Slic3r;
+
+SCENARIO("Placeholder parser scripting", "[PlaceholderParser]") {
+ PlaceholderParser parser;
+ auto config = DynamicPrintConfig::full_print_config();
+
+ config.set_deserialize( {
+ { "printer_notes", " PRINTER_VENDOR_PRUSA3D PRINTER_MODEL_MK2 " },
+ { "nozzle_diameter", "0.6;0.6;0.6;0.6" },
+ { "temperature", "357;359;363;378" }
+ });
+ parser.apply_config(config);
+ parser.set("foo", 0);
+ parser.set("bar", 2);
+ parser.set("num_extruders", 4);
+
+ SECTION("nested config options (legacy syntax)") { REQUIRE(parser.process("[temperature_[foo]]") == "357"); }
+ SECTION("array reference") { REQUIRE(parser.process("{temperature[foo]}") == "357"); }
+ SECTION("whitespaces and newlines are maintained") { REQUIRE(parser.process("test [ temperature_ [foo] ] \n hu") == "test 357 \n hu"); }
+
+ // Test the math expressions.
+ SECTION("math: 2*3") { REQUIRE(parser.process("{2*3}") == "6"); }
+ SECTION("math: 2*3/6") { REQUIRE(parser.process("{2*3/6}") == "1"); }
+ SECTION("math: 2*3/12") { REQUIRE(parser.process("{2*3/12}") == "0"); }
+ SECTION("math: 2.*3/12") { REQUIRE(std::stod(parser.process("{2.*3/12}")) == Approx(0.5)); }
+// SECTION("math: 10 % 2.5") { REQUIRE(parser.process("{10%2.5}") == "0"); }
+// SECTION("math: 11 / 2.5") { REQUIRE(parser.process("{11/2.5-1}") == "1"); }
+ SECTION("math: 2*(3-12)") { REQUIRE(parser.process("{2*(3-12)}") == "-18"); }
+ SECTION("math: 2*foo*(3-12)") { REQUIRE(parser.process("{2*foo*(3-12)}") == "0"); }
+ SECTION("math: 2*bar*(3-12)") { REQUIRE(parser.process("{2*bar*(3-12)}") == "-36"); }
+ SECTION("math: 2.5*bar*(3-12)") { REQUIRE(std::stod(parser.process("{2.5*bar*(3-12)}")) == Approx(-45)); }
+ SECTION("math: min(12, 14)") { REQUIRE(parser.process("{min(12, 14)}") == "12"); }
+ SECTION("math: max(12, 14)") { REQUIRE(parser.process("{max(12, 14)}") == "14"); }
+ SECTION("math: min(13.4, -1238.1)") { REQUIRE(std::stod(parser.process("{min(13.4, -1238.1)}")) == Approx(-1238.1)); }
+ SECTION("math: max(13.4, -1238.1)") { REQUIRE(std::stod(parser.process("{max(13.4, -1238.1)}")) == Approx(13.4)); }
+// SECTION("math: int(13.4)") { REQUIRE(parser.process("{int(13.4)}") == "13"); }
+
+ // Test the boolean expression parser.
+ auto boolean_expression = [&parser](const std::string& templ) { return parser.evaluate_boolean_expression(templ, parser.config()); };
+
+ SECTION("boolean expression parser: 12 == 12") { REQUIRE(boolean_expression("12 == 12")); }
+ SECTION("boolean expression parser: 12 != 12") { REQUIRE(! boolean_expression("12 != 12")); }
+ SECTION("boolean expression parser: regex matches") { REQUIRE(boolean_expression("\"has some PATTERN embedded\" =~ /.*PATTERN.*/")); }
+ SECTION("boolean expression parser: regex does not match") { REQUIRE(! boolean_expression("\"has some PATTERN embedded\" =~ /.*PTRN.*/")); }
+ SECTION("boolean expression parser: accessing variables, equal") { REQUIRE(boolean_expression("foo + 2 == bar")); }
+ SECTION("boolean expression parser: accessing variables, not equal") { REQUIRE(! boolean_expression("foo + 3 == bar")); }
+ SECTION("boolean expression parser: (12 == 12) and (13 != 14)") { REQUIRE(boolean_expression("(12 == 12) and (13 != 14)")); }
+ SECTION("boolean expression parser: (12 == 12) && (13 != 14)") { REQUIRE(boolean_expression("(12 == 12) && (13 != 14)")); }
+ SECTION("boolean expression parser: (12 == 12) or (13 == 14)") { REQUIRE(boolean_expression("(12 == 12) or (13 == 14)")); }
+ SECTION("boolean expression parser: (12 == 12) || (13 == 14)") { REQUIRE(boolean_expression("(12 == 12) || (13 == 14)")); }
+ SECTION("boolean expression parser: (12 == 12) and not (13 == 14)") { REQUIRE(boolean_expression("(12 == 12) and not (13 == 14)")); }
+ SECTION("boolean expression parser: ternary true") { REQUIRE(boolean_expression("(12 == 12) ? (1 - 1 == 0) : (2 * 2 == 3)")); }
+ SECTION("boolean expression parser: ternary false") { REQUIRE(! boolean_expression("(12 == 21/2) ? (1 - 1 == 0) : (2 * 2 == 3)")); }
+ SECTION("boolean expression parser: ternary false 2") { REQUIRE(boolean_expression("(12 == 13) ? (1 - 1 == 3) : (2 * 2 == 4)")); }
+ SECTION("boolean expression parser: ternary true 2") { REQUIRE(! boolean_expression("(12 == 2 * 6) ? (1 - 1 == 3) : (2 * 2 == 4)")); }
+ SECTION("boolean expression parser: lower than - false") { REQUIRE(! boolean_expression("12 < 3")); }
+ SECTION("boolean expression parser: lower than - true") { REQUIRE(boolean_expression("12 < 22")); }
+ SECTION("boolean expression parser: greater than - true") { REQUIRE(boolean_expression("12 > 3")); }
+ SECTION("boolean expression parser: greater than - false") { REQUIRE(! boolean_expression("12 > 22")); }
+ SECTION("boolean expression parser: lower than or equal- false") { REQUIRE(! boolean_expression("12 <= 3")); }
+ SECTION("boolean expression parser: lower than or equal - true") { REQUIRE(boolean_expression("12 <= 22")); }
+ SECTION("boolean expression parser: greater than or equal - true") { REQUIRE(boolean_expression("12 >= 3")); }
+ SECTION("boolean expression parser: greater than or equal - false") { REQUIRE(! boolean_expression("12 >= 22")); }
+ SECTION("boolean expression parser: lower than or equal (same values) - true") { REQUIRE(boolean_expression("12 <= 12")); }
+ SECTION("boolean expression parser: greater than or equal (same values) - true") { REQUIRE(boolean_expression("12 >= 12")); }
+ SECTION("complex expression") { REQUIRE(boolean_expression("printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 and num_extruders>1")); }
+ SECTION("complex expression2") { REQUIRE(boolean_expression("printer_notes=~/.*PRINTER_VEwerfNDOR_PRUSA3D.*/ or printer_notes=~/.*PRINTertER_MODEL_MK2.*/ or (nozzle_diameter[0]==0.6 and num_extruders>1)")); }
+ SECTION("complex expression3") { REQUIRE(! boolean_expression("printer_notes=~/.*PRINTER_VEwerfNDOR_PRUSA3D.*/ or printer_notes=~/.*PRINTertER_MODEL_MK2.*/ or (nozzle_diameter[0]==0.3 and num_extruders>1)")); }
+}