"""Tests for ContentIntelligenceService: rule-based content classification.""" import re import pytest from services.content_intelligence_service import ( _COMPARISON_RE, _IMAGE_REF_RE, _LIST_RE, _METRIC_RE, _QUOTE_RE, _TABLE_RE, _TIMELINE_RE, ) class TestMetricRegex: @pytest.mark.parametrize("text", [ "$2.3M revenue", "45% growth", "1,200 units", "revenue grew 45%", "profit increased by $2M", "ROI of 340%", "CAGR 12%", ]) def test_detects_metrics(self, text): assert _METRIC_RE.search(text), f"Failed to detect metric: {text}" @pytest.mark.parametrize("text", [ "The cat sat on the mat", "We had a meeting yesterday", ]) def test_rejects_non_metrics(self, text): assert not _METRIC_RE.search(text) class TestQuoteRegex: def test_detects_quoted_text(self): text = '"Innovation is the ability to see change as an opportunity" — John Doe' assert _QUOTE_RE.search(text) def test_detects_smart_quotes(self): text = '\u201cThis is a quoted statement\u201d' assert _QUOTE_RE.search(text) def test_rejects_short_quotes(self): text = '"Hi"' assert not _QUOTE_RE.search(text) class TestTableRegex: def test_detects_markdown_table(self): text = "| Name | Value |\n| --- | --- |\n| A | 1 |" assert _TABLE_RE.search(text) def test_rejects_non_table(self): text = "This is just normal text" assert not _TABLE_RE.search(text) class TestTimelineRegex: @pytest.mark.parametrize("text", [ "In 2023, we launched the product", "Q1 results were strong", "January 2024 earnings", ]) def test_detects_timeline(self, text): assert _TIMELINE_RE.search(text) class TestComparisonRegex: @pytest.mark.parametrize("text", [ "Plan A vs. Plan B", "compared to last year", "in contrast to competitors", "on the other hand, they chose", ]) def test_detects_comparison(self, text): assert _COMPARISON_RE.search(text) class TestListRegex: def test_detects_bullet_list(self): text = "- Item one\n- Item two\n- Item three" matches = _LIST_RE.findall(text) assert len(matches) == 3 def test_detects_asterisk_list(self): text = "* First\n* Second" assert _LIST_RE.search(text) class TestImageRefRegex: @pytest.mark.parametrize("text", [ "See figure 1 below", "see diagram for details", "image.png", "![alt text](photo.jpg)", "attached image shows", ]) def test_detects_image_references(self, text): assert _IMAGE_REF_RE.search(text)