//! What a deck admits, by its columns' types. use serde_json::json; use super::*; use crate::definitions::TableDefinition; use crate::ink::shipped; fn table(columns: &[(&str, &str)], title: &str, figure: Option<&str>, search: &[&str]) -> TableDefinition { serde_json::from_value(json!({ "id": "t", "name": "T", "plural": "Ts", "picture": null, "builtin": false, "engine": null, "title": title, "date": null, "project": null, "order": null, "slip": { "title": title, "subtitle": null, "trailing": null, "photo": null, "toggle": null, "figure": figure }, "tile": { "face": "slip-list" }, "page": [], "instructions": "T.", "search": search, "columns": columns.iter().map(|(key, kind)| json!({"key": key, "type": kind})).collect::>(), })) .unwrap() } /// RULE (owner, 3 Nov 2026: "I also want to include having numbers"): a deck admits what its columns hold together, by their types: text letters, an amount or a number digits, both where they mix; a type the alphabet does not name holds neither; a pick of people reads by their names. #[test] fn a_deck_admits_what_its_columns_hold() { let alphabet = shipped(); let people = table(&[("full_name", "text"), ("org", "text"), ("city", "place"), ("phones", "text")], "full_name", None, &["full_name", "org", "city"]); assert_eq!(deck(&people, alphabet), Admits::LETTERS, "a deck of names takes letters only"); assert_eq!(deck(&table(&[("amount_minor", "amount")], "amount_minor", None, &[]), alphabet), Admits::DIGITS, "an amount digits only"); assert_eq!(deck(&table(&[("count", "number")], "count", None, &[]), alphabet), Admits::DIGITS); let money = table(&[("description", "text"), ("tag", "text"), ("amount_minor", "amount")], "description", Some("amount_minor"), &["description", "tag"]); assert_eq!(deck(&money, alphabet), Admits::EVERY, "words and an amount together: both"); assert_eq!(deck(&table(&[("site", "url")], "site", None, &[]), alphabet), Admits::EVERY, "a web address is mixed text"); assert_eq!(deck(&table(&[("shot", "photo")], "shot", None, &[]), alphabet), Admits::default(), "a photo holds no letter"); assert_eq!(pick(&people, alphabet), Admits::LETTERS, "a pick of people reads by their names"); assert_eq!(pick(&money, alphabet), Admits::LETTERS, "a pick reads by the title alone, never the figure"); }