use super::*;
use crate::diagnostic_codes::Code;
fn diagnostic_codes(source: &str) -> Vec<Code> {
check_source(source).into_iter().map(|d| d.code).collect()
}
#[test]
fn returning_owned_binding_without_owned_return_type_warns() {
let codes = diagnostic_codes(
r#"
pipeline main() {
fn leak() -> channel {
let ch: owned<channel> = channel("leak", 4)
return ch
}
leak()
}
"#,
);
assert!(
codes.contains(&Code::OwnershipEscape),
"expected HARN-OWN-003 for `return ch` from `owned<channel>` binding, got: {codes:?}"
);
}
#[test]
fn returning_owned_binding_with_owned_return_type_is_silent() {
let codes = diagnostic_codes(
r#"
pipeline main() {
fn transfer() -> owned<channel> {
let ch: owned<channel> = channel("transfer", 4)
return ch
}
transfer()
}
"#,
);
assert!(
!codes.contains(&Code::OwnershipEscape),
"ownership transfer through `owned<T>` return type should not warn, got: {codes:?}"
);
}
#[test]
fn returning_non_owned_binding_is_silent() {
let codes = diagnostic_codes(
r#"
pipeline main() {
fn passthrough() -> channel {
let ch = channel("ok", 4)
return ch
}
passthrough()
}
"#,
);
assert!(
!codes.contains(&Code::OwnershipEscape),
"non-owned binding return must not fire HARN-OWN-003, got: {codes:?}"
);
}