use super::*;
use tracing_test::traced_test;
#[test]
#[traced_test]
fn excluded_unit_struct_delegating_to_bare_self_new_is_not_reported() {
let source = r#"
#[cfg_attr(alef, alef(skip))]
pub struct OdtExtractor;
impl OdtExtractor {
pub(crate) fn new() -> Self {
Self
}
}
impl Default for OdtExtractor {
fn default() -> Self {
Self::new()
}
}
"#;
let surface = extract_from_source(source);
let extractor = surface
.types
.iter()
.find(|typ| typ.name == "OdtExtractor")
.expect("OdtExtractor must still be extracted (into the IR) even though it is excluded");
assert!(
extractor.binding_excluded,
"#[cfg_attr(alef, alef(skip))] must set binding_excluded"
);
assert!(
extractor.fields.is_empty(),
"a unit struct has no fields to carry a default"
);
assert!(
!logs_contain("unresolved"),
"a zero-field type's Self::new() -> Self delegation is fully known (there are no \
fields to be wrong about); it must never have been reported as unresolved, excluded or \
not"
);
}
#[test]
#[traced_test]
fn non_excluded_unit_struct_delegating_to_bare_self_new_is_not_reported() {
let source = r#"
pub struct CodeExtractor;
impl CodeExtractor {
pub fn new() -> Self {
Self
}
}
impl Default for CodeExtractor {
fn default() -> Self {
Self::new()
}
}
"#;
let surface = extract_from_source(source);
let extractor = surface
.types
.iter()
.find(|typ| typ.name == "CodeExtractor")
.expect("CodeExtractor must be extracted");
assert!(!extractor.binding_excluded);
assert!(
!logs_contain("unresolved"),
"the bare-Self delegation must resolve cleanly regardless of whether the type is excluded"
);
}
#[test]
#[traced_test]
fn excluded_type_with_a_genuinely_unfoldable_default_is_not_reported() {
let source = r#"
#[alef(skip)]
pub struct WarmedCache {
pub capacity: usize,
}
impl Default for WarmedCache {
fn default() -> Self {
build_warmed_cache()
}
}
"#;
let surface = extract_from_source(source);
let cache = surface
.types
.iter()
.find(|typ| typ.name == "WarmedCache")
.expect("WarmedCache must be extracted");
assert!(cache.binding_excluded, "bare #[alef(skip)] must set binding_excluded");
let capacity = cache
.fields
.iter()
.find(|field| field.name == "capacity")
.expect("capacity field must be extracted");
assert!(
matches!(
capacity.typed_default,
Some(crate::core::ir::DefaultValue::Unresolved(_))
),
"the field must still carry the honest Unresolved marker, not a guessed value: {:?}",
capacity.typed_default
);
assert!(
!logs_contain("unresolved"),
"an excluded type's genuinely unfoldable default must not be logged; it never reaches a \
binding, so the warning is pure noise"
);
}
#[test]
#[traced_test]
fn non_excluded_type_with_the_same_unfoldable_default_still_warns() {
let source = r#"
pub struct WarmedCache {
pub capacity: usize,
}
impl Default for WarmedCache {
fn default() -> Self {
build_warmed_cache()
}
}
"#;
let surface = extract_from_source(source);
let cache = surface
.types
.iter()
.find(|typ| typ.name == "WarmedCache")
.expect("WarmedCache must be extracted");
assert!(!cache.binding_excluded);
assert!(
logs_contain("unresolved"),
"a non-excluded type's genuinely unfoldable default is still actionable (it reaches a \
binding) and must still be reported"
);
}