Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2020-01-21 14:10:02 +0300
committerbubnikv <bubnikv@gmail.com>2020-01-21 14:10:09 +0300
commit05ea01bdcccb3d8bc5d46b71c20a30e25352cea8 (patch)
tree9e2f7e15d95d4e0d596c7aa0fea84a980803670e /t
parent6eaf48ebd8cc9f6436ccd9a4e1b24899c87e7e5e (diff)
Ported PlaceholderParser unit tests to C++.
Diffstat (limited to 't')
-rw-r--r--t/custom_gcode.t69
1 files changed, 1 insertions, 68 deletions
diff --git a/t/custom_gcode.t b/t/custom_gcode.t
index 5ffd9b7f4..44f952318 100644
--- a/t/custom_gcode.t
+++ b/t/custom_gcode.t
@@ -1,4 +1,4 @@
-use Test::More tests => 81;
+use Test::More tests => 41;
use strict;
use warnings;
@@ -46,73 +46,6 @@ use Slic3r::Test;
#==========================================================
{
- my $parser = Slic3r::GCode::PlaceholderParser->new;
- my $config = Slic3r::Config::new_from_defaults;
- $config->set('printer_notes', ' PRINTER_VENDOR_PRUSA3D PRINTER_MODEL_MK2 ');
- $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
- $parser->apply_config($config);
- $parser->set('foo' => 0);
- $parser->set('bar' => 2);
- $parser->set('num_extruders' => 4);
- is $parser->process('[temperature_[foo]]'),
- $config->temperature->[0],
- "nested config options (legacy syntax)";
- is $parser->process('{temperature[foo]}'),
- $config->temperature->[0],
- "array reference";
- is $parser->process("test [ temperature_ [foo] ] \n hu"),
- "test " . $config->temperature->[0] . " \n hu",
- "whitespaces and newlines are maintained";
- is $parser->process('{2*3}'), '6', 'math: 2*3';
- is $parser->process('{2*3/6}'), '1', 'math: 2*3/6';
- is $parser->process('{2*3/12}'), '0', 'math: 2*3/12';
- ok abs($parser->process('{2.*3/12}') - 0.5) < 1e-7, 'math: 2.*3/12';
- is $parser->process('{10%2.5}') '0', 'math: 10 % 2.5';
- is $parser->process('{11/2.5-1}') '1', 'math: 11 % 2.5';
- is $parser->process('{2*(3-12)}'), '-18', 'math: 2*(3-12)';
- is $parser->process('{2*foo*(3-12)}'), '0', 'math: 2*foo*(3-12)';
- is $parser->process('{2*bar*(3-12)}'), '-36', 'math: 2*bar*(3-12)';
- ok abs($parser->process('{2.5*bar*(3-12)}') - -45) < 1e-7, 'math: 2.5*bar*(3-12)';
- is $parser->process('{min(12, 14)}'), '12', 'math: min(12, 14)';
- is $parser->process('{max(12, 14)}'), '14', 'math: max(12, 14)';
- is $parser->process('{min(13.4, -1238.1)}'), '-1238.1', 'math: min(13.4, -1238.1)';
- is $parser->process('{max(13.4, -1238.1)}'), '13.4', 'math: max(13.4, -1238.1)';
- is $parser->process('{int(13.4)}'), '13', 'math: int(13.4)';
-
- # Test the boolean expression parser.
- is $parser->evaluate_boolean_expression('12 == 12'), 1, 'boolean expression parser: 12 == 12';
- is $parser->evaluate_boolean_expression('12 != 12'), 0, 'boolean expression parser: 12 != 12';
- is $parser->evaluate_boolean_expression('"has some PATTERN embedded" =~ /.*PATTERN.*/'), 1, 'boolean expression parser: regex matches';
- is $parser->evaluate_boolean_expression('"has some PATTERN embedded" =~ /.*PTRN.*/'), 0, 'boolean expression parser: regex does not match';
- is $parser->evaluate_boolean_expression('foo + 2 == bar'), 1, 'boolean expression parser: accessing variables, equal';
- is $parser->evaluate_boolean_expression('foo + 3 == bar'), 0, 'boolean expression parser: accessing variables, not equal';
-
- is $parser->evaluate_boolean_expression('(12 == 12) and (13 != 14)'), 1, 'boolean expression parser: (12 == 12) and (13 != 14)';
- is $parser->evaluate_boolean_expression('(12 == 12) && (13 != 14)'), 1, 'boolean expression parser: (12 == 12) && (13 != 14)';
- is $parser->evaluate_boolean_expression('(12 == 12) or (13 == 14)'), 1, 'boolean expression parser: (12 == 12) or (13 == 14)';
- is $parser->evaluate_boolean_expression('(12 == 12) || (13 == 14)'), 1, 'boolean expression parser: (12 == 12) || (13 == 14)';
- is $parser->evaluate_boolean_expression('(12 == 12) and not (13 == 14)'), 1, 'boolean expression parser: (12 == 12) and not (13 == 14)';
- is $parser->evaluate_boolean_expression('(12 == 12) ? (1 - 1 == 0) : (2 * 2 == 3)'), 1, 'boolean expression parser: ternary true';
- is $parser->evaluate_boolean_expression('(12 == 21/2) ? (1 - 1 == 0) : (2 * 2 == 3)'), 0, 'boolean expression parser: ternary false';
- is $parser->evaluate_boolean_expression('(12 == 13) ? (1 - 1 == 3) : (2 * 2 == 4)'), 1, 'boolean expression parser: ternary false';
- is $parser->evaluate_boolean_expression('(12 == 2 * 6) ? (1 - 1 == 3) : (2 * 2 == 4)'), 0, 'boolean expression parser: ternary true';
- is $parser->evaluate_boolean_expression('12 < 3'), 0, 'boolean expression parser: lower than - false';
- is $parser->evaluate_boolean_expression('12 < 22'), 1, 'boolean expression parser: lower than - true';
- is $parser->evaluate_boolean_expression('12 > 3'), 1, 'boolean expression parser: greater than - true';
- is $parser->evaluate_boolean_expression('12 > 22'), 0, 'boolean expression parser: greater than - false';
- is $parser->evaluate_boolean_expression('12 <= 3'), 0, 'boolean expression parser: lower than or equal- false';
- is $parser->evaluate_boolean_expression('12 <= 22'), 1, 'boolean expression parser: lower than or equal - true';
- is $parser->evaluate_boolean_expression('12 >= 3'), 1, 'boolean expression parser: greater than or equal - true';
- is $parser->evaluate_boolean_expression('12 >= 22'), 0, 'boolean expression parser: greater than or equal - false';
- is $parser->evaluate_boolean_expression('12 <= 12'), 1, 'boolean expression parser: lower than or equal (same values) - true';
- is $parser->evaluate_boolean_expression('12 >= 12'), 1, 'boolean expression parser: greater than or equal (same values) - true';
-
- is $parser->evaluate_boolean_expression('printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 and num_extruders>1'), 1, 'complex expression';
- is $parser->evaluate_boolean_expression('printer_notes=~/.*PRINTER_VEwerfNDOR_PRUSA3D.*/ or printer_notes=~/.*PRINTertER_MODEL_MK2.*/ or (nozzle_diameter[0]==0.6 and num_extruders>1)'), 1, 'complex expression2';
- is $parser->evaluate_boolean_expression('printer_notes=~/.*PRINTER_VEwerfNDOR_PRUSA3D.*/ or printer_notes=~/.*PRINTertER_MODEL_MK2.*/ or (nozzle_diameter[0]==0.3 and num_extruders>1)'), 0, 'complex expression3';
-}
-
-{
my $config = Slic3r::Config::new_from_defaults;
$config->set('output_filename_format', 'ts_[travel_speed]_lh_[layer_height].gcode');
$config->set('start_gcode', "TRAVEL:[travel_speed] HEIGHT:[layer_height]\n");