Slic3r/xs/t/24_gcodemath.t
2017-11-06 22:03:27 -06:00

53 lines
1.7 KiB
Perl

#!/usr/bin/perl
use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 7;
{
{
my $test_string = "{if{3 == 4}} string";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, "", 'If statement with nested bracket removes on false resolution.';
}
{
my $test_string = "{if{3 == 4}} string\notherstring";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, "otherstring", 'if false only removes up to newline.';
}
{
my $test_string = "{if{3 == 3}} string";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, " string", 'If statement with nested bracket removes itself only on resulting true, does not strip text outside of brackets.';
}
{
my $test_string = "{if{3 == 3}}string";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, "string", 'If statement with nested bracket removes itself only on resulting true.';
}
{
my $test_string = "M104 S{4*5}; Sets temp to {4*5}";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, "M104 S20; Sets temp to 20", 'Bracket replacement works with math ops';
}
{
my $test_string = "M104 S\\{a\\}; Sets temp to {4*5}";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, "M104 S{a}; Sets temp to 20", 'Escaped string emittal.';
}
{
my $test_string = "M104 S{a}; Sets temp to {4*5}";
my $result = Slic3r::ConditionalGCode::apply_math($test_string);
is $result, "M104 S{a}; Sets temp to 20", 'string (minus brackets) on failure to parse.';
}
}