use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use openusd::sdf;
use openusd_build::Views;
mod common;
#[allow(
dead_code,
reason = "the table names every property of the fixture; this reads the values, not the names"
)]
mod generated {
include!("values/generated.rs");
}
fn fixture() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/values")
}
fn fields(data: &sdf::Data) -> BTreeMap<String, sdf::Value> {
data.iter()
.flat_map(|(path, spec)| {
spec.fields
.iter()
.map(move |(field, value)| (format!("{path}.{field}"), value.clone()))
})
.collect()
}
#[test]
fn compiled_values_match_the_model() {
let output = openusd_build::configure()
.search_path(fixture())
.build_library(fixture().join("schema.usda"), Views::Skip)
.expect("the values fixture builds");
common::matches(
&Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/values/generated.rs"),
&output.rust,
);
let from_model = output.with_family(|family| fields(&family.to_data().expect("the declarations build")));
let from_table = fields(&generated::SCHEMAS.to_data().expect("the compiled table builds"));
assert_eq!(
from_table.keys().collect::<Vec<_>>(),
from_model.keys().collect::<Vec<_>>(),
"the two carry the same fields"
);
for (field, value) in &from_model {
assert_eq!(&from_table[field], value, "{field} does not rebuild");
}
let kinds: Vec<sdf::ValueKind> = from_model.values().map(sdf::ValueKind::from).collect();
for expected in [
sdf::ValueKind::ValueBlock,
sdf::ValueKind::Dictionary,
sdf::ValueKind::Matrix2d,
sdf::ValueKind::Matrix3d,
sdf::ValueKind::Matrix4d,
sdf::ValueKind::Half,
sdf::ValueKind::Quath,
sdf::ValueKind::TimeCode,
sdf::ValueKind::AssetPath,
] {
assert!(kinds.contains(&expected), "the fixture declares a {expected:?}");
}
}