import unittest
import makesite


class StripHtmlTagsTest(unittest.TestCase):

    def test_simple_tag(self):
        """Test removing a simple HTML tag."""
        text = "<p>Hello World</p>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Hello World")

    def test_multiple_tags(self):
        """Test removing multiple HTML tags."""
        text = "<h1>Title</h1><p>Paragraph</p><div>Content</div>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "TitleParagraphContent")

    def test_nested_tags(self):
        """Test removing nested HTML tags."""
        text = "<div><p>Nested <strong>content</strong> here</p></div>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Nested content here")

    def test_self_closing_tags(self):
        """Test removing self-closing tags."""
        text = "Line 1<br/>Line 2<hr/>Line 3"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Line 1Line 2Line 3")

    def test_tags_with_attributes(self):
        """Test removing tags with attributes."""
        text = '<a href="http://example.com" class="link">Click here</a>'
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Click here")

    def test_tags_with_multiple_attributes(self):
        """Test removing tags with multiple attributes."""
        text = '<img src="image.jpg" alt="Picture" width="100" height="200"/>'
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "")

    def test_no_tags(self):
        """Test text with no HTML tags."""
        text = "Just plain text without any tags"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Just plain text without any tags")

    def test_empty_string(self):
        """Test with empty string."""
        text = ""
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "")

    def test_only_tags(self):
        """Test string with only tags and no text."""
        text = "<div></div><p></p><span></span>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "")

    def test_mixed_content(self):
        """Test realistic HTML content."""
        text = "<p>This is a <strong>bold</strong> statement with a <a href='#'>link</a>.</p>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "This is a bold statement with a link.")

    def test_malformed_tag_unclosed(self):
        """Test with unclosed tag."""
        text = "<p>Unclosed paragraph"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Unclosed paragraph")

    def test_tag_with_newlines(self):
        """Test tags spanning multiple lines - function doesn't handle this case."""
        text = """<div
        class="container"
        id="main">Content</div>"""
        result = makesite._strip_html_tags(text)
        # The function's regex doesn't match tags with newlines in them
        # So the opening tag remains, but closing tag is removed
        self.assertIn("Content", result)

    def test_special_characters_outside_tags(self):
        """Test that special characters outside tags are preserved."""
        text = "<p>Special chars: &amp; &lt; &gt; &quot;</p>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Special chars: &amp; &lt; &gt; &quot;")

    def test_html5_tags(self):
        """Test removing HTML5 semantic tags."""
        text = "<article><header>Title</header><section>Content</section></article>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "TitleContent")

    def test_script_and_style_tags(self):
        """Test removing script and style tags."""
        text = "<style>body{color:red;}</style><p>Text</p><script>alert('hi');</script>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "body{color:red;}Textalert('hi');")

    def test_comment_like_text(self):
        """Test HTML comments (not removed by this function)."""
        text = "<!-- This is a comment --><p>Text</p>"
        result = makesite._strip_html_tags(text)
        # Comments are not removed by strip_html_tags, only tags are
        self.assertIn("Text", result)

    def test_tags_with_numbers(self):
        """Test tags with numbers in the name."""
        text = "<h1>Header 1</h1><h2>Header 2</h2><h3>Header 3</h3>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Header 1Header 2Header 3")

    def test_preserves_whitespace(self):
        """Test that whitespace is preserved."""
        text = "<p>Word1   Word2\n  Word3</p>"
        result = makesite._strip_html_tags(text)
        self.assertEqual(result, "Word1   Word2\n  Word3")
