Seed optional history values from explicit constructors
This commit is contained in:
@@ -120,7 +120,9 @@ fn seed(schema: &'static Value, depth: usize) -> Result<Value, &'static str> {
|
||||
if let Some(options) = alternatives(schema) {
|
||||
if options
|
||||
.iter()
|
||||
.any(|s| matches_value(s, &json!("NotApplicable"), 0))
|
||||
.filter_map(|s| resolve(s).ok())
|
||||
.filter_map(|s| s.get("enum").and_then(Value::as_array))
|
||||
.any(|values| values.contains(&json!("NotApplicable")))
|
||||
{
|
||||
return Ok(json!("NotApplicable"));
|
||||
}
|
||||
|
||||
@@ -752,6 +752,38 @@ fn choose_history_constructor(draft: &mut Draft, path: &str, label: &str) {
|
||||
draft.shape(&path, value).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_optional_uuid_and_text_seed_absence_without_inventing_observations() {
|
||||
for fact in ["Header/Parent", "Artifact/review/Revision"] {
|
||||
let side = format!("{FACETS}/0/{fact}/oa");
|
||||
let schema = resolve(schema_at(&side).unwrap()).unwrap();
|
||||
assert_eq!(seed(schema, 0).unwrap(), json!("NotApplicable"));
|
||||
let observed_value = alternatives(schema)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|branch| branch_label(branch) == "Observed value")
|
||||
.unwrap();
|
||||
let value = branch_seed(observed_value).unwrap();
|
||||
assert_eq!(value, json!({"Value": null}));
|
||||
assert_eq!(
|
||||
seed(schema_at(&format!("{side}/Value")).unwrap(), 0).unwrap(),
|
||||
Value::Null,
|
||||
"a plain text/UUID shape is not the NotApplicable enum constructor"
|
||||
);
|
||||
if fact == "Header/Parent" {
|
||||
assert_eq!(
|
||||
serde_json::from_value::<Observed<Option<Id>>>(value).unwrap(),
|
||||
Observed::Value(None)
|
||||
);
|
||||
} else {
|
||||
assert_eq!(
|
||||
serde_json::from_value::<Observed<Option<String>>>(value).unwrap(),
|
||||
Observed::Value(None)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_nested_optional_number_events_switch_absent_present_and_recover_invalid_raw() {
|
||||
let (project, id) = fixture(Some(baseline(vec![])));
|
||||
|
||||
Reference in New Issue
Block a user