@@ -189,65 +189,98 @@ mod complex_globs {
189189 use bstr:: BString ;
190190 use gix_hash:: ObjectId ;
191191 use gix_refspec:: { parse:: Operation , MatchGroup } ;
192- use std:: borrow:: Cow ;
193192
194193 #[ test]
195194 fn one_sided_complex_glob_patterns_can_be_parsed ( ) {
196195 // The key change is that complex glob patterns with multiple asterisks
197196 // can now be parsed for one-sided refspecs
198- let spec1 = gix_refspec:: parse ( "refs/*/foo/*" . into ( ) , Operation :: Fetch ) ;
199- assert ! ( spec1 . is_ok( ) , "Should parse complex glob pattern for one-sided refspec" ) ;
197+ let spec = gix_refspec:: parse ( "refs/*/foo/*" . into ( ) , Operation :: Fetch ) ;
198+ assert ! ( spec . is_ok( ) , "Should parse complex glob pattern for one-sided refspec" ) ;
200199
201- let spec2 = gix_refspec:: parse ( "refs/*/*/bar" . into ( ) , Operation :: Fetch ) ;
200+ let spec = gix_refspec:: parse ( "refs/*/*/bar" . into ( ) , Operation :: Fetch ) ;
202201 assert ! (
203- spec2 . is_ok( ) ,
202+ spec . is_ok( ) ,
204203 "Should parse complex glob pattern with multiple asterisks"
205204 ) ;
206205
207- let spec3 = gix_refspec:: parse ( "refs/heads/* /release/*" . into ( ) , Operation :: Fetch ) ;
208- assert ! ( spec3 . is_ok( ) , "Should parse complex glob pattern" ) ;
206+ let spec = gix_refspec:: parse ( "refs/heads/[a-z.] /release/*" . into ( ) , Operation :: Fetch ) ;
207+ assert ! ( spec . is_ok( ) , "Should parse complex glob pattern" ) ;
209208
210209 // Two-sided refspecs with multiple asterisks should still fail
211- let spec4 = gix_refspec:: parse ( "refs/*/foo/*:refs/remotes/*" . into ( ) , Operation :: Fetch ) ;
212- assert ! ( spec4 . is_err( ) , "Two-sided refspecs with multiple asterisks should fail" ) ;
210+ let spec = gix_refspec:: parse ( "refs/*/foo/*:refs/remotes/*" . into ( ) , Operation :: Fetch ) ;
211+ assert ! ( spec . is_err( ) , "Two-sided refspecs with multiple asterisks should fail" ) ;
213212 }
214213
215214 #[ test]
216215 fn one_sided_simple_glob_patterns_match ( ) {
217216 // Test that simple glob patterns (one asterisk) work correctly with matching
218217 let refs = vec ! [
219- create_ref ( "refs/heads/feature/foo" , "1111111111111111111111111111111111111111" ) ,
220- create_ref ( "refs/heads/bugfix/bar" , "2222222222222222222222222222222222222222" ) ,
221- create_ref ( "refs/tags/v1.0" , "3333333333333333333333333333333333333333" ) ,
222- create_ref ( "refs/pull/123" , "4444444444444444444444444444444444444444" ) ,
218+ new_ref ( "refs/heads/feature/foo" , "1111111111111111111111111111111111111111" ) ,
219+ new_ref ( "refs/heads/bugfix/bar" , "2222222222222222222222222222222222222222" ) ,
220+ new_ref ( "refs/tags/v1.0" , "3333333333333333333333333333333333333333" ) ,
221+ new_ref ( "refs/pull/123" , "4444444444444444444444444444444444444444" ) ,
223222 ] ;
224223 let items: Vec < _ > = refs. iter ( ) . map ( |r| r. to_item ( ) ) . collect ( ) ;
225224
226225 // Test: refs/heads/* should match all refs under refs/heads/
227226 let spec = gix_refspec:: parse ( "refs/heads/*" . into ( ) , Operation :: Fetch ) . unwrap ( ) ;
228227 let group = MatchGroup :: from_fetch_specs ( [ spec] ) ;
229228 let outcome = group. match_lhs ( items. iter ( ) . copied ( ) ) ;
230- let mappings = outcome. mappings ;
231229
232- assert_eq ! ( mappings. len( ) , 2 , "Should match two refs under refs/heads/" ) ;
230+ insta:: assert_debug_snapshot!( outcome. mappings, @r#"
231+ [
232+ Mapping {
233+ item_index: Some(
234+ 0,
235+ ),
236+ lhs: FullName(
237+ "refs/heads/feature/foo",
238+ ),
239+ rhs: None,
240+ spec_index: 0,
241+ },
242+ Mapping {
243+ item_index: Some(
244+ 1,
245+ ),
246+ lhs: FullName(
247+ "refs/heads/bugfix/bar",
248+ ),
249+ rhs: None,
250+ spec_index: 0,
251+ },
252+ ]
253+ "# ) ;
233254
234255 // Test: refs/tags/* should match all refs under refs/tags/
235- let items2: Vec < _ > = refs. iter ( ) . map ( |r| r. to_item ( ) ) . collect ( ) ;
236- let spec2 = gix_refspec:: parse ( "refs/tags/*" . into ( ) , Operation :: Fetch ) . unwrap ( ) ;
237- let group2 = MatchGroup :: from_fetch_specs ( [ spec2] ) ;
238- let outcome2 = group2. match_lhs ( items2. iter ( ) . copied ( ) ) ;
239- let mappings2 = outcome2. mappings ;
256+ let items: Vec < _ > = refs. iter ( ) . map ( |r| r. to_item ( ) ) . collect ( ) ;
257+ let spec = gix_refspec:: parse ( "refs/tags/v[0.9]*" . into ( ) , Operation :: Fetch ) . unwrap ( ) ;
258+ let group = MatchGroup :: from_fetch_specs ( [ spec] ) ;
259+ let outcome = group. match_lhs ( items. iter ( ) . copied ( ) ) ;
240260
241- assert_eq ! ( mappings2. len( ) , 1 , "Should match one ref under refs/tags/" ) ;
261+ insta:: assert_debug_snapshot!( outcome. mappings, @r#"
262+ [
263+ Mapping {
264+ item_index: Some(
265+ 2,
266+ ),
267+ lhs: FullName(
268+ "refs/tags/v1.0",
269+ ),
270+ rhs: None,
271+ spec_index: 0,
272+ },
273+ ]
274+ "# ) ;
242275 }
243276
244277 #[ test]
245278 fn one_sided_glob_with_suffix_matches ( ) {
246279 // Test that glob patterns with suffix work correctly
247280 let refs = vec ! [
248- create_ref ( "refs/heads/feature" , "1111111111111111111111111111111111111111" ) ,
249- create_ref ( "refs/heads/feat" , "2222222222222222222222222222222222222222" ) ,
250- create_ref ( "refs/heads/main" , "3333333333333333333333333333333333333333" ) ,
281+ new_ref ( "refs/heads/feature" , "1111111111111111111111111111111111111111" ) ,
282+ new_ref ( "refs/heads/feat" , "2222222222222222222222222222222222222222" ) ,
283+ new_ref ( "refs/heads/main" , "3333333333333333333333333333333333333333" ) ,
251284 ] ;
252285 let items: Vec < _ > = refs. iter ( ) . map ( |r| r. to_item ( ) ) . collect ( ) ;
253286
@@ -257,11 +290,33 @@ mod complex_globs {
257290 let outcome = group. match_lhs ( items. iter ( ) . copied ( ) ) ;
258291 let mappings = outcome. mappings ;
259292
260- assert_eq ! ( mappings. len( ) , 2 , "Should match two refs starting with feat" ) ;
293+ insta:: assert_debug_snapshot!( mappings, @r#"
294+ [
295+ Mapping {
296+ item_index: Some(
297+ 0,
298+ ),
299+ lhs: FullName(
300+ "refs/heads/feature",
301+ ),
302+ rhs: None,
303+ spec_index: 0,
304+ },
305+ Mapping {
306+ item_index: Some(
307+ 1,
308+ ),
309+ lhs: FullName(
310+ "refs/heads/feat",
311+ ),
312+ rhs: None,
313+ spec_index: 0,
314+ },
315+ ]
316+ "# ) ;
261317 }
262318
263- // Helper function to create a ref
264- fn create_ref ( name : & str , id_hex : & str ) -> Ref {
319+ fn new_ref ( name : & str , id_hex : & str ) -> Ref {
265320 Ref {
266321 name : name. into ( ) ,
267322 target : ObjectId :: from_hex ( id_hex. as_bytes ( ) ) . unwrap ( ) ,
0 commit comments