@@ -305,6 +305,7 @@ fn path_prefix_remapping() {
305305 let mapping = & FilePathMapping :: new (
306306 vec ! [ ( path( "abc/def" ) , path( "foo" ) ) ] ,
307307 FileNameDisplayPreference :: Remapped ,
308+ FileNameEmbeddablePreference :: RemappedOnly ,
308309 ) ;
309310
310311 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() {
316317 let mapping = & FilePathMapping :: new (
317318 vec ! [ ( path( "abc/def" ) , path( "/foo" ) ) ] ,
318319 FileNameDisplayPreference :: Remapped ,
320+ FileNameEmbeddablePreference :: RemappedOnly ,
319321 ) ;
320322
321323 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() {
327329 let mapping = & FilePathMapping :: new (
328330 vec ! [ ( path( "/abc/def" ) , path( "foo" ) ) ] ,
329331 FileNameDisplayPreference :: Remapped ,
332+ FileNameEmbeddablePreference :: RemappedOnly ,
330333 ) ;
331334
332335 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() {
338341 let mapping = & FilePathMapping :: new (
339342 vec ! [ ( path( "/abc/def" ) , path( "/foo" ) ) ] ,
340343 FileNameDisplayPreference :: Remapped ,
344+ FileNameEmbeddablePreference :: RemappedOnly ,
341345 ) ;
342346
343347 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() {
351355 let mapping = & FilePathMapping :: new (
352356 vec ! [ ( path( "/foo" ) , path( "FOO" ) ) , ( path( "/bar" ) , path( "BAR" ) ) ] ,
353357 FileNameDisplayPreference :: Remapped ,
358+ FileNameEmbeddablePreference :: RemappedOnly ,
354359 ) ;
355360 let working_directory = path ( "/foo" ) ;
356361 let working_directory = RealFileName :: Remapped {
@@ -448,13 +453,79 @@ fn path_prefix_remapping_expand_to_absolute() {
448453 ) ;
449454}
450455
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+
451521#[ test]
452522fn path_prefix_remapping_reverse ( ) {
453523 // Ignores options without alphanumeric chars.
454524 {
455525 let mapping = & FilePathMapping :: new (
456526 vec ! [ ( path( "abc" ) , path( "/" ) ) , ( path( "def" ) , path( "." ) ) ] ,
457527 FileNameDisplayPreference :: Remapped ,
528+ FileNameEmbeddablePreference :: RemappedOnly ,
458529 ) ;
459530
460531 assert_eq ! ( reverse_map_prefix( mapping, "/hello.rs" ) , None ) ;
@@ -466,6 +537,7 @@ fn path_prefix_remapping_reverse() {
466537 let mapping = & FilePathMapping :: new (
467538 vec ! [ ( path( "abc" ) , path( "/redacted" ) ) , ( path( "def" ) , path( "/redacted" ) ) ] ,
468539 FileNameDisplayPreference :: Remapped ,
540+ FileNameEmbeddablePreference :: RemappedOnly ,
469541 ) ;
470542
471543 assert_eq ! ( reverse_map_prefix( mapping, "/redacted/hello.rs" ) , None ) ;
@@ -476,6 +548,7 @@ fn path_prefix_remapping_reverse() {
476548 let mapping = & FilePathMapping :: new (
477549 vec ! [ ( path( "abc" ) , path( "/redacted" ) ) , ( path( "def/ghi" ) , path( "/fake/dir" ) ) ] ,
478550 FileNameDisplayPreference :: Remapped ,
551+ FileNameEmbeddablePreference :: RemappedOnly ,
479552 ) ;
480553
481554 assert_eq ! (
0 commit comments