sheeter-engine 0.11.0

A CLI tool for converting data files between formats. v0.1.0 supports CSV <-> JSON.
Documentation
use sheeter_engine::{detect_content, detect_extension, Format};
use std::path::Path;

#[test]
fn detects_json_array() {
    assert_eq!(detect_content(b"[1,2,3]").unwrap(), Format::Json);
}

#[test]
fn detects_json_object() {
    assert_eq!(detect_content(b"{\"a\":1}").unwrap(), Format::Json);
}

#[test]
fn detects_ndjson() {
    assert_eq!(
        detect_content(b"{\"a\":1}\n{\"a\":2}\n").unwrap(),
        Format::Ndjson
    );
}

#[test]
fn detects_xml() {
    assert_eq!(detect_content(b"<r><a>1</a></r>").unwrap(), Format::Xml);
}

#[test]
fn detects_csv() {
    assert_eq!(
        detect_content(b"name,age\nAlice,30\n").unwrap(),
        Format::Csv
    );
}

#[test]
fn detects_tsv() {
    assert_eq!(
        detect_content(b"name\tage\nAlice\t30\n").unwrap(),
        Format::Tsv
    );
}

#[test]
fn detects_toml() {
    assert_eq!(
        detect_content(b"name = \"Alice\"\nage = 30\n").unwrap(),
        Format::Toml
    );
}

#[test]
fn detects_yaml() {
    assert_eq!(
        detect_content(b"- name: Alice\n  age: 30\n").unwrap(),
        Format::Yaml
    );
}

#[test]
fn bom_stripped_before_detection() {
    let with_bom = b"\xef\xbb\xbfname,age\nAlice,30\n";
    assert_eq!(detect_content(with_bom).unwrap(), Format::Csv);
}

#[test]
fn empty_input_errors() {
    assert!(detect_content(b"").is_err());
}

#[test]
fn extension_csv() {
    assert_eq!(detect_extension(Path::new("data.csv")), Some(Format::Csv));
}

#[test]
fn extension_jsonl_maps_to_ndjson() {
    assert_eq!(
        detect_extension(Path::new("events.jsonl")),
        Some(Format::Ndjson)
    );
}

#[test]
fn extension_unknown_returns_none() {
    assert_eq!(detect_extension(Path::new("data.xyz")), None);
}