add another test-case, start relying on Default::default

master
Sameer Puri 5 years ago
parent 06c6484b2c
commit 490e7100eb

@ -62,20 +62,26 @@ fn main() -> io::Result<()> {
}
};
let options = converter::ProgramOptions {
tolerance: matches
let mut options = ProgramOptions::default();
if let Some(tolerance) = matches
.value_of("tolerance")
.map(|x| x.parse().expect("could not parse tolerance"))
.unwrap_or(0.002),
feedrate: matches
.map(|tolerance| tolerance.parse().expect("could not parse tolerance"))
{
options.tolerance = tolerance;
}
if let Some(feedrate) = matches
.value_of("feedrate")
.map(|x| x.parse().expect("could not parse feedrate"))
.unwrap_or(300.0),
dpi: matches
.map(|feedrate| feedrate.parse().expect("could not parse tolerance"))
{
options.feedrate = feedrate;
}
if let Some(dpi) = matches
.value_of("dpi")
.map(|x| x.parse().expect("could not parse DPI"))
.unwrap_or(96.0),
};
.map(|dpi| dpi.parse().expect("could not parse tolerance"))
{
options.dpi = dpi;
}
let machine = machine::Machine::new(
matches
@ -120,19 +126,32 @@ fn main() -> io::Result<()> {
mod test {
use super::*;
#[test]
fn square_produces_expected_gcode() {
let shapes = include_str!("../tests/square.svg");
fn get_actual(input: &str) -> String {
let options = ProgramOptions::default();
let machine = Machine::default();
let document = roxmltree::Document::parse(&shapes).unwrap();
let document = roxmltree::Document::parse(input).unwrap();
let mut program = converter::svg2program(&document, options, machine);
postprocess::set_origin(&mut program, lyon_geom::math::point(0., 0.));
let program = converter::svg2program(&document, options, machine);
let mut actual = vec![];
assert!(gcode::program2gcode(program, &mut actual).is_ok());
assert_eq!(
String::from_utf8(actual).unwrap(),
include_str!("../tests/square.gcode")
)
String::from_utf8(actual).unwrap()
}
#[test]
fn square_produces_expected_gcode() {
let square = include_str!("../tests/square.svg");
let actual = get_actual(square);
assert_eq!(actual, include_str!("../tests/square.gcode"))
}
#[test]
fn square_transformed_produces_expected_gcode() {
let square_transformed = include_str!("../tests/square_transformed.svg");
let actual = get_actual(square_transformed);
assert_eq!(actual, include_str!("../tests/square_transformed.gcode"))
}
}

@ -0,0 +1,12 @@
G21
G94
G90
G0 X0 Y19
;svg#svg8 > g#layer1 > path#path838
G0 X9 Y8
G1 X9 Y0 F300
G1 X1 Y0 F300
G1 X0.9999999999999982 Y8 F300
G1 X9 Y8 F300
G0 X0 Y19
M20

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
sodipodi:docname="square_translated.svg"
inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
id="svg8"
version="1.1"
viewBox="0 0 10 10"
height="10mm"
width="10mm">
<defs
id="defs2" />
<sodipodi:namedview
inkscape:window-maximized="1"
inkscape:window-y="0"
inkscape:window-x="0"
inkscape:window-height="2109"
inkscape:window-width="3836"
units="mm"
showgrid="true"
inkscape:document-rotation="0"
inkscape:current-layer="layer1"
inkscape:document-units="mm"
inkscape:cy="35.055997"
inkscape:cx="21.930942"
inkscape:zoom="22.4"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base">
<inkscape:grid
spacingy="1"
spacingx="1"
units="mm"
id="grid836"
type="xygrid" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:groupmode="layer"
inkscape:label="Layer 1">
<path
id="path838"
transform="rotate(-90, 5, 5)"
d="M 1,1 H 9 V 9 H 1 Z"
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

Loading…
Cancel
Save