74 lines · 3.0 KB · RustRaw
use cotton_core::definitions::{builtin_table_definitions, theme::ThemeDefinition, ColumnType};fn drawable(object: &str) -> bool { // Drawn values and the two historical aliases are renderer vocabulary; // every other word must name a shipped enamel asset. matches!( object, "leaf" | "clock" | "words" | "figure" | "ring" | "cap" | "people" | "print" | "gauge" | "note" | "check" ) || cotton_store::manifest_dir() .join("../../apps/loom/Sources/CottonPaper/Media.xcassets") .join(format!("object-{object}.imageset/Contents.json")) .is_file()}/// RULE: Every shipped field card resolves an object in every shipped theme; otherwise a definition can silently deal a card with no drawing vocabulary.#[test]fn every_shipped_card_resolves_an_object() { for theme in ThemeDefinition::builtins() { let objects = theme .objects .as_ref() .expect("a shipped theme declares its objects"); for table in builtin_table_definitions() { table.validate().unwrap_or_else(|error| panic!("{}: {error}", table.id)); let parts = table.resolved_parts(); for card in parts.cards.iter().chain(parts.strip.iter()).flatten() { let Some(key) = &card.column else { continue }; let column = table .columns .iter() .find(|column| &column.key == key) .expect("a card names a declared column"); // The renderer reads bytes/amounts as figures, places as words, // and photo columns as pictures. Links may refine their object // from the linked definition after this empty-field reading. let kind = match column.column_type { ColumnType::Text | ColumnType::Longtext | ColumnType::AccountNumber | ColumnType::Url | ColumnType::Place => "text", ColumnType::Date => "date", ColumnType::Time => "time", ColumnType::Number | ColumnType::Bytes | ColumnType::Amount => "figure", ColumnType::Choice => "choice", ColumnType::Link => "link", ColumnType::Photo => "picture", ColumnType::File => "file", ColumnType::Bool => "toggle", }; let object = card .object .as_deref() .or_else(|| objects.get(kind).and_then(serde_json::Value::as_str)); assert!( object.is_some_and(drawable), "{}/{key} has no object in {}", table.id, theme.id ); } } }}