Better fix for non-global options not being replaced in filename placeholders. Includes refactoring and a new PlaceholderParser class. Also includes regression tests. #1831

This commit is contained in:
Alessandro Ranellucci 2014-03-17 00:39:07 +01:00
parent bc054e613c
commit 34f1511e0c
10 changed files with 146 additions and 128 deletions

View file

@ -1,4 +1,4 @@
use Test::More tests => 2;
use Test::More tests => 6;
use strict;
use warnings;
@ -44,10 +44,27 @@ use Slic3r::Test;
#==========================================================
{
my $config = Slic3r::Config->new_from_defaults;
is $config->replace_options('[temperature_[foo]]', { foo => '0' }),
200,
my $parser = Slic3r::GCode::PlaceholderParser->new;
$parser->apply_config(my $config = Slic3r::Config->new_from_defaults);
is $parser->process('[temperature_[foo]]', { foo => '0' }),
$config->temperature->[0],
"nested config options";
}
{
my $config = Slic3r::Config->new_from_defaults;
$config->set('output_filename_format', '[travel_speed]_[layer_height].gcode');
$config->set('start_gcode', "TRAVEL:[travel_speed] HEIGHT:[layer_height]\n");
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $output_file = $print->expanded_output_filepath;
ok $output_file !~ /\[travel_speed\]/, 'print config options are replaced in output filename';
ok $output_file !~ /\[layer_height\]/, 'region config options are replaced in output filename';
my $gcode = Slic3r::Test::gcode($print);
my ($t, $h) = map $config->$_, qw(travel_speed layer_height);
ok $gcode =~ /TRAVEL:$t/, 'print config options are replaced in custom G-code';
ok $gcode =~ /HEIGHT:$h/, 'region config options are replaced in custom G-code';
}
__END__

View file

@ -1,4 +1,4 @@
use Test::More tests => 4;
use Test::More tests => 2;
use strict;
use warnings;
@ -30,13 +30,4 @@ use Slic3r::Test;
ok abs(unscale($center->[Y]) - $config->print_center->[Y]) < epsilon, 'print is centered around print_center (Y)';
}
{
my $config = Slic3r::Config->new_from_defaults;
$config->set('output_filename_format', '[travel_speed]_[layer_height].gcode');
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $output_file = $print->expanded_output_filepath(undef, "foo.stl");
ok $output_file !~ /\[travel_speed\]/, 'print config options are replaced in output filename';
ok $output_file !~ /\[layer_height\]/, 'region config options are replaced in output filename';
}
__END__