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)
def var_token(m: typing.Match[str]) -> Token: """Produces variable token.""" start = m.start(1) pos = m.end() source = m.string while 1: end = find_all_balanced(source, pos) if pos == end: break mm = RE_VAR.match(source, end) if not mm: break pos = mm.end() value = source[start:end] mm = RE_VAR_FILTER.match(source, end) if mm: end = mm.end() value += "!" + mm.group() return end, "var", value
def var_token(m): """ Produces variable token. """ start = m.start(1) pos = m.end() source = m.string while 1: end = find_all_balanced(source, pos) if pos == end: break m = RE_VAR.match(source, end) if not m: break pos = m.end() value = str(source[start:end]) m = RE_VAR_FILTER.match(source, end) if m: end = m.end() value += '!' + m.group() return end, 'var', value
def test_start_out(self) -> None: """The start index is out of range.""" assert 10 == find_all_balanced("test", 10)
def test_balanced(self) -> None: """Separators are 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)
def test_not_balanced(self) -> None: """Separators are not balanced.""" assert 4 == find_all_balanced("test(a, b", 4) assert 4 == find_all_balanced("test[a, b()", 4)
def test_start_separator(self) -> None: """If text doesn't start with ``([`` return.""" 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_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_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)