Skip to content

Commit caa7d2e

Browse files
committed
test(parse): Add is_explicit example
1 parent 1888570 commit caa7d2e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

libvcs/parse/base.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MatcherRegistry(SkipDefaultFieldsReprMixin):
3939
_matchers: dict[str, Matcher] = dataclasses.field(default_factory=dict)
4040

4141
def register(self, cls: Matcher) -> None:
42-
"""
42+
r"""
4343
4444
.. currentmodule:: libvcs.parse.git
4545
@@ -76,11 +76,13 @@ def register(self, cls: Matcher) -> None:
7676
>>> class GitHubPrefix(Matcher):
7777
... label = 'gh-prefix'
7878
... description ='Matches prefixes like github:org/repo'
79-
... pattern = r'^github:(?P<path>)'
79+
... pattern = r'^github:(?P<path>.*)$'
8080
... pattern_defaults = {
8181
... 'hostname': 'github.com',
8282
... 'scheme': 'https'
8383
... }
84+
... # We know it's git, not any other VCS
85+
... is_explicit = True
8486
8587
>>> @dataclasses.dataclass(repr=False)
8688
... class GitHubLocation(GitURL):
@@ -91,6 +93,21 @@ def register(self, cls: Matcher) -> None:
9193
>>> GitHubLocation.is_valid(url='github:vcs-python/libvcs')
9294
True
9395
96+
>>> GitHubLocation.is_valid(url='github:vcs-python/libvcs', is_explicit=True)
97+
True
98+
99+
Notice how ``pattern_defaults`` neatly fills the values for us.
100+
101+
>>> GitHubLocation(url='github:vcs-python/libvcs')
102+
GitHubLocation(url=github:vcs-python/libvcs,
103+
scheme=https,
104+
hostname=github.com,
105+
path=vcs-python/libvcs,
106+
matcher=gh-prefix)
107+
108+
>>> GitHubLocation(url='github:vcs-python/libvcs').to_url()
109+
'https://github.com/vcs-python/libvcs'
110+
94111
>>> GitHubLocation.is_valid(url='gitlab:vcs-python/libvcs')
95112
False
96113

0 commit comments

Comments
 (0)