use assert_cmd::Command;
use std::fs;
use tempfile::tempdir;
fn run(from: &str, to: &str, input: &str, in_ext: &str, out_ext: &str) -> Result<String, String> {
let dir = tempdir().unwrap();
let inp = dir.path().join(format!("in.{in_ext}"));
let out = dir.path().join(format!("out.{out_ext}"));
fs::write(&inp, input).unwrap();
let result = Command::cargo_bin("sheeter")
.unwrap()
.args([
"convert",
"--from",
from,
"--to",
to,
inp.to_str().unwrap(),
out.to_str().unwrap(),
])
.output()
.unwrap();
if !result.status.success() {
return Err(String::from_utf8_lossy(&result.stderr).to_string());
}
Ok(fs::read_to_string(out).unwrap())
}
#[test]
fn tsv_to_json_cli() {
let json = run("tsv", "json", "name\tage\nAlice\t30", "tsv", "json").unwrap();
assert_eq!(json, r#"[{"name":"Alice","age":"30"}]"#);
}
#[test]
fn json_to_tsv_cli() {
let tsv = run(
"json",
"tsv",
r#"[{"name":"Alice","age":"30"}]"#,
"json",
"tsv",
)
.unwrap();
assert_eq!(tsv, "name\tage\nAlice\t30\n");
}