|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from bump_pydantic.glob_helpers import glob_to_re, match_glob |
| 8 | + |
| 9 | + |
| 10 | +class TestGlobHelpers: |
| 11 | + match_glob_values: list[tuple[str, Path, bool]] = [ |
| 12 | + ("foo", Path("foo"), True), |
| 13 | + ("foo", Path("bar"), False), |
| 14 | + ("foo", Path("foo/bar"), False), |
| 15 | + ("*", Path("foo"), True), |
| 16 | + ("*", Path("bar"), True), |
| 17 | + ("*", Path("foo/bar"), False), |
| 18 | + ("**", Path("foo"), True), |
| 19 | + ("**", Path("foo/bar"), True), |
| 20 | + ("**", Path("foo/bar/baz/qux"), True), |
| 21 | + ("foo/bar", Path("foo/bar"), True), |
| 22 | + ("foo/bar", Path("foo"), False), |
| 23 | + ("foo/bar", Path("far"), False), |
| 24 | + ("foo/bar", Path("foo/foo"), False), |
| 25 | + ("foo/*", Path("foo/bar"), True), |
| 26 | + ("foo/*", Path("foo/bar/baz"), False), |
| 27 | + ("foo/*", Path("foo"), False), |
| 28 | + ("foo/*", Path("bar"), False), |
| 29 | + ("foo/**", Path("foo/bar"), True), |
| 30 | + ("foo/**", Path("foo/bar/baz"), True), |
| 31 | + ("foo/**", Path("foo/bar/baz/qux"), True), |
| 32 | + ("foo/**", Path("foo"), True), |
| 33 | + ("foo/**", Path("bar"), False), |
| 34 | + ("foo/**/bar", Path("foo/bar"), True), |
| 35 | + ("foo/**/bar", Path("foo/baz/bar"), True), |
| 36 | + ("foo/**/bar", Path("foo/baz/qux/bar"), True), |
| 37 | + ("foo/**/bar", Path("foo/baz/qux"), False), |
| 38 | + ("foo/**/bar", Path("foo/bar/baz"), False), |
| 39 | + ("foo/**/bar", Path("foo/bar/bar"), True), |
| 40 | + ("foo/**/bar", Path("foo"), False), |
| 41 | + ("foo/**/bar", Path("bar"), False), |
| 42 | + ("foo/**/*/bar", Path("foo/bar"), False), |
| 43 | + ("foo/**/*/bar", Path("foo/baz/bar"), True), |
| 44 | + ("foo/**/*/bar", Path("foo/baz/qux/bar"), True), |
| 45 | + ("foo/**/*/bar", Path("foo/baz/qux"), False), |
| 46 | + ("foo/**/*/bar", Path("foo/bar/baz"), False), |
| 47 | + ("foo/**/*/bar", Path("foo/bar/bar"), True), |
| 48 | + ("foo/**/*/bar", Path("foo"), False), |
| 49 | + ("foo/**/*/bar", Path("bar"), False), |
| 50 | + ("foo/ba*", Path("foo/bar"), True), |
| 51 | + ("foo/ba*", Path("foo/baz"), True), |
| 52 | + ("foo/ba*", Path("foo/qux"), False), |
| 53 | + ("foo/ba*", Path("foo/baz/qux"), False), |
| 54 | + ("foo/ba*", Path("foo/bar/baz"), False), |
| 55 | + ("foo/ba*", Path("foo"), False), |
| 56 | + ("foo/ba*", Path("bar"), False), |
| 57 | + ("foo/**/ba*/*/qux", Path("foo/a/b/c/bar/a/qux"), True), |
| 58 | + ("foo/**/ba*/*/qux", Path("foo/a/b/c/baz/a/qux"), True), |
| 59 | + ("foo/**/ba*/*/qux", Path("foo/a/bar/a/qux"), True), |
| 60 | + ("foo/**/ba*/*/qux", Path("foo/baz/a/qux"), True), |
| 61 | + ("foo/**/ba*/*/qux", Path("foo/baz/qux"), False), |
| 62 | + ("foo/**/ba*/*/qux", Path("foo/a/b/c/qux/a/qux"), False), |
| 63 | + ("foo/**/ba*/*/qux", Path("foo"), False), |
| 64 | + ("foo/**/ba*/*/qux", Path("bar"), False), |
| 65 | + ] |
| 66 | + |
| 67 | + @pytest.mark.parametrize(("pattern", "path", "expected"), match_glob_values) |
| 68 | + def test_match_glob(self, pattern: str, path: Path, expected: bool): |
| 69 | + expr = glob_to_re(pattern) |
| 70 | + assert match_glob(path, pattern) == expected, f"path: {path}, pattern: {pattern}, expr: {expr}" |
0 commit comments