diff --git a/earthsnake/path.py b/earthsnake/path.py index 1d7adc1..4a11128 100644 --- a/earthsnake/path.py +++ b/earthsnake/path.py @@ -75,3 +75,13 @@ class Path: def __repr__(self) -> str: return f'' + + def startswith(self, sub: str) -> bool: + """Check if path starts with sub""" + + return self.path.startswith(sub) + + def endswith(self, sub: str) -> bool: + """Check if path ends with sub""" + + return self.path.endswith(sub) diff --git a/tests/test_path.py b/tests/test_path.py index d3c87f8..0fe4b68 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -106,3 +106,21 @@ def test_repr() -> None: """Test the __repr__ method""" assert repr(Path('/test.txt')) == '' + + +def test_startswith() -> None: + """Test the startswith method""" + + path = Path('/test.txt') + + assert path.startswith('/test') + assert not path.startswith('test') + + +def test_endswith() -> None: + """Test the endswith method""" + + path = Path('/test.txt') + + assert path.endswith('.txt') + assert not path.endswith('.py')