Skip to content

Commit

Permalink
H-3430: Implement folding for anyOf constraints (#5404)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Oct 18, 2024
1 parent a51ce8e commit 3842c47
Show file tree
Hide file tree
Showing 3 changed files with 440 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub enum ResolveClosedDataTypeError {
ConflictingConstEnumValue(JsonValue, Vec<JsonValue>),
#[error("The constraint is unsatisfiable: {}", json!(.0))]
UnsatisfiableConstraint(ValueConstraints),
#[error("The combined constraints results in an empty `anyOf`")]
EmptyAnyOf,
}

impl ClosedDataType {
Expand Down Expand Up @@ -431,10 +433,7 @@ mod tests {
);
assert_eq!(number.label, defs.number.label);
assert_eq!(number.r#abstract, defs.number.r#abstract);
assert_eq!(
json!(number.all_of),
json!([defs.number.constraints, defs.value.constraints])
);
assert_eq!(json!(number.all_of), json!([defs.number.constraints]));
}

fn check_closed_integer(integer: &ClosedDataType, defs: &DataTypeDefinitions) {
Expand All @@ -450,10 +449,7 @@ mod tests {
);
assert_eq!(integer.label, defs.number.label);
assert_eq!(integer.r#abstract, defs.integer.r#abstract);
assert_eq!(
json!(integer.all_of),
json!([defs.integer.constraints, defs.value.constraints])
);
assert_eq!(json!(integer.all_of), json!([defs.integer.constraints]));
}

fn check_closed_unsigned(unsigned: &ClosedDataType, defs: &DataTypeDefinitions) {
Expand All @@ -469,10 +465,7 @@ mod tests {
);
assert_eq!(unsigned.label, defs.number.label);
assert_eq!(unsigned.r#abstract, defs.unsigned.r#abstract);
assert_eq!(
json!(unsigned.all_of),
json!([defs.unsigned.constraints, defs.value.constraints])
);
assert_eq!(json!(unsigned.all_of), json!([defs.unsigned.constraints]));
}

fn check_closed_unsigned_int(unsigned_int: &ClosedDataType, defs: &DataTypeDefinitions) {
Expand All @@ -496,8 +489,7 @@ mod tests {
"minimum": 0.0,
"maximum": 4_294_967_295.0,
"multipleOf": 1.0,
},
defs.value.constraints
}
])
);
}
Expand All @@ -515,10 +507,7 @@ mod tests {
);
assert_eq!(small.label, defs.small.label);
assert_eq!(small.r#abstract, defs.small.r#abstract);
assert_eq!(
json!(small.all_of),
json!([defs.small.constraints, defs.value.constraints])
);
assert_eq!(json!(small.all_of), json!([defs.small.constraints]));
}

fn check_closed_unsigned_small_int(
Expand Down Expand Up @@ -551,8 +540,7 @@ mod tests {
"minimum": 0.0,
"maximum": 100.0,
"multipleOf": 1.0,
},
defs.value.constraints
}
])
);
}
Expand Down
Loading

0 comments on commit 3842c47

Please sign in to comment.