xsd-parser 1.5.2

Rust code generator for XML schema files
Documentation
use xsd_parser::{config::SerdeXmlRsVersion, Config, IdentType};

use crate::utils::{generate_test, ConfigEx};

fn config() -> Config {
    Config::test_default().with_generate([
        (IdentType::Element, "tns:Foo"),
        (IdentType::Element, "tns:ListOfMyStrings"),
    ])
}

#[cfg(not(feature = "update-expectations"))]
macro_rules! check_obj {
    ($obj:expr) => {{
        let obj = $obj;

        assert_eq!(
            obj.a_list.0,
            vec![
                String::from("one"),
                String::from("two"),
                String::from("three")
            ]
        );
    }};
}

#[cfg(not(feature = "update-expectations"))]
macro_rules! test_obj {
    ($module:ident) => {{
        use $module::{Foo, ListType};

        Foo {
            a_list: ListType(vec![
                String::from("one"),
                String::from("two"),
                String::from("three"),
            ]),
        }
    }};
}

/* default */

#[test]
fn generate_default() {
    generate_test(
        "tests/feature/list/schema.xsd",
        "tests/feature/list/expected/default.rs",
        config(),
    );
}

#[cfg(not(feature = "update-expectations"))]
mod default {
    #![allow(unused_imports)]

    include!("expected/default.rs");
}

/* quick_xml */

#[test]
fn generate_quick_xml() {
    generate_test(
        "tests/feature/list/schema.xsd",
        "tests/feature/list/expected/quick_xml.rs",
        config().with_quick_xml(),
    );
}

#[test]
#[cfg(not(feature = "update-expectations"))]
fn read_quick_xml() {
    use quick_xml::Foo;

    let obj = crate::utils::quick_xml_read_test::<Foo, _>("tests/feature/list/example/default.xml");

    check_obj!(obj);
}

#[test]
#[cfg(not(feature = "update-expectations"))]
fn read_quick_xml_different_separators() {
    use quick_xml::Foo;

    let obj = crate::utils::quick_xml_read_test::<Foo, _>(
        "tests/feature/list/example/different_separators.xml",
    );

    assert_eq!(
        obj.a_list.0,
        vec![String::from("one,two"), String::from("three")]
    );
}

#[test]
#[cfg(not(feature = "update-expectations"))]
fn read_quick_xml_list_of_my_strings() {
    use quick_xml::ListOfMyStrings;

    let obj = crate::utils::quick_xml_read_test::<ListOfMyStrings, _>(
        "tests/feature/list/example/list_of_my_strings.xml",
    );

    let expected = ["1", "2", "3", "4", "5,6", "7.8", "9"]
        .into_iter()
        .map(String::from)
        .collect::<Vec<_>>();

    assert_eq!(obj.0, expected);
}

#[test]
#[cfg(not(feature = "update-expectations"))]
fn write_quick_xml() {
    let obj = test_obj!(quick_xml);

    crate::utils::quick_xml_write_test(&obj, "Foo", "tests/feature/list/example/default.xml");
}

#[cfg(not(feature = "update-expectations"))]
mod quick_xml {
    #![allow(unused_imports)]

    include!("expected/quick_xml.rs");
}

/* serde_xml_rs */

#[test]
fn generate_serde_xml_rs() {
    generate_test(
        "tests/feature/list/schema.xsd",
        "tests/feature/list/expected/serde_xml_rs.rs",
        config().with_serde_xml_rs(SerdeXmlRsVersion::Version08AndAbove),
    );
}

#[test]
#[cfg(not(feature = "update-expectations"))]
fn read_serde_xml_rs() {
    use serde_xml_rs::Foo;

    let obj =
        crate::utils::serde_xml_rs_read_test::<Foo, _>("tests/feature/list/example/default.xml");

    check_obj!(obj);
}

#[cfg(not(feature = "update-expectations"))]
mod serde_xml_rs {
    #![allow(unused_imports)]

    include!("expected/serde_xml_rs.rs");
}