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")])
}
#[cfg(not(feature = "update-expectations"))]
macro_rules! check_obj {
($obj:expr) => {{
let obj = $obj;
assert_eq!(obj.a, 1.5e2);
assert_eq!(obj.b, 3);
assert_eq!(obj.c, "string");
}};
}
#[cfg(not(feature = "update-expectations"))]
macro_rules! test_obj {
($module:ident) => {{
use $module::Foo;
Foo {
a: 1.5e2,
b: 3,
c: "string".into(),
}
}};
}
#[test]
fn generate_default() {
generate_test(
"tests/feature/extension_base/schema.xsd",
"tests/feature/extension_base/expected/default.rs",
config(),
);
}
#[cfg(not(feature = "update-expectations"))]
mod quick_xml {
#![allow(unused_imports)]
include!("expected/quick_xml.rs");
}
#[cfg(not(feature = "update-expectations"))]
mod default {
#![allow(unused_imports)]
include!("expected/default.rs");
}
#[test]
fn generate_quick_xml() {
generate_test(
"tests/feature/extension_base/schema.xsd",
"tests/feature/extension_base/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/extension_base/example/default.xml",
);
check_obj!(obj);
}
#[test]
#[cfg(not(feature = "update-expectations"))]
fn write_quick_xml() {
let obj = test_obj!(quick_xml);
crate::utils::quick_xml_write_test(
&obj,
"tns:Foo",
"tests/feature/extension_base/example/serialize.xml",
);
}
#[test]
fn generate_serde_xml_rs() {
generate_test(
"tests/feature/extension_base/schema.xsd",
"tests/feature/extension_base/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/extension_base/example/default.xml",
);
check_obj!(obj);
}
#[cfg(not(feature = "update-expectations"))]
mod serde_xml_rs {
#![allow(unused_imports)]
include!("expected/serde_xml_rs.rs");
}
#[test]
fn generate_serde_quick_xml() {
generate_test(
"tests/feature/extension_base/schema.xsd",
"tests/feature/extension_base/expected/serde_quick_xml.rs",
config().with_serde_quick_xml(),
);
}
#[test]
#[cfg(not(feature = "update-expectations"))]
fn read_serde_quick_xml() {
use serde_quick_xml::Foo;
let obj = crate::utils::serde_quick_xml_read_test::<Foo, _>(
"tests/feature/extension_base/example/default.xml",
);
check_obj!(obj);
}
#[cfg(not(feature = "update-expectations"))]
mod serde_quick_xml {
#![allow(unused_imports)]
include!("expected/serde_quick_xml.rs");
}