scheme-edit 0.2.0

Lossless Scheme S-expression parser and editor (toml_edit-style CST)
Documentation
use scheme_edit::{list, quoted_sym, string_lit, sym, Node};

fn channel_node() -> Node {
    list(vec![
        sym("channel"),
        list(vec![sym("name"), quoted_sym("pantherx")]),
        list(vec![
            sym("url"),
            string_lit("https://codeberg.org/gofranz/panther.git"),
        ]),
        list(vec![sym("branch"), string_lit("master")]),
        list(vec![
            sym("introduction"),
            list(vec![
                sym("make-channel-introduction"),
                string_lit("54b4056ac571611892c743b65f4c47dc298c49da"),
                list(vec![
                    sym("openpgp-fingerprint"),
                    string_lit("A36A D41E ECC7 A871 1003  5D24 524F EB1A 9D33 C9CB"),
                ]),
            ]),
        ]),
    ])
}

#[test]
fn short_form_stays_flat() {
    assert_eq!(
        list(vec![sym("name"), quoted_sym("guix")]).to_pretty(0),
        "(name 'guix)"
    );
}

#[test]
fn channel_breaks_like_guix() {
    assert_eq!(
        channel_node().to_pretty(0),
        "(channel\n  (name 'pantherx)\n  (url \"https://codeberg.org/gofranz/panther.git\")\n  (branch \"master\")\n  (introduction\n    (make-channel-introduction\n      \"54b4056ac571611892c743b65f4c47dc298c49da\"\n      (openpgp-fingerprint\n        \"A36A D41E ECC7 A871 1003  5D24 524F EB1A 9D33 C9CB\"))))"
    );
}

#[test]
fn pretty_output_reparses_identically() {
    let n = channel_node();
    let doc = scheme_edit::Document::parse(&n.to_pretty(0)).unwrap();
    let reparsed = doc.forms().next().unwrap();
    assert_eq!(reparsed.to_pretty(0), n.to_pretty(0));
}