diff options
| author | natsuoto <[email protected]> | 2026-07-01 17:00:59 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-01 17:00:59 +0530 |
| commit | abc0d47bc7b45f6022fcfd26295cf00b738735a0 (patch) | |
| tree | 8e786bad759899e1f4df3072d6babf7bdb02eb47 /tests | |
| parent | 3d5094a875fbfb167d53278585414fc7884ad521 (diff) | |
| download | edify-abc0d47bc7b45f6022fcfd26295cf00b738735a0.tar.xz edify-abc0d47bc7b45f6022fcfd26295cf00b738735a0.zip | |
feat: __repr__ shows the pattern-so-far on the builder
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/builder/repr.test.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/builder/repr.test.py b/tests/builder/repr.test.py new file mode 100644 index 0000000..278f40b --- /dev/null +++ b/tests/builder/repr.test.py @@ -0,0 +1,31 @@ +"""Tests for :meth:`BuilderCore.__repr__` on :class:`RegexBuilder` and :class:`Pattern`.""" + +from edify import Pattern, RegexBuilder + + +def test_repr_of_a_fresh_regex_builder_shows_the_empty_non_capturing_group(): + assert repr(RegexBuilder()) == "<RegexBuilder '(?:)'>" + + +def test_repr_of_a_fresh_pattern_shows_the_empty_non_capturing_group(): + assert repr(Pattern()) == "<Pattern '(?:)'>" + + +def test_repr_of_a_regex_builder_shows_the_pattern_so_far(): + builder = RegexBuilder().start_of_input().exactly(4).digit().end_of_input() + assert repr(builder) == "<RegexBuilder '^\\\\d{4}$'>" + + +def test_repr_of_a_pattern_shows_the_pattern_so_far(): + pattern = Pattern().one_or_more().word() + assert repr(pattern) == "<Pattern '\\\\w+'>" + + +def test_repr_of_a_builder_with_open_frames_shows_the_unclosed_marker(): + builder = RegexBuilder().any_of().string("cat") + assert repr(builder) == "<RegexBuilder '<unclosed>'>" + + +def test_repr_uses_the_concrete_class_name_not_the_base(): + assert repr(RegexBuilder()).startswith("<RegexBuilder ") + assert repr(Pattern()).startswith("<Pattern ") |
