[roads] QA F-09: a present but empty until: or ports: is key.empty, never absent
Clearing a narrowing field (until:, until: # comment, ports:) used to read as absent, which is the widest value: a permanent grant or all traffic. It is now an error, so the road grants nothing. Three fixtures, FORMATS.md updated, and the F-09 test is no longer ignored.
This commit is contained in:
@@ -16,6 +16,8 @@ pub const MAX_FILE: usize = 256 * 1024;
|
||||
|
||||
pub const REQUIRED: [&str; 4] = ["id", "subject", "verb", "created"];
|
||||
pub const OPTIONAL: [&str; 5] = ["object", "until", "ports", "via", "classic"];
|
||||
/// Optional keys whose absence is their widest value; present but empty is `key.empty`.
|
||||
pub const NARROWING: [&str; 2] = ["until", "ports"];
|
||||
/// The canonical key order.
|
||||
pub const ORDER: [&str; 9] = [
|
||||
"id", "subject", "verb", "object", "until", "ports", "via", "classic", "created",
|
||||
@@ -481,6 +483,23 @@ impl Road {
|
||||
problems.push(p(&f.key, r::KEY_UNKNOWN, "unknown key".into()));
|
||||
}
|
||||
}
|
||||
// A condition that narrows a road is widest when it is absent (no end, all traffic), so a key that is
|
||||
// present but empty is an error, never "absent": clearing a field must not widen a road (QA F-09).
|
||||
for k in NARROWING {
|
||||
if fields
|
||||
.iter()
|
||||
.any(|f| f.key == k && f.value == Value::Absent)
|
||||
{
|
||||
problems.push(p(
|
||||
k,
|
||||
r::KEY_EMPTY,
|
||||
format!(
|
||||
"`{k}:` is empty, which would widen the road to {}; give a value or remove the key",
|
||||
if k == "until" { "a permanent grant" } else { "all traffic" }
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
for k in REQUIRED {
|
||||
if get(k).is_none() {
|
||||
problems.push(
|
||||
|
||||
@@ -15,6 +15,7 @@ pub const KEY_DUPLICATE: &str = "key.duplicate";
|
||||
pub const KEY_MISSING: &str = "key.missing";
|
||||
pub const KEY_FORBIDDEN: &str = "key.forbidden";
|
||||
pub const KEY_TYPE: &str = "key.type";
|
||||
pub const KEY_EMPTY: &str = "key.empty";
|
||||
pub const ID_FORMAT: &str = "id.format";
|
||||
pub const ID_FILE_NAME: &str = "id.file-name";
|
||||
pub const ID_DUPLICATE: &str = "id.duplicate";
|
||||
@@ -78,6 +79,7 @@ pub const ALL: &[&str] = &[
|
||||
KEY_MISSING,
|
||||
KEY_FORBIDDEN,
|
||||
KEY_TYPE,
|
||||
KEY_EMPTY,
|
||||
ID_FORMAT,
|
||||
ID_FILE_NAME,
|
||||
ID_DUPLICATE,
|
||||
|
||||
Reference in New Issue
Block a user