From 527dc83928c06c7d90f92752b0e5bb9df908633a Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Thu, 28 Mar 2019 12:57:30 -0400 Subject: [PATCH] Fixed bug in glob matching. --- st3/sublime_lib/_util/glob.py | 5 +++-- tests/test_glob.py | 1 + tests/test_pure_resource_path.py | 1 + tests/test_resource_path.py | 12 ++++++++++++ tests/uniquely_named_file_ks27jArEz4 | 0 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/uniquely_named_file_ks27jArEz4 diff --git a/st3/sublime_lib/_util/glob.py b/st3/sublime_lib/_util/glob.py index 0b56933..4dd6259 100644 --- a/st3/sublime_lib/_util/glob.py +++ b/st3/sublime_lib/_util/glob.py @@ -16,10 +16,11 @@ @lru_cache() def get_glob_matcher(pattern: str) -> Callable[[str], bool]: - s = '' + s = r'\A' if pattern.startswith('/'): pattern = pattern[1:] - s += r'\A' + else: + pattern = '**/' + pattern for part in GLOB_RE.split(pattern): if part == '': diff --git a/tests/test_glob.py b/tests/test_glob.py index de021a2..c4cb396 100644 --- a/tests/test_glob.py +++ b/tests/test_glob.py @@ -44,6 +44,7 @@ def test_basic(self): ], [ 'Packages/Foo/bar/baz', + 'FooFoo/bar', ] ) diff --git a/tests/test_pure_resource_path.py b/tests/test_pure_resource_path.py index 8112266..dba5559 100644 --- a/tests/test_pure_resource_path.py +++ b/tests/test_pure_resource_path.py @@ -202,6 +202,7 @@ def test_match(self): self.assertFalse(path.match('Foo')) self.assertFalse(path.match('Packages/*/*/bar')) self.assertFalse(path.match('/Foo/bar')) + self.assertFalse(path.match('ar')) def test_joinpath(self): self.assertEqual( diff --git a/tests/test_resource_path.py b/tests/test_resource_path.py index 2894869..d218b50 100644 --- a/tests/test_resource_path.py +++ b/tests/test_resource_path.py @@ -33,6 +33,18 @@ def test_glob_resources(self): ] ) + self.assertEqual( + ResourcePath.glob_resources("ks27jArEz4"), + [] + ) + + self.assertEqual( + ResourcePath.glob_resources("*ks27jArEz4"), + [ + ResourcePath('Packages/sublime_lib/tests/uniquely_named_file_ks27jArEz4') + ] + ) + def test_from_file_path_packages(self): self.assertEqual( ResourcePath.from_file_path(Path(sublime.packages_path(), 'test_package')), diff --git a/tests/uniquely_named_file_ks27jArEz4 b/tests/uniquely_named_file_ks27jArEz4 new file mode 100644 index 0000000..e69de29