import unittest

from block import BlockType, block_to_block_type


class TestBlock(unittest.TestCase):
    def test_block_to_block_type_when_given_heading_it_should_return_heading(self):
        cases = [
            {"input": "# Importante", "expected": BlockType.HEADING},
            {"input": "## Importante", "expected": BlockType.HEADING},
            {"input": "### Importante", "expected": BlockType.HEADING},
            {"input": "#### Importante", "expected": BlockType.HEADING},
            {"input": "##### Importante", "expected": BlockType.HEADING},
            {"input": "###### Importante", "expected": BlockType.HEADING},
        ]

        for case in cases:
            with self.subTest(inputs=case["input"]):
                result = block_to_block_type(case["input"])
                self.assertEqual(result, case["expected"])

    def test_block_to_block_type_when_given_code_it_should_return_code(self):
        cases = [
            {
                "input": "```\nconsole.log('hello world')\n```",
                "expected": BlockType.CODE,
            },
            {
                "input": "```\nconsole.log('hello world');\nfunction(num) {\n\treturn num;\n}\n```",
                "expected": BlockType.CODE,
            },
            {
                "input": "```js\nconsole.log('hello world');\nfunction(num) {\n\treturn num;\n}\n```",
                "expected": BlockType.CODE,
            },
            {
                "input": "```typescript\nconsole.log('hello world');\nfunction(num) {\n\treturn num;\n}\n```",
                "expected": BlockType.CODE,
            },
        ]

        for case in cases:
            with self.subTest(inputs=case["input"]):
                result = block_to_block_type(case["input"])
                self.assertEqual(result, case["expected"])

    def test_block_to_block_type_when_given_quote_it_should_return_quote(self):
        cases = [
            {
                "input": "> this is\n> a quote\n>about stuff",
                "expected": BlockType.QUOTE,
            },
            {"input": ">this is\n", "expected": BlockType.QUOTE},
            {"input": "> this is", "expected": BlockType.QUOTE},
            {"input": ">this is", "expected": BlockType.QUOTE},
        ]

        for case in cases:
            with self.subTest(inputs=case["input"]):
                result = block_to_block_type(case["input"])
                self.assertEqual(result, case["expected"])

    def test_block_to_block_type_when_given_unordered_it_should_return_unordered(self):
        cases = [
            {
                "input": "- item one\n- item two\n- item three",
                "expected": BlockType.UNORDERED_LIST,
            },
        ]

        for case in cases:
            with self.subTest(inputs=case["input"]):
                result = block_to_block_type(case["input"])
                self.assertEqual(result, case["expected"])

    def test_block_to_block_type_when_given_ordered_it_should_return_unordered(self):
        cases = [
            {
                "input": "1. item one\n2. item two\n3. item three",
                "expected": BlockType.ORDERED_LIST,
            },
        ]

        for case in cases:
            with self.subTest(inputs=case["input"]):
                result = block_to_block_type(case["input"])
                self.assertEqual(result, case["expected"])

    def test_block_to_block_type_when_given_paragraph_it_should_return_paragraph(self):
        cases = [
            {
                "input": "This is a paragraph about nothing.",
                "expected": BlockType.PARAGRAPH,
            },
        ]

        for case in cases:
            with self.subTest(inputs=case["input"]):
                result = block_to_block_type(case["input"])
                self.assertEqual(result, case["expected"])
