Add a test for path to svg conversion and back
@@ -40,3 +40,22 @@ pub fn to_svg_with_encoding(path: &Path, encoding: PathEncoding) -> String {
.as_str()
.into()
}
+
+#[cfg(test)]
+mod tests {
+ use super::Path;
+
+ #[test]
+ fn simple_path_to_svg_and_back() {
+ let mut path = Path::default();
+ path.move_to((0, 0));
+ path.line_to((100, 100));
+ path.line_to((0, 100));
+ path.close();
+
+ let svg = Path::to_svg(&path);
+ assert_eq!(svg, "M0 0L100 100L0 100L0 0Z");
+ // And back. Someone may find why they are not equal.
+ let _recreated = Path::from_svg(svg).expect("Failed to parse SVG path");
+ }
+}
