#!/usr/bin/env python

"""Test suite for rstcheck."""

from __future__ import unicode_literals

import unittest

import rstcheck


class Tests(unittest.TestCase):

    def assert_lines_equal(self, line_numbers, results):
        self.assertEqual(line_numbers,
                         list(dict(results).keys()))

    def test_parse_gcc_style_error_message(self):
        self.assertEqual(
            (32, 'error message'),
            rstcheck.parse_gcc_style_error_message(
                'filename:32:7: error message',
                filename='filename'))

    def test_parse_gcc_style_error_message_with_no_column(self):
        self.assertEqual(
            (32, 'error message'),
            rstcheck.parse_gcc_style_error_message(
                'filename:32: error message',
                filename='filename',
                has_column=False))

    def test_parse_gcc_style_error_message_with_parsing_error(self):
        with self.assertRaises(ValueError):
            rstcheck.parse_gcc_style_error_message(
                ':32:3 error message',
                filename='filename')

        with self.assertRaises(IndexError):
            rstcheck.parse_gcc_style_error_message(
                'filename:32: error message',
                filename='filename',
                has_column=True)

    def test_check(self):
        self.assert_lines_equal(
            [6],
            rstcheck.check(
                """\
Test
====

.. code-block:: python

    print(
"""))

    def test_check_json(self):
        self.assert_lines_equal(
            [7],
            rstcheck.check(
                """\
Test
====

.. code-block:: json

    {
        'abc': 123
    }
"""))

    def test_check_with_extra_blank_lines(self):
        self.assert_lines_equal(
            [6],
            rstcheck.check(
                """\
Test
====

.. code-block:: python

    print(



"""))

    def test_check_nested_rst(self):
        self.assert_lines_equal(
            [32],
            rstcheck.check(
                """\
Test
====

.. code-block:: rst

    Test
    ====

    .. code-block:: rst


        Test
        ====

        .. code-block:: rst

            Test
            ====

            .. code-block:: rst

                Test
                ====

                .. code-block:: rst

                    Test
                    ====

                    .. code-block:: python

                        print(
"""))

    def test_ignore_sphinx_directives(self):
        self.assert_lines_equal(
            [],
            rstcheck.check(
                """\
.. toctree::
    :maxdepth: 2

    intro
    strings
    datatypes
    numeric
    (many more documents listed here)
"""))


if __name__ == '__main__':
    unittest.main()

@@ -1733,148 +1733,587 @@
 ines
-(self):%0A        self.assert_lines_equal(%0A            %5B6%5D,%0A            rstcheck.check(%0A                %22%22%22%5C%0ATest%0A====%0A%0A.. code-block:: python
+_before(self):%0A        self.assert_lines_equal(%0A            %5B8%5D,%0A            rstcheck.check(%0A                %22%22%22%5C%0ATest%0A====%0A%0A.. code-block:: python%0A%0A%0A%0A    print(%0A%22%22%22))%0A%0A    def test_check_with_extra_blank_lines_after(self):%0A        self.assert_lines_equal(%0A            %5B6%5D,%0A            rstcheck.check(%0A                %22%22%22%5C%0ATest%0A====%0A%0A.. code-block:: python%0A%0A    print(%0A%0A%0A%0A%22%22%22))%0A%0A    def test_check_with_extra_blank_lines_before_and_after(self):%0A        self.assert_lines_equal(%0A            %5B8%5D,%0A            rstcheck.check(%0A                %22%22%22%5C%0ATest%0A====%0A%0A.. code-block:: python%0A%0A
 %0A%0A  

Add more tests