//! PLOT chooses the output format from the extension of `path` when no device is named (#2556), //! like EXPORT does; a device that writes another format is refused. use cadcraft_engine::Session; use cadcraft_engine::cmd::file::{IoHooks, set_io}; use cadcraft_engine::cmd::plotters::{PlotterStore, set_plotter_store}; use serde_json::json; fn session() -> Session { set_plotter_store(PlotterStore::memory()); set_io(IoHooks { read: |_, _| Err("no reader in this test".into()), write: |_, _| Err("no writer in this test".into()), plot: Some(|d, space, opts| cadcraft_io::plotter::plot(d, space, opts).map_err(|e| e.to_string())), }); let mut s = Session::new(); s.cmdline("line 0,0 100,0").unwrap(); s.cmdline("").unwrap(); s } fn magic(path: &std::path::Path) -> Vec { std::fs::read(path).unwrap().into_iter().take(5).collect() } #[test] fn the_extension_picks_png_svg_or_pdf() { let mut s = session(); let dir = std::env::temp_dir().join(format!("cadcraft-plot-format-{}", std::process::id())); std::fs::create_dir_all(&dir).unwrap(); let cases: [(&str, &[u8], &str); 4] = [("a.png", b"\x89PNG\r", "png"), ("b.svg", b"