@@ -305,6 +305,7 @@ fn path_prefix_remapping() {
305
305
let mapping = & FilePathMapping :: new (
306
306
vec ! [ ( path( "abc/def" ) , path( "foo" ) ) ] ,
307
307
FileNameDisplayPreference :: Remapped ,
308
+ FileNameEmbeddablePreference :: RemappedOnly ,
308
309
) ;
309
310
310
311
assert_eq ! ( map_path_prefix( mapping, "abc/def/src/main.rs" ) , path_str( "foo/src/main.rs" ) ) ;
@@ -316,6 +317,7 @@ fn path_prefix_remapping() {
316
317
let mapping = & FilePathMapping :: new (
317
318
vec ! [ ( path( "abc/def" ) , path( "/foo" ) ) ] ,
318
319
FileNameDisplayPreference :: Remapped ,
320
+ FileNameEmbeddablePreference :: RemappedOnly ,
319
321
) ;
320
322
321
323
assert_eq ! ( map_path_prefix( mapping, "abc/def/src/main.rs" ) , path_str( "/foo/src/main.rs" ) ) ;
@@ -327,6 +329,7 @@ fn path_prefix_remapping() {
327
329
let mapping = & FilePathMapping :: new (
328
330
vec ! [ ( path( "/abc/def" ) , path( "foo" ) ) ] ,
329
331
FileNameDisplayPreference :: Remapped ,
332
+ FileNameEmbeddablePreference :: RemappedOnly ,
330
333
) ;
331
334
332
335
assert_eq ! ( map_path_prefix( mapping, "/abc/def/src/main.rs" ) , path_str( "foo/src/main.rs" ) ) ;
@@ -338,6 +341,7 @@ fn path_prefix_remapping() {
338
341
let mapping = & FilePathMapping :: new (
339
342
vec ! [ ( path( "/abc/def" ) , path( "/foo" ) ) ] ,
340
343
FileNameDisplayPreference :: Remapped ,
344
+ FileNameEmbeddablePreference :: RemappedOnly ,
341
345
) ;
342
346
343
347
assert_eq ! ( map_path_prefix( mapping, "/abc/def/src/main.rs" ) , path_str( "/foo/src/main.rs" ) ) ;
@@ -351,6 +355,7 @@ fn path_prefix_remapping_expand_to_absolute() {
351
355
let mapping = & FilePathMapping :: new (
352
356
vec ! [ ( path( "/foo" ) , path( "FOO" ) ) , ( path( "/bar" ) , path( "BAR" ) ) ] ,
353
357
FileNameDisplayPreference :: Remapped ,
358
+ FileNameEmbeddablePreference :: RemappedOnly ,
354
359
) ;
355
360
let working_directory = path ( "/foo" ) ;
356
361
let working_directory = RealFileName :: Remapped {
@@ -448,13 +453,79 @@ fn path_prefix_remapping_expand_to_absolute() {
448
453
) ;
449
454
}
450
455
456
+ #[ test]
457
+ fn path_prefix_remapping_expand_to_absolute_and_local ( ) {
458
+ // "virtual" working directory is relative path
459
+ let mapping = & FilePathMapping :: new (
460
+ vec ! [ ( path( "/foo" ) , path( "FOO" ) ) , ( path( "/bar" ) , path( "BAR" ) ) ] ,
461
+ FileNameDisplayPreference :: Remapped ,
462
+ FileNameEmbeddablePreference :: LocalAndRemapped ,
463
+ ) ;
464
+ let working_directory = path ( "/foo" ) ;
465
+ let working_directory = RealFileName :: Remapped {
466
+ local_path : Some ( working_directory. clone ( ) ) ,
467
+ virtual_name : mapping. map_prefix ( working_directory) . 0 . into_owned ( ) ,
468
+ } ;
469
+
470
+ assert_eq ! ( working_directory. remapped_path_if_available( ) , path( "FOO" ) ) ;
471
+
472
+ // Unmapped absolute path
473
+ assert_eq ! (
474
+ mapping. to_embeddable_absolute_path(
475
+ RealFileName :: LocalPath ( path( "/foo/src/main.rs" ) ) ,
476
+ & working_directory
477
+ ) ,
478
+ RealFileName :: Remapped {
479
+ local_path: Some ( path( "/foo/src/main.rs" ) ) ,
480
+ virtual_name: path( "FOO/src/main.rs" )
481
+ }
482
+ ) ;
483
+
484
+ // Unmapped absolute path with unrelated working directory
485
+ assert_eq ! (
486
+ mapping. to_embeddable_absolute_path(
487
+ RealFileName :: LocalPath ( path( "/bar/src/main.rs" ) ) ,
488
+ & working_directory
489
+ ) ,
490
+ RealFileName :: Remapped {
491
+ local_path: Some ( path( "/bar/src/main.rs" ) ) ,
492
+ virtual_name: path( "BAR/src/main.rs" )
493
+ }
494
+ ) ;
495
+
496
+ // Already remapped absolute path, with unrelated working directory
497
+ assert_eq ! (
498
+ mapping. to_embeddable_absolute_path(
499
+ RealFileName :: Remapped {
500
+ local_path: Some ( path( "/bar/src/main.rs" ) ) ,
501
+ virtual_name: path( "BAR/src/main.rs" ) ,
502
+ } ,
503
+ & working_directory
504
+ ) ,
505
+ RealFileName :: Remapped {
506
+ local_path: Some ( path( "/bar/src/main.rs" ) ) ,
507
+ virtual_name: path( "BAR/src/main.rs" )
508
+ }
509
+ ) ;
510
+
511
+ // Already remapped relative path
512
+ assert_eq ! (
513
+ mapping. to_embeddable_absolute_path(
514
+ RealFileName :: Remapped { local_path: None , virtual_name: path( "XYZ/src/main.rs" ) } ,
515
+ & working_directory
516
+ ) ,
517
+ RealFileName :: Remapped { local_path: None , virtual_name: path( "XYZ/src/main.rs" ) }
518
+ ) ;
519
+ }
520
+
451
521
#[ test]
452
522
fn path_prefix_remapping_reverse ( ) {
453
523
// Ignores options without alphanumeric chars.
454
524
{
455
525
let mapping = & FilePathMapping :: new (
456
526
vec ! [ ( path( "abc" ) , path( "/" ) ) , ( path( "def" ) , path( "." ) ) ] ,
457
527
FileNameDisplayPreference :: Remapped ,
528
+ FileNameEmbeddablePreference :: RemappedOnly ,
458
529
) ;
459
530
460
531
assert_eq ! ( reverse_map_prefix( mapping, "/hello.rs" ) , None ) ;
@@ -466,6 +537,7 @@ fn path_prefix_remapping_reverse() {
466
537
let mapping = & FilePathMapping :: new (
467
538
vec ! [ ( path( "abc" ) , path( "/redacted" ) ) , ( path( "def" ) , path( "/redacted" ) ) ] ,
468
539
FileNameDisplayPreference :: Remapped ,
540
+ FileNameEmbeddablePreference :: RemappedOnly ,
469
541
) ;
470
542
471
543
assert_eq ! ( reverse_map_prefix( mapping, "/redacted/hello.rs" ) , None ) ;
@@ -476,6 +548,7 @@ fn path_prefix_remapping_reverse() {
476
548
let mapping = & FilePathMapping :: new (
477
549
vec ! [ ( path( "abc" ) , path( "/redacted" ) ) , ( path( "def/ghi" ) , path( "/fake/dir" ) ) ] ,
478
550
FileNameDisplayPreference :: Remapped ,
551
+ FileNameEmbeddablePreference :: RemappedOnly ,
479
552
) ;
480
553
481
554
assert_eq ! (
0 commit comments