Skip to content

Commit 2b8670e

Browse files
authored
Merge pull request #15 from evtn/dev
fix: implemented .case_insensitive on many entities with .apply
2 parents 4facf81 + 54baaa2 commit 2b8670e

4 files changed

Lines changed: 21 additions & 28 deletions

File tree

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[report]
2+
exclude_lines =
3+
pragma: not covered
4+
@overload

.github/workflows/test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test that everything works
1+
name: Test
22

33
on:
44
workflow_dispatch:
@@ -53,4 +53,9 @@ jobs:
5353
- run: poetry install --with dev
5454

5555
- name: Test
56-
run: poetry run pytest test/
56+
run: poetry run coverage run --include "rgx/*" -m pytest test/
57+
58+
- name: Coveralls Update
59+
uses: coverallsapp/github-action@v2
60+
with:
61+
github-token: ${{ secrets.GITHUB_TOKEN }}

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "rgx"
3-
version = "1.4.0"
3+
version = "1.4.2"
44
description = "Typed, simple and readable regexp generation"
55
authors = ["Dmitry Gritsenko <rgx@evtn.ru>"]
66
license = "MIT"
@@ -17,6 +17,7 @@ python = "^3.7"
1717
[tool.poetry.group.dev.dependencies]
1818
pytest = "^7.4.0"
1919
mypy = "^1.4.1"
20+
coveralls = "^3.3.1"
2021

2122
[build-system]
2223
requires = ["poetry-core>=1.0.0"]

rgx/entities.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def render_prefix(self) -> StrGen:
449449
yield self.prefix
450450

451451
def case_insensitive(self):
452-
return self.__class__(self.contents.case_insensitive())
452+
return self.apply(lambda x: x.case_insensitive())
453453

454454
def render(self) -> StrGen:
455455
yield "("
@@ -818,10 +818,8 @@ def __init__(self, *contents: AnyRegexPattern) -> None:
818818
def __add__(self, other: AnyRegexPattern) -> Concat:
819819
return Concat(*self.contents, other)
820820

821-
def case_insensitive(self):
822-
new = Concat()
823-
new.contents = [part.case_insensitive() for part in self.contents]
824-
return new
821+
def case_insensitive(self) -> RegexPattern:
822+
return self.apply(lambda x: x.case_insensitive())
825823

826824
def render(self) -> StrGen:
827825
for part in self.contents:
@@ -855,13 +853,7 @@ def __init__(self, *alternatives: AnyRegexPattern):
855853
]
856854

857855
def case_insensitive(self) -> RegexPattern:
858-
new = Option()
859-
alts = [part.case_insensitive() for part in self.alternatives]
860-
861-
if all(isinstance(alt, LocalFlags) and "i" in alt.flags for alt in alts):
862-
pass
863-
864-
return new
856+
return self.apply(lambda x: x.case_insensitive())
865857

866858
def merge_flags(self) -> LocalFlags | Option:
867859
self = self.apply(lambda x: x.merge_flags())
@@ -948,12 +940,7 @@ def __init__(
948940
self.lazy = lazy
949941

950942
def case_insensitive(self) -> RegexPattern:
951-
new = self.contents.case_insensitive().repeat(self.min_count)
952-
if self.max_count is None:
953-
new = new.or_more()
954-
else:
955-
new = new.to(self.max_count)
956-
return new
943+
return self.apply(lambda x: x.case_insensitive())
957944

958945
def repeat(self, count: int, lazy: bool = False) -> Range:
959946
"""
@@ -1161,13 +1148,6 @@ def __init__(
11611148
self.true_option = respect_priority(true_option, Option.priority + 1)
11621149
self.false_option = respect_priority(false_option, Option.priority + 1)
11631150

1164-
def case_insensitive(self) -> RegexPattern:
1165-
return ConditionalPattern(
1166-
self.group,
1167-
self.true_option.case_insensitive(),
1168-
self.false_option.case_insensitive(),
1169-
)
1170-
11711151
def render(self) -> StrGen:
11721152
yield "(?("
11731153
yield str(self.group)
@@ -1184,6 +1164,9 @@ def apply(self, fn: Processor) -> Self:
11841164
fn(self.false_option),
11851165
)
11861166

1167+
def case_insensitive(self) -> RegexPattern:
1168+
return self.apply(lambda x: x.case_insensitive())
1169+
11871170

11881171
class Literal(RegexPattern):
11891172
def __init__(self, contents: str) -> None:

0 commit comments

Comments
 (0)