Skip to content

Commit 9006419

Browse files
ericktgraydon
authored andcommitted
---
yaml --- r: 36395 b: refs/heads/try2 c: 28745ce h: refs/heads/master i: 36393: 662d669 36391: a73e601 v: v3
1 parent b0d4dae commit 9006419

File tree

2 files changed

+122
-128
lines changed

2 files changed

+122
-128
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ab5d84258e25eb74d0293df444e200561010b5df
8+
refs/heads/try2: 28745ce7c8d23444130b10cf101875ddbb4e174d
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libcore/path.rs

Lines changed: 121 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -498,90 +498,132 @@ pub pure fn normalize(components: &[~str]) -> ~[~str] {
498498
move cs
499499
}
500500
501-
#[test]
502-
fn test_double_slash_collapsing()
503-
{
504-
let path = PosixPath("tmp/");
505-
let path = path.push("/hmm");
506-
let path = path.normalize();
507-
assert ~"tmp/hmm" == path.to_str();
508-
509-
let path = WindowsPath("tmp/");
510-
let path = path.push("/hmm");
511-
let path = path.normalize();
512-
assert ~"tmp\\hmm" == path.to_str();
513-
}
514-
515-
mod posix {
501+
// Various windows helpers, and tests for the impl.
502+
mod windows {
503+
#[inline(always)]
504+
pub pure fn is_sep(u: u8) -> bool {
505+
u == '/' as u8 || u == '\\' as u8
506+
}
516507
517-
#[cfg(test)]
518-
fn mk(s: &str) -> PosixPath { PosixPath(s) }
508+
pub pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
509+
if (s.len() > 1 &&
510+
s[0] == '\\' as u8 &&
511+
s[1] == '\\' as u8) {
512+
let mut i = 2;
513+
while i < s.len() {
514+
if s[i] == '\\' as u8 {
515+
let pre = s.slice(2, i);
516+
let rest = s.slice(i, s.len());
517+
return Some((move pre, move rest));
518+
}
519+
i += 1;
520+
}
521+
}
522+
None
523+
}
519524
520-
#[cfg(test)]
521-
fn t(wp: &PosixPath, s: &str) {
522-
let ss = wp.to_str();
523-
let sss = str::from_slice(s);
524-
if (ss != sss) {
525-
debug!("got %s", ss);
526-
debug!("expected %s", sss);
527-
assert ss == sss;
525+
pub pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
526+
unsafe {
527+
if (s.len() > 1 &&
528+
libc::isalpha(s[0] as libc::c_int) != 0 &&
529+
s[1] == ':' as u8) {
530+
let rest = if s.len() == 2 {
531+
~""
532+
} else {
533+
s.slice(2, s.len())
534+
};
535+
return Some((s.slice(0,1), move rest));
536+
}
537+
None
528538
}
529539
}
540+
}
541+
542+
#[cfg(tests)]
543+
mod tests {
544+
#[test]
545+
fn test_double_slash_collapsing() {
546+
let path = PosixPath("tmp/");
547+
let path = path.push("/hmm");
548+
let path = path.normalize();
549+
assert ~"tmp/hmm" == path.to_str();
550+
551+
let path = WindowsPath("tmp/");
552+
let path = path.push("/hmm");
553+
let path = path.normalize();
554+
assert ~"tmp\\hmm" == path.to_str();
555+
}
530556

531557
#[test]
532558
fn test_filetype_foo_bar() {
533-
let wp = mk("foo.bar");
559+
let wp = PosixPath("foo.bar");
560+
assert wp.filetype() == Some(~".bar");
561+
562+
let wp = WindowsPath("foo.bar");
534563
assert wp.filetype() == Some(~".bar");
535564
}
536565

537566
#[test]
538567
fn test_filetype_foo() {
539-
let wp = mk("foo");
568+
let wp = PosixPath("foo");
569+
assert wp.filetype() == None;
570+
571+
let wp = WindowsPath("foo");
540572
assert wp.filetype() == None;
541573
}
542574

543575
#[test]
544576
fn test_posix_paths() {
545-
t(&(mk("hi")), "hi");
546-
t(&(mk("/lib")), "/lib");
547-
t(&(mk("hi/there")), "hi/there");
548-
t(&(mk("hi/there.txt")), "hi/there.txt");
577+
fn t(wp: &PosixPath, s: &str) {
578+
let ss = wp.to_str();
579+
let sss = str::from_slice(s);
580+
if (ss != sss) {
581+
debug!("got %s", ss);
582+
debug!("expected %s", sss);
583+
assert ss == sss;
584+
}
585+
}
586+
587+
t(&(PosixPath("hi")), "hi");
588+
t(&(PosixPath("/lib")), "/lib");
589+
t(&(PosixPath("hi/there")), "hi/there");
590+
t(&(PosixPath("hi/there.txt")), "hi/there.txt");
549591

550-
t(&(mk("hi/there.txt")), "hi/there.txt");
551-
t(&(mk("hi/there.txt")
592+
t(&(PosixPath("hi/there.txt")), "hi/there.txt");
593+
t(&(PosixPath("hi/there.txt")
552594
.with_filetype("")), "hi/there");
553595

554-
t(&(mk("/a/b/c/there.txt")
596+
t(&(PosixPath("/a/b/c/there.txt")
555597
.with_dirname("hi")), "hi/there.txt");
556598

557-
t(&(mk("hi/there.txt")
599+
t(&(PosixPath("hi/there.txt")
558600
.with_dirname(".")), "./there.txt");
559601

560-
t(&(mk("a/b/c")
602+
t(&(PosixPath("a/b/c")
561603
.push("..")), "a/b/c/..");
562604

563-
t(&(mk("there.txt")
605+
t(&(PosixPath("there.txt")
564606
.with_filetype("o")), "there.o");
565607

566-
t(&(mk("hi/there.txt")
608+
t(&(PosixPath("hi/there.txt")
567609
.with_filetype("o")), "hi/there.o");
568610

569-
t(&(mk("hi/there.txt")
611+
t(&(PosixPath("hi/there.txt")
570612
.with_filetype("o")
571613
.with_dirname("/usr/lib")),
572614
"/usr/lib/there.o");
573615

574-
t(&(mk("hi/there.txt")
616+
t(&(PosixPath("hi/there.txt")
575617
.with_filetype("o")
576618
.with_dirname("/usr/lib/")),
577619
"/usr/lib/there.o");
578620

579-
t(&(mk("hi/there.txt")
621+
t(&(PosixPath("hi/there.txt")
580622
.with_filetype("o")
581623
.with_dirname("/usr//lib//")),
582624
"/usr/lib/there.o");
583625

584-
t(&(mk("/usr/bin/rust")
626+
t(&(PosixPath("/usr/bin/rust")
585627
.push_many([~"lib", ~"thingy.so"])
586628
.with_filestem("librustc")),
587629
"/usr/bin/rust/lib/librustc.so");
@@ -590,86 +632,55 @@ mod posix {
590632

591633
#[test]
592634
fn test_normalize() {
593-
t(&(mk("hi/there.txt")
635+
fn t(wp: &PosixPath, s: &str) {
636+
let ss = wp.to_str();
637+
let sss = str::from_slice(s);
638+
if (ss != sss) {
639+
debug!("got %s", ss);
640+
debug!("expected %s", sss);
641+
assert ss == sss;
642+
}
643+
}
644+
645+
t(&(PosixPath("hi/there.txt")
594646
.with_dirname(".").normalize()), "there.txt");
595647

596-
t(&(mk("a/b/../c/././/../foo.txt/").normalize()),
648+
t(&(PosixPath("a/b/../c/././/../foo.txt/").normalize()),
597649
"a/foo.txt");
598650

599-
t(&(mk("a/b/c")
651+
t(&(PosixPath("a/b/c")
600652
.push("..").normalize()), "a/b");
601653
}
602-
}
603-
604-
// Various windows helpers, and tests for the impl.
605-
mod windows {
606-
607-
#[inline(always)]
608-
pub pure fn is_sep(u: u8) -> bool {
609-
u == '/' as u8 || u == '\\' as u8
610-
}
611-
612-
pub pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
613-
if (s.len() > 1 &&
614-
s[0] == '\\' as u8 &&
615-
s[1] == '\\' as u8) {
616-
let mut i = 2;
617-
while i < s.len() {
618-
if s[i] == '\\' as u8 {
619-
let pre = s.slice(2, i);
620-
let rest = s.slice(i, s.len());
621-
return Some((move pre, move rest));
622-
}
623-
i += 1;
624-
}
625-
}
626-
None
627-
}
628-
629-
pub pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
630-
unsafe {
631-
if (s.len() > 1 &&
632-
libc::isalpha(s[0] as libc::c_int) != 0 &&
633-
s[1] == ':' as u8) {
634-
let rest = if s.len() == 2 {
635-
~""
636-
} else {
637-
s.slice(2, s.len())
638-
};
639-
return Some((s.slice(0,1), move rest));
640-
}
641-
None
642-
}
643-
}
644654

645655
#[test]
646656
fn test_extract_unc_prefixes() {
647-
assert extract_unc_prefix("\\\\").is_none();
648-
assert extract_unc_prefix("\\\\hi").is_none();
649-
assert extract_unc_prefix("\\\\hi\\") == Some((~"hi", ~"\\"));
650-
assert extract_unc_prefix("\\\\hi\\there") ==
657+
assert windows::extract_unc_prefix("\\\\").is_none();
658+
assert windows::extract_unc_prefix("\\\\hi").is_none();
659+
assert windows::extract_unc_prefix("\\\\hi\\") ==
660+
Some((~"hi", ~"\\"));
661+
assert windows::extract_unc_prefix("\\\\hi\\there") ==
651662
Some((~"hi", ~"\\there"));
652-
assert extract_unc_prefix("\\\\hi\\there\\friends.txt") ==
663+
assert windows::extract_unc_prefix("\\\\hi\\there\\friends.txt") ==
653664
Some((~"hi", ~"\\there\\friends.txt"));
654665
}
655666

656667
#[test]
657668
fn test_extract_drive_prefixes() {
658-
assert extract_drive_prefix("c").is_none();
659-
assert extract_drive_prefix("c:") == Some((~"c", ~""));
660-
assert extract_drive_prefix("d:") == Some((~"d", ~""));
661-
assert extract_drive_prefix("z:") == Some((~"z", ~""));
662-
assert extract_drive_prefix("c:\\hi") == Some((~"c", ~"\\hi"));
663-
assert extract_drive_prefix("d:hi") == Some((~"d", ~"hi"));
664-
assert extract_drive_prefix("c:hi\\there.txt") ==
669+
assert windows::extract_drive_prefix("c").is_none();
670+
assert windows::extract_drive_prefix("c:") == Some((~"c", ~""));
671+
assert windows::extract_drive_prefix("d:") == Some((~"d", ~""));
672+
assert windows::extract_drive_prefix("z:") == Some((~"z", ~""));
673+
assert windows::extract_drive_prefix("c:\\hi") ==
674+
Some((~"c", ~"\\hi"));
675+
assert windows::extract_drive_prefix("d:hi") == Some((~"d", ~"hi"));
676+
assert windows::extract_drive_prefix("c:hi\\there.txt") ==
665677
Some((~"c", ~"hi\\there.txt"));
666-
assert extract_drive_prefix("c:\\hi\\there.txt") ==
678+
assert windows::extract_drive_prefix("c:\\hi\\there.txt") ==
667679
Some((~"c", ~"\\hi\\there.txt"));
668680
}
669681

670682
#[test]
671683
fn test_windows_paths() {
672-
fn mk(s: &str) -> WindowsPath { WindowsPath(s) }
673684
fn t(wp: &WindowsPath, s: &str) {
674685
let ss = wp.to_str();
675686
let sss = str::from_slice(s);
@@ -680,51 +691,34 @@ mod windows {
680691
}
681692
}
682693

683-
t(&(mk("hi")), "hi");
684-
t(&(mk("hi/there")), "hi\\there");
685-
t(&(mk("hi/there.txt")), "hi\\there.txt");
694+
t(&(WindowsPath("hi")), "hi");
695+
t(&(WindowsPath("hi/there")), "hi\\there");
696+
t(&(WindowsPath("hi/there.txt")), "hi\\there.txt");
686697

687-
t(&(mk("there.txt")
698+
t(&(WindowsPath("there.txt")
688699
.with_filetype("o")), "there.o");
689700

690-
t(&(mk("hi/there.txt")
701+
t(&(WindowsPath("hi/there.txt")
691702
.with_filetype("o")), "hi\\there.o");
692703

693-
t(&(mk("hi/there.txt")
704+
t(&(WindowsPath("hi/there.txt")
694705
.with_filetype("o")
695706
.with_dirname("c:\\program files A")),
696707
"c:\\program files A\\there.o");
697708

698-
t(&(mk("hi/there.txt")
709+
t(&(WindowsPath("hi/there.txt")
699710
.with_filetype("o")
700711
.with_dirname("c:\\program files B\\")),
701712
"c:\\program files B\\there.o");
702713

703-
t(&(mk("hi/there.txt")
714+
t(&(WindowsPath("hi/there.txt")
704715
.with_filetype("o")
705716
.with_dirname("c:\\program files C\\/")),
706717
"c:\\program files C\\there.o");
707718

708-
t(&(mk("c:\\program files (x86)\\rust")
719+
t(&(WindowsPath("c:\\program files (x86)\\rust")
709720
.push_many([~"lib", ~"thingy.dll"])
710721
.with_filename("librustc.dll")),
711722
"c:\\program files (x86)\\rust\\lib\\librustc.dll");
712-
713-
}
714-
715-
#[cfg(test)]
716-
fn mk(s: &str) -> PosixPath { PosixPath(s) }
717-
718-
#[test]
719-
fn test_filetype_foo_bar() {
720-
let wp = mk("foo.bar");
721-
assert wp.filetype() == Some(~".bar");
722723
}
723-
724-
#[test]
725-
fn test_filetype_foo() {
726-
let wp = mk("foo");
727-
assert wp.filetype() == None;
728-
}
729-
730724
}

0 commit comments

Comments
 (0)