use super::*; use crate::definitions::theme::ThemeDefinition; use serde_json::json; /// RULE: Every shipped definition, board and theme file names a format_version this build reads. /// An upgrade decides what a person's edits carry onto by the format a file is in; a file that does not say is unreadable to it. #[test] fn every_shipped_file_names_a_format_this_build_reads() { for (path, json) in shipped_files() { let raw: Value = serde_json::from_str(json).unwrap_or_else(|error| panic!("{path}: {error}")); check_file(&path, &raw).unwrap_or_else(|error| panic!("{error}")); } } /// RULE: A file without format_version, or with one newer than the build, is refused, and the refusal names the file and both versions. /// A build must never draw a format it cannot read as if it could, and whoever fixes it needs to know which file and which versions. #[test] fn a_file_without_or_beyond_this_builds_format_is_refused_by_name() { let missing = check_file("themes/paper.json", &json!({"id": "paper"})).unwrap_err().to_string(); assert!(missing.contains("themes/paper.json") && missing.contains(&FORMAT_VERSION.to_string()), "{missing}"); let newer = FORMAT_VERSION + 1; let beyond = check_file("todo.json", &json!({"format_version": newer, "id": "todo"})).unwrap_err().to_string(); assert!(beyond.contains("todo.json") && beyond.contains(&newer.to_string()) && beyond.contains(&FORMAT_VERSION.to_string()), "{beyond}"); assert!(check_file("todo.json", &json!({"format_version": "1"})).is_err(), "a version is a number"); assert_eq!(check_file("todo.json", &json!({"format_version": FORMAT_VERSION})).unwrap(), FORMAT_VERSION); // An authored row may leave it out; it may not name a newer one. assert!(check_authored("boards/home.json", &json!({"id": "home"})).is_ok()); assert!(ThemeDefinition::strict(&json!({"id": "own", "format_version": newer})).is_err()); assert!(crate::definitions::board::BoardDefinition::strict(&json!({"format_version": newer, "id": "home", "parts": [{"kind": "head"}]})).is_err()); }