@@ -7,6 +7,49 @@ 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 ! ( search. directory_matches_prefix( "dir" . into( ) ) , "{spec}: must match" ) ;
16
+ assert ! ( !search. directory_matches_prefix( "d" . into( ) ) , "{spec}: must not match" ) ;
17
+ }
18
+ }
19
+
20
+ for spec in [ "dir/d" , "dir/d/" , "dir/*/*" , "dir/d/*.o" ] {
21
+ for specs in [ & [ spec] as & [ _ ] , & [ spec, "other" ] ] {
22
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( specs) , None , Path :: new ( "" ) ) ?;
23
+ assert ! ( search. directory_matches_prefix( "dir/d" . into( ) ) , "{spec}: must match" ) ;
24
+ assert ! ( !search. directory_matches_prefix( "d" . into( ) ) , "{spec}: must not match" ) ;
25
+ assert ! ( !search. directory_matches_prefix( "di" . into( ) ) , "{spec}: must not match" ) ;
26
+ }
27
+ }
28
+ Ok ( ( ) )
29
+ }
30
+
31
+ #[ test]
32
+ fn directory_matches_prefix_starting_wildcards_always_match ( ) -> crate :: Result {
33
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ "*ir" ] ) , None , Path :: new ( "" ) ) ?;
34
+ assert ! ( search. directory_matches_prefix( "dir" . into( ) ) ) ;
35
+ assert ! ( search. directory_matches_prefix( "d" . into( ) ) ) ;
36
+ Ok ( ( ) )
37
+ }
38
+
39
+ #[ test]
40
+ fn directory_matches_prefix_all_excluded ( ) -> crate :: Result {
41
+ for spec in [ "!dir" , "!dir/" , "!d*" , "!di*" , "!dir/*" , "!dir/*.o" , "!*ir" ] {
42
+ for specs in [ & [ spec] as & [ _ ] , & [ spec, "other" ] ] {
43
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( specs) , None , Path :: new ( "" ) ) ?;
44
+ assert ! (
45
+ !search. directory_matches_prefix( "dir" . into( ) ) ,
46
+ "{spec}: must not match, it's excluded"
47
+ ) ;
48
+ }
49
+ }
50
+ Ok ( ( ) )
51
+ }
52
+
10
53
#[ test]
11
54
fn no_pathspecs_match_everything ( ) -> crate :: Result {
12
55
let mut search = gix_pathspec:: Search :: from_specs ( [ ] , None , Path :: new ( "" ) ) ?;
@@ -21,6 +64,7 @@ fn no_pathspecs_match_everything() -> crate::Result {
21
64
"this is actually a fake pattern, as we have to match even though there isn't anything"
22
65
) ;
23
66
assert ! ( search. can_match_relative_path( "anything" . into( ) , None ) ) ;
67
+ assert ! ( search. directory_matches_prefix( "anything" . into( ) ) ) ;
24
68
Ok ( ( ) )
25
69
}
26
70
@@ -51,6 +95,8 @@ fn starts_with() -> crate::Result {
51
95
search. can_match_relative_path( "a" . into( ) , None ) ,
52
96
"if unspecified, we match for good measure"
53
97
) ;
98
+ assert ! ( search. directory_matches_prefix( "a" . into( ) ) ) ;
99
+ assert ! ( !search. directory_matches_prefix( "ab" . into( ) ) ) ;
54
100
assert_eq ! (
55
101
search
56
102
. pattern_matching_relative_path( "a/file" . into( ) , None , & mut no_attrs)
0 commit comments