mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-04-24 06:39:56 +08:00
53 lines
1.7 KiB
Perl
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.';
|
|
}
|
|
}
|