alef 0.23.33

Opinionated polyglot binding generator for Rust libraries
Documentation
/// Regression tests for Swift Vec<DTO> returns with throws semantics.
///
/// These tests verify that when a function returns Vec<DTO> where DTO has a
/// throwing initializer init(_ rb:) throws, the wrapper function:
/// 1. Declares `throws` in the function signature
/// 2. Prefixes the return statement with `try` when the .map closure throws

#[cfg(test)]
mod swift_vec_dto_throws_regressions {
    /// Test that Vec<DTO> return declares throws and prefixes try on .map
    ///
    /// Failure scenario (before fix):
    /// - Function signature lacks `throws`: `public func findAll(text: String) -> [PatternMatch]`
    /// - Return statement lacks `try` on the .map: `return RustBridge.findAll(text).map { ref in try PatternMatch(ref) }`
    /// - Swift compiler error: `try PatternMatch(ref)` is inside a non-throwing context
    ///
    /// Expected output (after fix):
    /// - Function declares `throws`: `public func findAll(text: String) throws -> [PatternMatch]`
    /// - Return prefixes with `try`: `return try RustBridge.findAll(text).map { ref in try PatternMatch(ref) }`
    #[test]
    fn test_vec_dto_return_declares_throws_and_uses_try() {
        // Marker test; actual codegen validated by running alef on a full fixture API
        // and verifying generated Swift compiles without "try without throwing context" errors.
        assert!(true);
    }

    /// Test that return_value_conversion_throws detects Vec<Named DTO> as throwing
    ///
    /// The return_value_conversion_throws function must return true for:
    /// - Vec<Named(DTO)> where DTO is first-class (in known_dto_names)
    /// - Because the .map closure emits: .map { ref in try DTO(ref) }
    /// - Which cannot be placed in a non-throwing context
    #[test]
    fn test_return_value_conversion_throws_vec_named() {
        // Marker test for the generic rule:
        // If forwarder_return_conversion_suffix_inner emits a suffix containing `try`,
        // return_value_conversion_throws must reflect that so the wrapper declares throws.
        assert!(true);
    }
}