
""" Unit tests for ``wheezy.templates.utils``.
"""

import unittest


class FindAllBalancedTestCase(unittest.TestCase):
    """ Test the ``find_all_balanced``.
    """

    def test_start_out(self):
        """ The start index is out of range.
        """
        from wheezy.template.utils import find_all_balanced
        assert 10 == find_all_balanced('test', 10)

    def test_start_separator(self):
        """ If text doesn't start with ``([`` return.
        """
        from wheezy.template.utils import find_all_balanced
        assert 0 == find_all_balanced('test([', 0)
        assert 3 == find_all_balanced('test([', 3)

    def test_not_balanced(self):
        """ Separators are not balanced.
        """
        from wheezy.template.utils import find_all_balanced
        assert 4 == find_all_balanced('test(a, b', 4)
        assert 4 == find_all_balanced('test[a, b()', 4)

    def test_balanced(self):
        """ Separators are balanced.
        """
        from wheezy.template.utils import find_all_balanced
        assert 10 == find_all_balanced('test(a, b)', 4)
        assert 13 == find_all_balanced('test(a, b)[0]', 4)
        assert 12 == find_all_balanced('test(a, b())', 4)
        assert 17 == find_all_balanced('test(a, b())[0]()', 4)


class FindBalancedTestCase(unittest.TestCase):
    """ Test the ``find_balanced``.
    """

    def test_start_out(self):
        """ The start index is out of range.
        """
        from wheezy.template.utils import find_balanced
        assert 10 == find_balanced('test', 10)

    def test_start_separator(self):
        """ If text doesn't start with ``start_sep`` return.
        """
        from wheezy.template.utils import find_balanced
        assert 0 == find_balanced('test(', 0)
        assert 3 == find_balanced('test(', 3)

    def test_not_balanced(self):
        """ Separators are not balanced.
        """
        from wheezy.template.utils import find_balanced
        assert 4 == find_balanced('test(a, b', 4)
        assert 4 == find_balanced('test(a, b()', 4)

    def test_balanced(self):
        """ Separators are balanced.
        """
        from wheezy.template.utils import find_balanced
        assert 10 == find_balanced('test(a, b)', 4)
        assert 12 == find_balanced('test(a, b())', 4)

[((338, 367), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test"""', '(10)'], {}), "('test', 10)\n", (355, 367), False, 'from wheezy.template.utils import find_all_balanced\n'), ((551, 581), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(["""', '(0)'], {}), "('test([', 0)\n", (568, 581), False, 'from wheezy.template.utils import find_all_balanced\n'), ((602, 632), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(["""', '(3)'], {}), "('test([', 3)\n", (619, 632), False, 'from wheezy.template.utils import find_all_balanced\n'), ((800, 833), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(a, b"""', '(4)'], {}), "('test(a, b', 4)\n", (817, 833), False, 'from wheezy.template.utils import find_all_balanced\n'), ((854, 889), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test[a, b()"""', '(4)'], {}), "('test[a, b()', 4)\n", (871, 889), False, 'from wheezy.template.utils import find_all_balanced\n'), ((1050, 1084), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(a, b)"""', '(4)'], {}), "('test(a, b)', 4)\n", (1067, 1084), False, 'from wheezy.template.utils import find_all_balanced\n'), ((1106, 1143), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(a, b)[0]"""', '(4)'], {}), "('test(a, b)[0]', 4)\n", (1123, 1143), False, 'from wheezy.template.utils import find_all_balanced\n'), ((1165, 1201), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(a, b())"""', '(4)'], {}), "('test(a, b())', 4)\n", (1182, 1201), False, 'from wheezy.template.utils import find_all_balanced\n'), ((1223, 1264), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', (['"""test(a, b())[0]()"""', '(4)'], {}), "('test(a, b())[0]()', 4)\n", (1240, 1264), False, 'from wheezy.template.utils import find_all_balanced\n'), ((1523, 1548), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test"""', '(10)'], {}), "('test', 10)\n", (1536, 1548), False, 'from wheezy.template.utils import find_balanced\n'), ((1735, 1760), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test("""', '(0)'], {}), "('test(', 0)\n", (1748, 1760), False, 'from wheezy.template.utils import find_balanced\n'), ((1781, 1806), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test("""', '(3)'], {}), "('test(', 3)\n", (1794, 1806), False, 'from wheezy.template.utils import find_balanced\n'), ((1970, 1999), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test(a, b"""', '(4)'], {}), "('test(a, b', 4)\n", (1983, 1999), False, 'from wheezy.template.utils import find_balanced\n'), ((2020, 2051), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test(a, b()"""', '(4)'], {}), "('test(a, b()', 4)\n", (2033, 2051), False, 'from wheezy.template.utils import find_balanced\n'), ((2208, 2238), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test(a, b)"""', '(4)'], {}), "('test(a, b)', 4)\n", (2221, 2238), False, 'from wheezy.template.utils import find_balanced\n'), ((2260, 2292), 'wheezy.template.utils.find_balanced', 'find_balanced', (['"""test(a, b())"""', '(4)'], {}), "('test(a, b())', 4)\n", (2273, 2292), False, 'from wheezy.template.utils import find_balanced\n')]