blob: e149052aebe67315b071a9a1c138e725cfa4d52d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
"""Tests for the pass-through branches when subexpression anchors merge without conflict."""
import pytest
from edify import RegexBuilder
from edify.errors.structure import CannotCallSubexpressionError
def test_start_of_input_merges_into_parent_without_existing_start():
sub = RegexBuilder().start_of_input().digit()
parent = RegexBuilder().digit()
pattern = parent.subexpression(sub, ignore_start_and_end=False).to_regex_string()
assert "^" in pattern
def test_end_of_input_merges_into_parent_without_existing_end():
sub = RegexBuilder().digit().end_of_input()
parent = RegexBuilder().digit()
pattern = parent.subexpression(sub, ignore_start_and_end=False).to_regex_string()
assert "$" in pattern
def test_subexpression_called_with_unfinished_expression_raises():
unfinished_sub = RegexBuilder().capture().digit()
parent = RegexBuilder()
with pytest.raises(CannotCallSubexpressionError):
parent.subexpression(unfinished_sub)
|