@@ -7,6 +7,116 @@ fn directories() -> crate::Result {
7
7
baseline:: run ( "directory" , true , baseline:: directories)
8
8
}
9
9
10
+ #[ test]
11
+ fn directory_matches_prefix ( ) -> crate :: Result {
12
+ for spec in [ "dir" , "dir/" , "di*" , "dir/*" , "dir/*.o" ] {
13
+ for specs in [ & [ spec] as & [ _ ] , & [ spec, "other" ] ] {
14
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( specs) , None , Path :: new ( "" ) ) ?;
15
+ assert ! (
16
+ search. directory_matches_prefix( "dir" . into( ) , false ) ,
17
+ "{spec}: must match"
18
+ ) ;
19
+ assert ! (
20
+ !search. directory_matches_prefix( "d" . into( ) , false ) ,
21
+ "{spec}: must not match"
22
+ ) ;
23
+ }
24
+ }
25
+
26
+ for spec in [ "dir/d" , "dir/d/" , "dir/*/*" , "dir/d/*.o" ] {
27
+ for specs in [ & [ spec] as & [ _ ] , & [ spec, "other" ] ] {
28
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( specs) , None , Path :: new ( "" ) ) ?;
29
+ assert ! (
30
+ search. directory_matches_prefix( "dir/d" . into( ) , false ) ,
31
+ "{spec}: must match"
32
+ ) ;
33
+ assert ! (
34
+ search. directory_matches_prefix( "dir/d" . into( ) , true ) ,
35
+ "{spec}: must match"
36
+ ) ;
37
+ for leading in [ false , true ] {
38
+ assert ! (
39
+ !search. directory_matches_prefix( "d" . into( ) , leading) ,
40
+ "{spec}: must not match"
41
+ ) ;
42
+ assert ! (
43
+ !search. directory_matches_prefix( "di" . into( ) , leading) ,
44
+ "{spec}: must not match"
45
+ ) ;
46
+ }
47
+ }
48
+ }
49
+ Ok ( ( ) )
50
+ }
51
+
52
+ #[ test]
53
+ fn directory_matches_prefix_starting_wildcards_always_match ( ) -> crate :: Result {
54
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ "*ir" ] ) , None , Path :: new ( "" ) ) ?;
55
+ assert ! ( search. directory_matches_prefix( "dir" . into( ) , false ) ) ;
56
+ assert ! ( search. directory_matches_prefix( "d" . into( ) , false ) ) ;
57
+ Ok ( ( ) )
58
+ }
59
+
60
+ #[ test]
61
+ fn directory_matches_prefix_leading ( ) -> crate :: Result {
62
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ "d/d/generated/b" ] ) , None , Path :: new ( "" ) ) ?;
63
+ assert ! ( !search. directory_matches_prefix( "di" . into( ) , false ) ) ;
64
+ assert ! ( !search. directory_matches_prefix( "di" . into( ) , true ) ) ;
65
+ assert ! ( search. directory_matches_prefix( "d" . into( ) , true ) ) ;
66
+ assert ! ( !search. directory_matches_prefix( "d" . into( ) , false ) ) ;
67
+ assert ! ( search. directory_matches_prefix( "d/d" . into( ) , true ) ) ;
68
+ assert ! ( !search. directory_matches_prefix( "d/d" . into( ) , false ) ) ;
69
+ assert ! ( search. directory_matches_prefix( "d/d/generated" . into( ) , true ) ) ;
70
+ assert ! ( !search. directory_matches_prefix( "d/d/generated" . into( ) , false ) ) ;
71
+ assert ! ( !search. directory_matches_prefix( "d/d/generatedfoo" . into( ) , false ) ) ;
72
+ assert ! ( !search. directory_matches_prefix( "d/d/generatedfoo" . into( ) , true ) ) ;
73
+
74
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":(icase)d/d/GENERATED/b" ] ) , None , Path :: new ( "" ) ) ?;
75
+ assert ! (
76
+ search. directory_matches_prefix( "d/d/generated" . into( ) , true ) ,
77
+ "icase is respected as well"
78
+ ) ;
79
+ assert ! ( !search. directory_matches_prefix( "d/d/generated" . into( ) , false ) ) ;
80
+ Ok ( ( ) )
81
+ }
82
+
83
+ #[ test]
84
+ fn directory_matches_prefix_negative_wildcard ( ) -> crate :: Result {
85
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":!*generated*" ] ) , None , Path :: new ( "" ) ) ?;
86
+ assert ! (
87
+ search. directory_matches_prefix( "di" . into( ) , false ) ,
88
+ "it's always considered matching, we can't really tell anyway"
89
+ ) ;
90
+ assert ! ( search. directory_matches_prefix( "di" . into( ) , true ) ) ;
91
+ assert ! ( search. directory_matches_prefix( "d" . into( ) , true ) ) ;
92
+ assert ! ( search. directory_matches_prefix( "d" . into( ) , false ) ) ;
93
+ assert ! ( search. directory_matches_prefix( "d/d" . into( ) , true ) ) ;
94
+ assert ! ( search. directory_matches_prefix( "d/d" . into( ) , false ) ) ;
95
+ assert ! ( search. directory_matches_prefix( "d/d/generated" . into( ) , true ) ) ;
96
+ assert ! ( search. directory_matches_prefix( "d/d/generated" . into( ) , false ) ) ;
97
+ assert ! ( search. directory_matches_prefix( "d/d/generatedfoo" . into( ) , false ) ) ;
98
+ assert ! ( search. directory_matches_prefix( "d/d/generatedfoo" . into( ) , true ) ) ;
99
+
100
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":(exclude,icase)*GENERATED*" ] ) , None , Path :: new ( "" ) ) ?;
101
+ assert ! ( search. directory_matches_prefix( "d/d/generated" . into( ) , true ) ) ;
102
+ assert ! ( search. directory_matches_prefix( "d/d/generated" . into( ) , false ) ) ;
103
+ Ok ( ( ) )
104
+ }
105
+
106
+ #[ test]
107
+ fn directory_matches_prefix_all_excluded ( ) -> crate :: Result {
108
+ for spec in [ "!dir" , "!dir/" , "!d*" , "!di*" , "!dir/*" , "!dir/*.o" , "!*ir" ] {
109
+ for specs in [ & [ spec] as & [ _ ] , & [ spec, "other" ] ] {
110
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( specs) , None , Path :: new ( "" ) ) ?;
111
+ assert ! (
112
+ !search. directory_matches_prefix( "dir" . into( ) , false ) ,
113
+ "{spec}: must not match, it's excluded"
114
+ ) ;
115
+ }
116
+ }
117
+ Ok ( ( ) )
118
+ }
119
+
10
120
#[ test]
11
121
fn no_pathspecs_match_everything ( ) -> crate :: Result {
12
122
let mut search = gix_pathspec:: Search :: from_specs ( [ ] , None , Path :: new ( "" ) ) ?;
@@ -21,6 +131,7 @@ fn no_pathspecs_match_everything() -> crate::Result {
21
131
"this is actually a fake pattern, as we have to match even though there isn't anything"
22
132
) ;
23
133
assert ! ( search. can_match_relative_path( "anything" . into( ) , None ) ) ;
134
+ assert ! ( search. directory_matches_prefix( "anything" . into( ) , false ) ) ;
24
135
Ok ( ( ) )
25
136
}
26
137
@@ -51,6 +162,8 @@ fn starts_with() -> crate::Result {
51
162
search. can_match_relative_path( "a" . into( ) , None ) ,
52
163
"if unspecified, we match for good measure"
53
164
) ;
165
+ assert ! ( search. directory_matches_prefix( "a" . into( ) , false ) ) ;
166
+ assert ! ( !search. directory_matches_prefix( "ab" . into( ) , false ) ) ;
54
167
assert_eq ! (
55
168
search
56
169
. pattern_matching_relative_path( "a/file" . into( ) , None , & mut no_attrs)
0 commit comments