forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_globpattern.py
More file actions
85 lines (77 loc) · 3.25 KB
/
test_globpattern.py
File metadata and controls
85 lines (77 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from panda3d.core import GlobPattern
def test_globpattern_matches_file():
patt = GlobPattern('/a/b/c')
assert patt.matches_file('/a/b/c')
assert patt.matches_file('///a////b//c')
assert patt.matches_file('/a/b/././c')
assert not patt.matches_file('')
assert not patt.matches_file('/')
assert not patt.matches_file('/a/b/d')
assert not patt.matches_file('/A/b/c')
assert not patt.matches_file('/a/b/c/')
assert not patt.matches_file('/a/b/c/.')
assert not patt.matches_file('a/b/c')
assert not patt.matches_file('./a/b/c')
# Test regular pattern
patt = GlobPattern('*a')
assert patt.matches_file('a')
assert patt.matches_file('aa')
assert patt.matches_file('xa')
assert not patt.matches_file('A')
assert not patt.matches_file('ax')
assert not patt.matches_file('xax')
# Test path ending in directory
for patt in GlobPattern('/a/b/c/'), \
GlobPattern('/a/b/c/.'), \
GlobPattern('/a/b//c//'), \
GlobPattern('/a/b/./c/./'):
assert patt.matches_file('/a/b/c/')
assert patt.matches_file('///a////b//c//')
assert patt.matches_file('/a/b/././c/')
assert patt.matches_file('/a/b/c/.')
assert not patt.matches_file('/a/b/c')
assert not patt.matches_file('/a/b/c/./d')
assert not patt.matches_file('a/b/c/')
assert not patt.matches_file('./a/b/c/')
# Test globstar in middle
for patt in GlobPattern('/a/**/c'), GlobPattern('/a/**/**/c'):
assert patt.matches_file('/a/c')
assert patt.matches_file('/a/b/c')
assert patt.matches_file('/a/b/d/c')
assert not patt.matches_file('/a/b/c/d')
assert not patt.matches_file('/d/b/c')
assert not patt.matches_file('/a/b/d')
# Test globstar in beginning
for patt in GlobPattern('/**/b/c'), GlobPattern('/**/**/**/b/c'):
assert patt.matches_file('/a/b/c')
assert patt.matches_file('/a/d/b/c')
assert patt.matches_file('/a/b/c')
assert patt.matches_file('/a/b/c/./b//c')
assert not patt.matches_file('/a/b/c/d')
assert not patt.matches_file('/a/c')
assert not patt.matches_file('/a/b/d')
# Test globstar at end
for patt in GlobPattern('/a/b/**'), \
GlobPattern('/a/b/**/**'), \
GlobPattern('/a/b//**//**/**'):
assert patt.matches_file('/a/b/')
assert patt.matches_file('/a/b/.')
assert patt.matches_file('/a/b//')
assert patt.matches_file('/a/b/c')
assert patt.matches_file('/a/b/c/d/e/f/g/h')
assert patt.matches_file('/a/b/d/c')
assert not patt.matches_file('/a/')
assert not patt.matches_file('/a/c/b')
# Test multiple globstars at multiple locations
patt = GlobPattern('/a/**/b/**/c')
assert patt.matches_file('/a/b/c')
assert patt.matches_file('/a/./b/./c')
assert patt.matches_file('/a//b//c')
assert patt.matches_file('/a/x/y/b/c')
assert patt.matches_file('/a/b/x/y/c')
assert patt.matches_file('/a/b/c/a/b/c')
assert patt.matches_file('/a/x/y/b/x/y/c')
assert not patt.matches_file('/a/b/x')
assert not patt.matches_file('/a/b/c/x')
assert not patt.matches_file('/a/b/c/')
assert not patt.matches_file('/a/b/c/.')