def test_citation_extraction_edge_cases(self):
        """Test citation extraction with edge cases and malformed citations."""
        # Test function to extract citations that exactly matches the implementation in core.utils
        def extract_citations(text):
            # Handle None or empty input
            if text is None or text == "":
                return []

            # Match the core implementation pattern: 7-8 alphanumeric chars
            citation_pattern = re.compile(r"\[([A-Za-z0-9]{7,8})\]")

            sids = []
            for match in citation_pattern.finditer(text):
                sid = match.group(1)
                sids.append(sid)

            return sids

        # Edge case tests
        test_cases = [
            (
                "Incomplete citation [abc1234",  # Missing closing bracket
                []  # This would not match with the regular pattern
            ),
            (
                "Empty citation []",  # Empty citation
                []  # This would match but capture an empty string
            ),
            (
                "Citation with special chars [abc-1234]",  # Contains hyphen
                []  # Should not capture because hyphen is not allowed in the pattern
            ),
            (
                "Citation at the end of sentence[abcd1234].",  # No space before citation
                ["abcd1234"]  # Should still capture
            ),
            (
                "Valid citation [abc1234]",  # Valid citation
                ["abc1234"]  # Should capture
            ),
            (
                "Text with [short] but no valid citation format.",  # 'short' is only 5 chars, too short
                []  # Should not extract non-citation brackets with wrong length
            ),
            (
                "Text with [abc123] (too short) and [abcdefghi] (too long).",
                []  # Should not extract brackets with wrong length
            ),
            (
                "Text with [abc-1234] has the right length but contains special characters.",
                []  # Should not extract brackets with special characters
            ),
        ]

        # Run tests
        for text, expected_citations in test_cases:
            extracted = extract_citations(text)
            assert extracted == expected_citations
Test citation extraction with edge cases and malformed citations.
py/tests/unit/retrieval/test_citations.py