24_gcodemath.t 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 10;
  6. {
  7. {
  8. my $test_string = "{if{3 == 4}} string";
  9. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  10. is $result, "", 'If statement with nested bracket removes on false resolution.';
  11. }
  12. {
  13. my $test_string = "{if{3 == 4}} string\notherstring";
  14. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  15. is $result, "otherstring", 'if false only removes up to newline.';
  16. }
  17. {
  18. my $test_string = "{if{3 == 3}} string";
  19. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  20. is $result, " string", 'If statement with nested bracket removes itself only on resulting true, does not strip text outside of brackets.';
  21. }
  22. {
  23. my $test_string = "{if 3 > 2} string";
  24. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  25. is $result, " string", 'If statement with nested bracket removes itself only on resulting true, does not strip text outside of brackets.';
  26. }
  27. {
  28. my $test_string = "{if{3 == 3}}string";
  29. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  30. is $result, "string", 'If statement with nested bracket removes itself only on resulting true.';
  31. }
  32. {
  33. my $test_string = "M104 S{4*5}; Sets temp to {4*5}";
  34. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  35. is $result, "M104 S20; Sets temp to 20", 'Bracket replacement works with math ops';
  36. }
  37. {
  38. my $test_string = "M104 S\\{a\\}; Sets temp to {4*5}";
  39. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  40. is $result, "M104 S{a}; Sets temp to 20", 'Escaped string emittal.';
  41. }
  42. {
  43. my $test_string = "M104 S{a}; Sets temp to {4*5}";
  44. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  45. is $result, "M104 S{a}; Sets temp to 20", 'string (minus brackets) on failure to parse.';
  46. }
  47. {
  48. my $config = Slic3r::Config->new;
  49. $config->set('infill_extruder', 2);
  50. $config->normalize;
  51. my $test_string = "{if [infill_extruder] == 2}M104 S210";
  52. my $pp = Slic3r::GCode::PlaceholderParser->new;
  53. $pp->apply_config($config);
  54. my $interim = $pp->process($test_string);
  55. is $interim, "{if 2 == 2}M104 S210", 'Placeholder parser works inside conditional gcode.';
  56. my $result = Slic3r::ConditionalGCode::apply_math($interim);
  57. is $result, "M104 S210", 'If statement with nested bracket removes itself only on resulting true, does not strip text outside of brackets.';
  58. }
  59. }