
""" 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)

[((16, 21, 16, 50), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(16, 39, 16, 45): '"""test"""', (16, 47, 16, 49): '(10)'}, {}), "('test', 10)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((22, 20, 22, 50), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(22, 38, 22, 46): '"""test(["""', (22, 48, 22, 49): '(0)'}, {}), "('test([', 0)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((23, 20, 23, 50), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(23, 38, 23, 46): '"""test(["""', (23, 48, 23, 49): '(3)'}, {}), "('test([', 3)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((29, 20, 29, 53), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(29, 38, 29, 49): '"""test(a, b"""', (29, 51, 29, 52): '(4)'}, {}), "('test(a, b', 4)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((30, 20, 30, 55), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(30, 38, 30, 51): '"""test[a, b()"""', (30, 53, 30, 54): '(4)'}, {}), "('test[a, b()', 4)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((36, 21, 36, 55), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(36, 39, 36, 51): '"""test(a, b)"""', (36, 53, 36, 54): '(4)'}, {}), "('test(a, b)', 4)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((37, 21, 37, 58), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(37, 39, 37, 54): '"""test(a, b)[0]"""', (37, 56, 37, 57): '(4)'}, {}), "('test(a, b)[0]', 4)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((38, 21, 38, 57), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(38, 39, 38, 53): '"""test(a, b())"""', (38, 55, 38, 56): '(4)'}, {}), "('test(a, b())', 4)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((39, 21, 39, 62), 'wheezy.template.utils.find_all_balanced', 'find_all_balanced', ({(39, 39, 39, 58): '"""test(a, b())[0]()"""', (39, 60, 39, 61): '(4)'}, {}), "('test(a, b())[0]()', 4)", False, 'from wheezy.template.utils import find_all_balanced\n'), ((50, 21, 50, 46), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(50, 35, 50, 41): '"""test"""', (50, 43, 50, 45): '(10)'}, {}), "('test', 10)", False, 'from wheezy.template.utils import find_balanced\n'), ((56, 20, 56, 45), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(56, 34, 56, 41): '"""test("""', (56, 43, 56, 44): '(0)'}, {}), "('test(', 0)", False, 'from wheezy.template.utils import find_balanced\n'), ((57, 20, 57, 45), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(57, 34, 57, 41): '"""test("""', (57, 43, 57, 44): '(3)'}, {}), "('test(', 3)", False, 'from wheezy.template.utils import find_balanced\n'), ((63, 20, 63, 49), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(63, 34, 63, 45): '"""test(a, b"""', (63, 47, 63, 48): '(4)'}, {}), "('test(a, b', 4)", False, 'from wheezy.template.utils import find_balanced\n'), ((64, 20, 64, 51), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(64, 34, 64, 47): '"""test(a, b()"""', (64, 49, 64, 50): '(4)'}, {}), "('test(a, b()', 4)", False, 'from wheezy.template.utils import find_balanced\n'), ((70, 21, 70, 51), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(70, 35, 70, 47): '"""test(a, b)"""', (70, 49, 70, 50): '(4)'}, {}), "('test(a, b)', 4)", False, 'from wheezy.template.utils import find_balanced\n'), ((71, 21, 71, 53), 'wheezy.template.utils.find_balanced', 'find_balanced', ({(71, 35, 71, 49): '"""test(a, b())"""', (71, 51, 71, 52): '(4)'}, {}), "('test(a, b())', 4)", False, 'from wheezy.template.utils import find_balanced\n')]