@@ -180,10 +180,13 @@ impl PackageIdSpec {
180
180
}
181
181
}
182
182
183
- match self . url {
184
- Some ( ref u) => u == package_id. source_id ( ) . url ( ) ,
185
- None => true ,
183
+ if let Some ( u) = & self . url {
184
+ if u != package_id. source_id ( ) . url ( ) {
185
+ return false ;
186
+ }
186
187
}
188
+
189
+ true
187
190
}
188
191
189
192
/// Checks a list of `PackageId`s to find 1 that matches this `PackageIdSpec`. If 0, 2, or
@@ -331,7 +334,10 @@ mod tests {
331
334
fn ok ( spec : & str , expected : PackageIdSpec , expected_rendered : & str ) {
332
335
let parsed = PackageIdSpec :: parse ( spec) . unwrap ( ) ;
333
336
assert_eq ! ( parsed, expected) ;
334
- assert_eq ! ( parsed. to_string( ) , expected_rendered) ;
337
+ let rendered = parsed. to_string ( ) ;
338
+ assert_eq ! ( rendered, expected_rendered) ;
339
+ let reparsed = PackageIdSpec :: parse ( & rendered) . unwrap ( ) ;
340
+ assert_eq ! ( reparsed, expected) ;
335
341
}
336
342
337
343
ok (
@@ -424,6 +430,98 @@ mod tests {
424
430
} ,
425
431
"foo@1.2" ,
426
432
) ;
433
+
434
+ // pkgid-spec.md
435
+ ok (
436
+ "regex" ,
437
+ PackageIdSpec {
438
+ name : String :: from ( "regex" ) ,
439
+ version : None ,
440
+ url : None ,
441
+ } ,
442
+ "regex" ,
443
+ ) ;
444
+ ok (
445
+ "regex@1.4" ,
446
+ PackageIdSpec {
447
+ name : String :: from ( "regex" ) ,
448
+ version : Some ( "1.4" . parse ( ) . unwrap ( ) ) ,
449
+ url : None ,
450
+ } ,
451
+ "regex@1.4" ,
452
+ ) ;
453
+ ok (
454
+ "regex@1.4.3" ,
455
+ PackageIdSpec {
456
+ name : String :: from ( "regex" ) ,
457
+ version : Some ( "1.4.3" . parse ( ) . unwrap ( ) ) ,
458
+ url : None ,
459
+ } ,
460
+ "regex@1.4.3" ,
461
+ ) ;
462
+ ok (
463
+ "https://github.com/rust-lang/crates.io-index#regex" ,
464
+ PackageIdSpec {
465
+ name : String :: from ( "regex" ) ,
466
+ version : None ,
467
+ url : Some ( Url :: parse ( "https://github.com/rust-lang/crates.io-index" ) . unwrap ( ) ) ,
468
+ } ,
469
+ "https://github.com/rust-lang/crates.io-index#regex" ,
470
+ ) ;
471
+ ok (
472
+ "https://github.com/rust-lang/crates.io-index#regex@1.4.3" ,
473
+ PackageIdSpec {
474
+ name : String :: from ( "regex" ) ,
475
+ version : Some ( "1.4.3" . parse ( ) . unwrap ( ) ) ,
476
+ url : Some ( Url :: parse ( "https://github.com/rust-lang/crates.io-index" ) . unwrap ( ) ) ,
477
+ } ,
478
+ "https://github.com/rust-lang/crates.io-index#regex@1.4.3" ,
479
+ ) ;
480
+ ok (
481
+ "https://github.com/rust-lang/cargo#0.52.0" ,
482
+ PackageIdSpec {
483
+ name : String :: from ( "cargo" ) ,
484
+ version : Some ( "0.52.0" . parse ( ) . unwrap ( ) ) ,
485
+ url : Some ( Url :: parse ( "https://github.com/rust-lang/cargo" ) . unwrap ( ) ) ,
486
+ } ,
487
+ "https://github.com/rust-lang/cargo#0.52.0" ,
488
+ ) ;
489
+ ok (
490
+ "https://github.com/rust-lang/cargo#cargo-platform@0.1.2" ,
491
+ PackageIdSpec {
492
+ name : String :: from ( "cargo-platform" ) ,
493
+ version : Some ( "0.1.2" . parse ( ) . unwrap ( ) ) ,
494
+ url : Some ( Url :: parse ( "https://github.com/rust-lang/cargo" ) . unwrap ( ) ) ,
495
+ } ,
496
+ "https://github.com/rust-lang/cargo#cargo-platform@0.1.2" ,
497
+ ) ;
498
+ ok (
499
+ "ssh://git@github.com/rust-lang/regex.git#regex@1.4.3" ,
500
+ PackageIdSpec {
501
+ name : String :: from ( "regex" ) ,
502
+ version : Some ( "1.4.3" . parse ( ) . unwrap ( ) ) ,
503
+ url : Some ( Url :: parse ( "ssh://git@github.com/rust-lang/regex.git" ) . unwrap ( ) ) ,
504
+ } ,
505
+ "ssh://git@github.com/rust-lang/regex.git#regex@1.4.3" ,
506
+ ) ;
507
+ ok (
508
+ "file:///path/to/my/project/foo" ,
509
+ PackageIdSpec {
510
+ name : String :: from ( "foo" ) ,
511
+ version : None ,
512
+ url : Some ( Url :: parse ( "file:///path/to/my/project/foo" ) . unwrap ( ) ) ,
513
+ } ,
514
+ "file:///path/to/my/project/foo" ,
515
+ ) ;
516
+ ok (
517
+ "file:///path/to/my/project/foo#1.1.8" ,
518
+ PackageIdSpec {
519
+ name : String :: from ( "foo" ) ,
520
+ version : Some ( "1.1.8" . parse ( ) . unwrap ( ) ) ,
521
+ url : Some ( Url :: parse ( "file:///path/to/my/project/foo" ) . unwrap ( ) ) ,
522
+ } ,
523
+ "file:///path/to/my/project/foo#1.1.8" ,
524
+ ) ;
427
525
}
428
526
429
527
#[ test]
@@ -450,6 +548,12 @@ mod tests {
450
548
assert ! ( PackageIdSpec :: parse( "foo@1.2.3" ) . unwrap( ) . matches( foo) ) ;
451
549
assert ! ( !PackageIdSpec :: parse( "foo@1.2.2" ) . unwrap( ) . matches( foo) ) ;
452
550
assert ! ( PackageIdSpec :: parse( "foo@1.2" ) . unwrap( ) . matches( foo) ) ;
551
+ assert ! ( PackageIdSpec :: parse( "https://example.com#foo@1.2" )
552
+ . unwrap( )
553
+ . matches( foo) ) ;
554
+ assert ! ( !PackageIdSpec :: parse( "https://bob.com#foo@1.2" )
555
+ . unwrap( )
556
+ . matches( foo) ) ;
453
557
454
558
let meta = PackageId :: new ( "meta" , "1.2.3+hello" , sid) . unwrap ( ) ;
455
559
assert ! ( PackageIdSpec :: parse( "meta" ) . unwrap( ) . matches( meta) ) ;
0 commit comments