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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
"""Tests for the validation raise paths across every builder mixin.
Each test triggers exactly one of the per-method input-validation branches
that the happy-path builder tests never hit.
"""
import pytest
from edify import RegexBuilder
from edify.errors.anchors import (
CannotDefineStartAfterEndError,
EndInputAlreadyDefinedError,
StartInputAlreadyDefinedError,
)
from edify.errors.input import (
MustBeIntegerGreaterThanZeroError,
MustBeLessThanError,
MustBeOneCharacterError,
MustBePositiveIntegerError,
MustBeSingleCharacterError,
MustHaveASmallerValueError,
)
from edify.errors.naming import NamedGroupDoesNotExistError
from edify.errors.structure import CannotCallSubexpressionError
def test_start_of_input_twice_raises():
with pytest.raises(StartInputAlreadyDefinedError):
RegexBuilder().start_of_input().start_of_input()
def test_start_of_input_after_end_raises():
with pytest.raises(CannotDefineStartAfterEndError):
RegexBuilder().end_of_input().start_of_input()
def test_end_of_input_twice_raises():
with pytest.raises(EndInputAlreadyDefinedError):
RegexBuilder().end_of_input().end_of_input()
def test_named_capture_empty_string_raises():
with pytest.raises(MustBeOneCharacterError):
RegexBuilder().named_capture("")
def test_string_empty_raises():
with pytest.raises(MustBeOneCharacterError):
RegexBuilder().string("")
def test_range_first_codepoint_not_less_than_second_raises():
with pytest.raises(MustHaveASmallerValueError):
RegexBuilder().range("z", "a")
def test_anything_but_string_empty_raises():
with pytest.raises(MustBeOneCharacterError):
RegexBuilder().anything_but_string("")
def test_anything_but_chars_empty_raises():
with pytest.raises(MustBeOneCharacterError):
RegexBuilder().anything_but_chars("")
def test_anything_but_range_multi_char_raises():
with pytest.raises(MustBeSingleCharacterError):
RegexBuilder().anything_but_range("abc", "z")
def test_anything_but_range_ascending_raises():
with pytest.raises(MustHaveASmallerValueError):
RegexBuilder().anything_but_range("z", "a")
def test_exactly_non_positive_raises():
with pytest.raises(MustBePositiveIntegerError):
RegexBuilder().exactly(0).digit()
def test_at_least_non_positive_raises():
with pytest.raises(MustBePositiveIntegerError):
RegexBuilder().at_least(-1).digit()
def test_at_most_non_positive_raises():
with pytest.raises(MustBePositiveIntegerError):
RegexBuilder().at_most(0).digit()
def test_between_negative_lower_raises():
with pytest.raises(MustBeIntegerGreaterThanZeroError):
RegexBuilder().between(-1, 5).digit()
def test_between_lower_not_less_than_upper_raises():
with pytest.raises(MustBeLessThanError):
RegexBuilder().between(5, 5).digit()
def test_between_lazy_negative_lower_raises():
with pytest.raises(MustBeIntegerGreaterThanZeroError):
RegexBuilder().between_lazy(-1, 5).digit()
def test_between_lazy_lower_not_less_than_upper_raises():
with pytest.raises(MustBeLessThanError):
RegexBuilder().between_lazy(5, 5).digit()
def test_named_back_reference_undeclared_raises():
with pytest.raises(NamedGroupDoesNotExistError):
RegexBuilder().named_back_reference("missing")
def test_to_regex_string_with_open_frame_raises():
unfinished = RegexBuilder().capture().digit()
with pytest.raises(CannotCallSubexpressionError):
unfinished.to_regex_string()
def test_to_regex_with_open_frame_raises():
unfinished = RegexBuilder().capture().digit()
with pytest.raises(CannotCallSubexpressionError):
unfinished.to_regex()
|