36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import pathlib
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from plan.named_paths import named_files, named_paths
|
|
|
|
|
|
class NamedPaths(unittest.TestCase):
|
|
def test_names_each_tracked_file_or_folder_a_backticked_span_names_once_with_its_files(self):
|
|
cases = (
|
|
("`src/` and `src`", ["src/app.py", "srcfoo/x.py"], [("src", 1)]),
|
|
("`src/`", ["src/app.py", "src/b.py"], [("src", 2)]),
|
|
("`src/app.py`, `gone.py` and `run`", ["src/app.py"], [("src/app.py", 1)]),
|
|
)
|
|
for text, tracked, named in cases:
|
|
with self.subTest(text=text):
|
|
self.assertEqual(named_paths(text, tracked), named)
|
|
|
|
|
|
class NamedFiles(unittest.TestCase):
|
|
def test_lists_each_tracked_file_a_span_names_by_itself_or_its_folder_once(self):
|
|
cases = (
|
|
("`src` and `src/a.py`", ["b.py", "src/a.py", "src/b.py", "srcfoo/x.py"], ["src/a.py", "src/b.py"]),
|
|
("`b.py`, `gone.py` and `run`", ["b.py", "c.py"], ["b.py"]),
|
|
("no span", ["b.py"], []),
|
|
)
|
|
for text, tracked, named in cases:
|
|
with self.subTest(text=text):
|
|
self.assertEqual(named_files(text, tracked), named)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|