@@ -271,7 +271,7 @@ impl GenericPath for Path {
271
271
}
272
272
}
273
273
}
274
- Some ( Path :: new ( comps. connect_vec ( & sep) ) )
274
+ Some ( Path :: from_vec ( comps. connect_vec ( & sep) ) )
275
275
}
276
276
}
277
277
}
@@ -283,7 +283,7 @@ impl Path {
283
283
///
284
284
/// Raises the `null_byte` condition if the vector contains a NUL.
285
285
#[ inline]
286
- pub fn new ( v : & [ u8 ] ) -> Path {
286
+ pub fn from_vec ( v : & [ u8 ] ) -> Path {
287
287
GenericPath :: from_vec ( v)
288
288
}
289
289
@@ -433,12 +433,12 @@ mod tests {
433
433
434
434
#[ test]
435
435
fn test_paths ( ) {
436
- t ! ( v: Path :: new ( [ ] ) , b!( "." ) ) ;
437
- t ! ( v: Path :: new ( b!( "/" ) ) , b!( "/" ) ) ;
438
- t ! ( v: Path :: new ( b!( "a/b/c" ) ) , b!( "a/b/c" ) ) ;
439
- t ! ( v: Path :: new ( b!( "a/b/c" , 0xff ) ) , b!( "a/b/c" , 0xff ) ) ;
440
- t ! ( v: Path :: new ( b!( 0xff , "/../foo" , 0x80 ) ) , b!( "foo" , 0x80 ) ) ;
441
- let p = Path :: new ( b ! ( "a/b/c" , 0xff ) ) ;
436
+ t ! ( v: Path :: from_vec ( [ ] ) , b!( "." ) ) ;
437
+ t ! ( v: Path :: from_vec ( b!( "/" ) ) , b!( "/" ) ) ;
438
+ t ! ( v: Path :: from_vec ( b!( "a/b/c" ) ) , b!( "a/b/c" ) ) ;
439
+ t ! ( v: Path :: from_vec ( b!( "a/b/c" , 0xff ) ) , b!( "a/b/c" , 0xff ) ) ;
440
+ t ! ( v: Path :: from_vec ( b!( 0xff , "/../foo" , 0x80 ) ) , b!( "foo" , 0x80 ) ) ;
441
+ let p = Path :: from_vec ( b ! ( "a/b/c" , 0xff ) ) ;
442
442
assert_eq ! ( p. as_str( ) , None ) ;
443
443
444
444
t ! ( s: Path :: from_str( "" ) , "." ) ;
@@ -464,15 +464,15 @@ mod tests {
464
464
t ! ( s: Path :: from_str( "foo/../../.." ) , "../.." ) ;
465
465
t ! ( s: Path :: from_str( "foo/../../bar" ) , "../bar" ) ;
466
466
467
- assert_eq ! ( Path :: new ( b!( "foo/bar" ) ) . into_vec( ) , b!( "foo/bar" ) . to_owned( ) ) ;
468
- assert_eq ! ( Path :: new ( b!( "/foo/../../bar" ) ) . into_vec( ) ,
467
+ assert_eq ! ( Path :: from_vec ( b!( "foo/bar" ) ) . into_vec( ) , b!( "foo/bar" ) . to_owned( ) ) ;
468
+ assert_eq ! ( Path :: from_vec ( b!( "/foo/../../bar" ) ) . into_vec( ) ,
469
469
b!( "/bar" ) . to_owned( ) ) ;
470
470
assert_eq ! ( Path :: from_str( "foo/bar" ) . into_str( ) , Some ( ~"foo/bar"));
471
471
assert_eq!(Path::from_str(" /foo/../../bar").into_str(), Some(~" /bar"));
472
472
473
- let p = Path::new (b!(" foo/bar", 0x80));
473
+ let p = Path::from_vec (b!(" foo/bar", 0x80));
474
474
assert_eq!(p.as_str(), None);
475
- assert_eq!(Path::new (b!(" foo", 0xff, " /bar")).into_str(), None);
475
+ assert_eq!(Path::from_vec (b!(" foo", 0xff, " /bar")).into_str(), None);
476
476
}
477
477
478
478
#[test]
@@ -485,7 +485,7 @@ mod tests {
485
485
assert_eq!(v.as_slice(), b!(" foo/bar", 0));
486
486
(b!(" /bar").to_owned())
487
487
}).inside {
488
- Path::new (b!(" foo/bar", 0))
488
+ Path::from_vec (b!(" foo/bar", 0))
489
489
};
490
490
assert!(handled);
491
491
assert_eq!(p.as_vec(), b!(" /bar"));
@@ -541,16 +541,16 @@ mod tests {
541
541
)
542
542
)
543
543
544
- t!(~" new ( ) w/nul" => {
544
+ t!(~" from_vec ( ) w/nul" => {
545
545
do cond.trap(|_| {
546
546
(b!(" null", 0).to_owned())
547
547
}).inside {
548
- Path::new (b!(" foo/bar", 0))
548
+ Path::from_vec (b!(" foo/bar", 0))
549
549
};
550
550
})
551
551
552
552
t!(~" set_filename w/nul" => {
553
- let mut p = Path::new (b!(" foo/bar"));
553
+ let mut p = Path::from_vec (b!(" foo/bar"));
554
554
do cond.trap(|_| {
555
555
(b!(" null", 0).to_owned())
556
556
}).inside {
@@ -559,7 +559,7 @@ mod tests {
559
559
})
560
560
561
561
t!(~" set_dirname w/nul" => {
562
- let mut p = Path::new (b!(" foo/bar"));
562
+ let mut p = Path::from_vec (b!(" foo/bar"));
563
563
do cond.trap(|_| {
564
564
(b!(" null", 0).to_owned())
565
565
}).inside {
@@ -568,7 +568,7 @@ mod tests {
568
568
})
569
569
570
570
t!(~" push w/nul" => {
571
- let mut p = Path::new (b!(" foo/bar"));
571
+ let mut p = Path::from_vec (b!(" foo/bar"));
572
572
do cond.trap(|_| {
573
573
(b!(" null", 0).to_owned())
574
574
}).inside {
@@ -595,7 +595,7 @@ mod tests {
595
595
);
596
596
(v: $path:expr, $op:ident, $exp:expr) => (
597
597
{
598
- let path = Path::new ($path);
598
+ let path = Path::from_vec ($path);
599
599
assert_eq!(path.$op(), $exp);
600
600
}
601
601
)
@@ -715,15 +715,15 @@ mod tests {
715
715
);
716
716
(v: [$($path:expr),+], [$($left:expr),+], Some($($right:expr),+)) => (
717
717
{
718
- let mut p = Path::new (b!($($path),+));
718
+ let mut p = Path::from_vec (b!($($path),+));
719
719
let file = p.pop_opt();
720
720
assert_eq!(p.as_vec(), b!($($left),+));
721
721
assert_eq!(file.map(|v| v.as_slice()), Some(b!($($right),+)));
722
722
}
723
723
);
724
724
(v: [$($path:expr),+], [$($left:expr),+], None) => (
725
725
{
726
- let mut p = Path::new (b!($($path),+));
726
+ let mut p = Path::from_vec (b!($($path),+));
727
727
let file = p.pop_opt();
728
728
assert_eq!(p.as_vec(), b!($($left),+));
729
729
assert_eq!(file, None);
@@ -746,15 +746,15 @@ mod tests {
746
746
t!(s: " /a", " /", Some(" a"));
747
747
t!(s: " /", " /", None);
748
748
749
- assert_eq!(Path::new (b!(" foo/bar", 0x80)).pop_opt_str(), None);
750
- assert_eq!(Path::new (b!(" foo", 0x80, " /bar")).pop_opt_str(), Some(~" bar"));
749
+ assert_eq!(Path::from_vec (b!(" foo/bar", 0x80)).pop_opt_str(), None);
750
+ assert_eq!(Path::from_vec (b!(" foo", 0x80, " /bar")).pop_opt_str(), Some(~" bar"));
751
751
}
752
752
753
753
#[test]
754
754
fn test_join() {
755
- t!(v: Path::new (b!(" a/b/c")).join(b!(" ..")), b!(" a/b"));
756
- t!(v: Path::new (b!(" /a/b/c")).join(b!(" d")), b!(" /a/b/c/d"));
757
- t!(v: Path::new (b!(" a/", 0x80, " /c")).join(b!(0xff)), b!(" a/", 0x80, " /c/", 0xff));
755
+ t!(v: Path::from_vec (b!(" a/b/c")).join(b!(" ..")), b!(" a/b"));
756
+ t!(v: Path::from_vec (b!(" /a/b/c")).join(b!(" d")), b!(" /a/b/c/d"));
757
+ t!(v: Path::from_vec (b!(" a/", 0x80, " /c")).join(b!(0xff)), b!(" a/", 0x80, " /c/", 0xff));
758
758
t!(s: Path::from_str(" a/b/c").join_str(" .."), " a/b");
759
759
t!(s: Path::from_str(" /a/b/c").join_str(" d"), " /a/b/c/d");
760
760
t!(s: Path::from_str(" a/b").join_str(" c/d"), " a/b/c/d");
@@ -786,10 +786,10 @@ mod tests {
786
786
787
787
#[test]
788
788
fn test_with_helpers() {
789
- t!(v: Path::new (b!(" a/b/c")).with_dirname(b!(" d")), b!(" d/c"));
790
- t!(v: Path::new (b!(" a/b/c")).with_dirname(b!(" d/e")), b!(" d/e/c"));
791
- t!(v: Path::new (b!(" a/", 0x80, " b/c")).with_dirname(b!(0xff)), b!(0xff, " /c"));
792
- t!(v: Path::new (b!(" a/b/", 0x80)).with_dirname(b!(" /", 0xcd)),
789
+ t!(v: Path::from_vec (b!(" a/b/c")).with_dirname(b!(" d")), b!(" d/c"));
790
+ t!(v: Path::from_vec (b!(" a/b/c")).with_dirname(b!(" d/e")), b!(" d/e/c"));
791
+ t!(v: Path::from_vec (b!(" a/", 0x80, " b/c")).with_dirname(b!(0xff)), b!(0xff, " /c"));
792
+ t!(v: Path::from_vec (b!(" a/b/", 0x80)).with_dirname(b!(" /", 0xcd)),
793
793
b!(" /", 0xcd, " /", 0x80));
794
794
t!(s: Path::from_str(" a/b/c").with_dirname_str(" d"), " d/c");
795
795
t!(s: Path::from_str(" a/b/c").with_dirname_str(" d/e"), " d/e/c");
@@ -807,9 +807,9 @@ mod tests {
807
807
t!(s: Path::from_str(" foo").with_dirname_str(" .."), " ../foo");
808
808
t!(s: Path::from_str(" foo").with_dirname_str(" ../.."), " ../../foo");
809
809
810
- t!(v: Path::new (b!(" a/b/c")).with_filename(b!(" d")), b!(" a/b/d"));
811
- t!(v: Path::new (b!(" a/b/c", 0xff)).with_filename(b!(0x80)), b!(" a/b/", 0x80));
812
- t!(v: Path::new (b!(" /", 0xff, " /foo")).with_filename(b!(0xcd)),
810
+ t!(v: Path::from_vec (b!(" a/b/c")).with_filename(b!(" d")), b!(" a/b/d"));
811
+ t!(v: Path::from_vec (b!(" a/b/c", 0xff)).with_filename(b!(0x80)), b!(" a/b/", 0x80));
812
+ t!(v: Path::from_vec (b!(" /", 0xff, " /foo")).with_filename(b!(0xcd)),
813
813
b!(" /", 0xff, " /", 0xcd));
814
814
t!(s: Path::from_str(" a/b/c").with_filename_str(" d"), " a/b/d");
815
815
t!(s: Path::from_str(" . ").with_filename_str(" foo"), " foo");
@@ -831,12 +831,12 @@ mod tests {
831
831
t!(s: Path::from_str(" ..").with_filename_str(" "), " ..");
832
832
t!(s: Path::from_str(" ../..").with_filename_str(" "), " ../..");
833
833
834
- t!(v: Path::new (b!(" hi/there", 0x80, " . txt")).with_filestem(b!(0xff)),
834
+ t!(v: Path::from_vec (b!(" hi/there", 0x80, " . txt")).with_filestem(b!(0xff)),
835
835
b!(" hi/", 0xff, " . txt"));
836
- t!(v: Path::new (b!(" hi/there. txt", 0x80)).with_filestem(b!(0xff)),
836
+ t!(v: Path::from_vec (b!(" hi/there. txt", 0x80)).with_filestem(b!(0xff)),
837
837
b!(" hi/", 0xff, " . txt", 0x80));
838
- t!(v: Path::new (b!(" hi/there", 0xff)).with_filestem(b!(0x80)), b!(" hi/", 0x80));
839
- t!(v: Path::new (b!(" hi", 0x80, " /there")).with_filestem([]), b!(" hi", 0x80));
838
+ t!(v: Path::from_vec (b!(" hi/there", 0xff)).with_filestem(b!(0x80)), b!(" hi/", 0x80));
839
+ t!(v: Path::from_vec (b!(" hi", 0x80, " /there")).with_filestem([]), b!(" hi", 0x80));
840
840
t!(s: Path::from_str(" hi/there. txt").with_filestem_str(" here"), " hi/here. txt");
841
841
t!(s: Path::from_str(" hi/there. txt").with_filestem_str(" "), " hi/. txt");
842
842
t!(s: Path::from_str(" hi/there. txt").with_filestem_str(" . "), " hi/..txt");
@@ -859,13 +859,13 @@ mod tests {
859
859
t!(s: Path::from_str(" hi/there..").with_filestem_str(" here"), " hi/here. ");
860
860
t!(s: Path::from_str(" hi/there..").with_filestem_str(" "), " hi");
861
861
862
- t!(v: Path::new (b!(" hi/there", 0x80, " . txt")).with_extension(b!(" exe")),
862
+ t!(v: Path::from_vec (b!(" hi/there", 0x80, " . txt")).with_extension(b!(" exe")),
863
863
b!(" hi/there", 0x80, " . exe"));
864
- t!(v: Path::new (b!(" hi/there. txt", 0x80)).with_extension(b!(0xff)),
864
+ t!(v: Path::from_vec (b!(" hi/there. txt", 0x80)).with_extension(b!(0xff)),
865
865
b!(" hi/there. ", 0xff));
866
- t!(v: Path::new (b!(" hi/there", 0x80)).with_extension(b!(0xff)),
866
+ t!(v: Path::from_vec (b!(" hi/there", 0x80)).with_extension(b!(0xff)),
867
867
b!(" hi/there", 0x80, " . ", 0xff));
868
- t!(v: Path::new (b!(" hi/there. ", 0xff)).with_extension([]), b!(" hi/there"));
868
+ t!(v: Path::from_vec (b!(" hi/there. ", 0xff)).with_extension([]), b!(" hi/there"));
869
869
t!(s: Path::from_str(" hi/there. txt").with_extension_str(" exe"), " hi/there. exe");
870
870
t!(s: Path::from_str(" hi/there. txt").with_extension_str(" "), " hi/there");
871
871
t!(s: Path::from_str(" hi/there. txt").with_extension_str(" . "), " hi/there..");
@@ -899,9 +899,9 @@ mod tests {
899
899
{
900
900
let path = $path;
901
901
let arg = $arg;
902
- let mut p1 = Path::new (path);
902
+ let mut p1 = Path::from_vec (path);
903
903
p1.$set(arg);
904
- let p2 = Path::new (path);
904
+ let p2 = Path::from_vec (path);
905
905
assert_eq!(p1, p2.$with(arg));
906
906
}
907
907
)
@@ -968,9 +968,9 @@ mod tests {
968
968
)
969
969
)
970
970
971
- t!(v: Path::new (b!(" a/b/c")), b!(" c"), b!(" a/b"), b!(" c"), None);
972
- t!(v: Path::new (b!(" a/b/", 0xff)), b!(0xff), b!(" a/b"), b!(0xff), None);
973
- t!(v: Path::new (b!(" hi/there. ", 0xff)), b!(" there. ", 0xff), b!(" hi"),
971
+ t!(v: Path::from_vec (b!(" a/b/c")), b!(" c"), b!(" a/b"), b!(" c"), None);
972
+ t!(v: Path::from_vec (b!(" a/b/", 0xff)), b!(0xff), b!(" a/b"), b!(0xff), None);
973
+ t!(v: Path::from_vec (b!(" hi/there. ", 0xff)), b!(" there. ", 0xff), b!(" hi"),
974
974
b!(" there"), Some(b!(0xff)));
975
975
t!(s: Path::from_str(" a/b/c"), Some(" c"), Some(" a/b"), Some(" c"), None);
976
976
t!(s: Path::from_str(" . "), Some(" "), Some(" . "), Some(" "), None);
@@ -985,16 +985,16 @@ mod tests {
985
985
t!(s: Path::from_str(" hi/. there"), Some(" . there"), Some(" hi"), Some(" . there"), None);
986
986
t!(s: Path::from_str(" hi/..there"), Some(" ..there"), Some(" hi"),
987
987
Some(" . "), Some(" there"));
988
- t!(s: Path::new (b!(" a/b/", 0xff)), None, Some(" a/b"), None, None);
989
- t!(s: Path::new (b!(" a/b/", 0xff, " . txt")), None, Some(" a/b"), None, Some(" txt"));
990
- t!(s: Path::new (b!(" a/b/c. ", 0x80)), None, Some(" a/b"), Some(" c"), None);
991
- t!(s: Path::new (b!(0xff, " /b")), Some(" b"), None, Some(" b"), None);
988
+ t!(s: Path::from_vec (b!(" a/b/", 0xff)), None, Some(" a/b"), None, None);
989
+ t!(s: Path::from_vec (b!(" a/b/", 0xff, " . txt")), None, Some(" a/b"), None, Some(" txt"));
990
+ t!(s: Path::from_vec (b!(" a/b/c. ", 0x80)), None, Some(" a/b"), Some(" c"), None);
991
+ t!(s: Path::from_vec (b!(0xff, " /b")), Some(" b"), None, Some(" b"), None);
992
992
}
993
993
994
994
#[test]
995
995
fn test_dir_file_path() {
996
- t!(v: Path::new (b!(" hi/there", 0x80)).dir_path(), b!(" hi"));
997
- t!(v: Path::new (b!(" hi", 0xff, " /there")).dir_path(), b!(" hi", 0xff));
996
+ t!(v: Path::from_vec (b!(" hi/there", 0x80)).dir_path(), b!(" hi"));
997
+ t!(v: Path::from_vec (b!(" hi", 0xff, " /there")).dir_path(), b!(" hi", 0xff));
998
998
t!(s: Path::from_str(" hi/there").dir_path(), " hi");
999
999
t!(s: Path::from_str(" hi").dir_path(), " . ");
1000
1000
t!(s: Path::from_str(" /hi").dir_path(), " /");
@@ -1019,8 +1019,8 @@ mod tests {
1019
1019
)
1020
1020
)
1021
1021
1022
- t!(v: Path::new (b!(" hi/there", 0x80)).file_path(), Some(b!(" there", 0x80)));
1023
- t!(v: Path::new (b!(" hi", 0xff, " /there")).file_path(), Some(b!(" there")));
1022
+ t!(v: Path::from_vec (b!(" hi/there", 0x80)).file_path(), Some(b!(" there", 0x80)));
1023
+ t!(v: Path::from_vec (b!(" hi", 0xff, " /there")).file_path(), Some(b!(" there")));
1024
1024
t!(s: Path::from_str(" hi/there").file_path(), Some(" there"));
1025
1025
t!(s: Path::from_str(" hi").file_path(), Some(" hi"));
1026
1026
t!(s: Path::from_str(" . ").file_path(), None);
@@ -1134,7 +1134,7 @@ mod tests {
1134
1134
);
1135
1135
(v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => (
1136
1136
{
1137
- let path = Path::new (b!($($arg),+));
1137
+ let path = Path::from_vec (b!($($arg),+));
1138
1138
let comps = path.component_iter().to_owned_vec();
1139
1139
let exp: &[&[u8]] = [$(b!($($exp),*)),*];
1140
1140
assert_eq!(comps.as_slice(), exp);
0 commit comments