66 lines · 3.3 KB · RustRaw
//! Opened faces consume definition slots; the engine owns their words.use cotton_core::definitions::TableDefinition;use cotton_core::records::card::{resolve, Around};use cotton_core::records::page::Words;use cotton_core::rules::shell_lines::LineSet;use serde_json::{json, Value};fn definition(id: &str) -> TableDefinition { let path = cotton_store::manifest_dir().join(format!("kits/personal/tables/{id}.json")); let table = TableDefinition::from_json(&std::fs::read_to_string(path).unwrap()).unwrap(); table.validate().unwrap(); table}fn fields(id: &str, data: Value) -> std::collections::BTreeMap<String, Value> { let table = definition(id); let now = chrono::DateTime::parse_from_rfc3339("2026-11-01T12:00:00Z").unwrap().with_timezone(&chrono::Utc); let card = resolve(table.card.as_ref().unwrap(), &table, "sample", data.as_object().unwrap(), "Asia/Kolkata", now, Words::shipped(), &LineSet::shipped("cards").unwrap(), Around::default()).unwrap(); card.fields.into_iter().collect()}#[test]fn receipt_keeps_category_period_notes_and_status_without_changing_deck_state() { let fields = fields("transaction", json!({"description":"Sample purchase", "tag":"supplies", "for_period":"November 2026", "notes":"Synthetic receipt notes", "status":"proposed", "certainty":"estimate"})); assert_eq!(fields["tag"], "supplies"); assert_eq!(fields["period"], "November 2026"); assert_eq!(fields["body"], "Synthetic receipt notes"); assert!(fields.contains_key("note")); assert!(!fields.contains_key("state"), "the deck still stamps only expected transactions");}#[test]fn photo_keeps_city_and_camera_and_calendar_keeps_the_address() { let photo = fields("photo", json!({"place_city":"Sample city", "camera_make":"Example", "camera_model":"35"})); assert_eq!(photo["city"], "Sample city"); let camera = photo["model"].as_str().unwrap(); assert!(camera.contains("Example") && camera.contains("35")); let event = fields("event", json!({"event_place":"Sample hall", "country":"India", "notes":"Synthetic board notes"})); let address = event["city"].as_str().unwrap(); assert!(address.contains("Sample hall") && address.contains("India")); assert_eq!(event["body"], "Synthetic board notes");}#[test]fn todo_history_is_dated_and_recurrence_is_said_in_words() { let todo = fields("todo", json!({"title":"Synthetic task", "status":"done", "created_at":"2026-10-22T10:00:00Z", "completed_at":"2026-10-29T10:00:00Z", "repeats":"weekly"})); assert!(todo["started"].as_str().unwrap().contains("22 Oct")); assert!(todo["expires"].as_str().unwrap().contains("29 Oct")); assert!(!todo["repeats"].as_str().unwrap().is_empty());}#[test]fn people_index_declares_all_four_filtered_relationships() { let person = definition("person"); let related = person.related.unwrap(); let actual: Vec<_> = related.iter().map(|r| (r.table.as_str(), r.column.as_deref().unwrap())).collect(); assert_eq!(actual, [("thread", "member_people"), ("photo", "people"), ("event", "people"), ("todo", "people")]); for id in ["photo", "event"] { let table = definition(id); let field = table.card.unwrap().fields.into_iter().find(|f| format!("{:?}",f.slot) == "People").unwrap(); assert!(field.max.is_none(), "opened faces receive every person"); }}