use super::{ContractId, FlowContract, OwnedFlowContract};
#[test]
fn unknown_output_labels_must_agree_literally() {
let target = FlowContract::new(
ContractId::new("render.v1"),
1,
"LocalCoordinates",
"CanvasFrame",
);
let different = FlowContract::new(
ContractId::new("render.v1"),
1,
"LocalCoordinates",
"TotallyDifferentType",
);
assert!(!target.semantically_compatible_with(different));
assert!(target.semantically_compatible_with(target));
}
#[test]
fn known_domains_keep_accepting_spelling_differences() {
let target = FlowContract::new(
ContractId::new("render.v1"),
1,
"LocalCoordinates",
"CanvasFrame",
);
let respelled = FlowContract::new(
ContractId::new("render.v1"),
1,
"local_coordinates",
"CanvasFrame",
);
assert!(target.semantically_compatible_with(respelled));
let respelled_with_other_output = FlowContract::new(
ContractId::new("render.v1"),
1,
"local_coordinates",
"TotallyDifferentType",
);
assert!(!target.semantically_compatible_with(respelled_with_other_output));
}
#[test]
fn static_and_owned_flow_contracts_compare_identically() {
let cases = [
("render.v1", 1, "LocalCoordinates", "CanvasFrame"),
("render.v1", 1, "local_coordinates", "CanvasFrame"),
("render.v1", 1, "LocalCoordinates", "TotallyDifferentType"),
("render.v1", 2, "LocalCoordinates", "CanvasFrame"),
("render.v2", 1, "LocalCoordinates", "CanvasFrame"),
("", 0, "", ""),
];
for &(id, version, input, output) in &cases {
for &(other_id, other_version, other_input, other_output) in &cases {
let left = FlowContract::new(ContractId::new(id), version, input, output);
let right = FlowContract::new(
ContractId::new(other_id),
other_version,
other_input,
other_output,
);
let owned_left = OwnedFlowContract::from(left);
let owned_right = OwnedFlowContract::from(right);
assert_eq!(
left.is_declared(),
owned_left.is_declared(),
"is_declared disagrees for {left:?}"
);
assert_eq!(
left.compatible_with(right),
owned_left == owned_right,
"literal comparison disagrees for {left:?} vs {right:?}"
);
assert_eq!(
left.semantically_compatible_with(right),
owned_left.semantically_compatible_with(&owned_right),
"semantic comparison disagrees for {left:?} vs {right:?}"
);
}
}
}
#[test]
fn compatible_with_stays_literal_while_the_semantic_entry_point_folds_spellings() {
let literal = FlowContract::new(
ContractId::new("render.v1"),
1,
"LocalCoordinates",
"CanvasFrame",
);
let respelled = FlowContract::new(
ContractId::new("render.v1"),
1,
"local_coordinates",
"CanvasFrame",
);
assert!(
!literal.compatible_with(respelled),
"compatible_with must stay a literal comparison"
);
assert!(
literal.semantically_compatible_with(respelled),
"the semantic entry point folds known-domain spellings"
);
assert_eq!(
literal.compatible_with(respelled),
OwnedFlowContract::from(literal) == OwnedFlowContract::from(respelled)
);
assert_eq!(
literal.semantically_compatible_with(respelled),
OwnedFlowContract::from(literal)
.semantically_compatible_with(&OwnedFlowContract::from(respelled))
);
}