24_gcodemath.t 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 7;
  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 == 3}}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.';
  26. }
  27. {
  28. my $test_string = "M104 S{4*5}; Sets temp to {4*5}";
  29. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  30. is $result, "M104 S20; Sets temp to 20", 'Bracket replacement works with math ops';
  31. }
  32. {
  33. my $test_string = "M104 S\\{a\\}; Sets temp to {4*5}";
  34. my $result = Slic3r::ConditionalGCode::apply_math($test_string);
  35. is $result, "M104 S{a}; Sets temp to 20", 'Escaped string emittal.';
  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", 'string (minus brackets) on failure to parse.';
  41. }
  42. }