diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 05:33:17 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 05:33:17 +0000 |
commit | 7c37377a717a32501b8c07406a6ad8a0b7229240 (patch) | |
tree | 979bf47baa340e6d313210221aedd45ddb063205 /base/file_path_unittest.cc | |
parent | b058597f786b4d1398bfa0cf4971bf7bb2b75c3b (diff) | |
download | chromium_src-7c37377a717a32501b8c07406a6ad8a0b7229240.zip chromium_src-7c37377a717a32501b8c07406a6ad8a0b7229240.tar.gz chromium_src-7c37377a717a32501b8c07406a6ad8a0b7229240.tar.bz2 |
Add a method for normalizing path separators on Windows.
TEST=new unittests
Review URL: http://codereview.chromium.org/2831029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50822 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path_unittest.cc')
-rw-r--r-- | base/file_path_unittest.cc | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc index 92659f1..828a642 100644 --- a/base/file_path_unittest.cc +++ b/base/file_path_unittest.cc @@ -661,7 +661,7 @@ TEST_F(FilePathTest, EqualityTest) { #if defined(FILE_PATH_USES_WIN_SEPARATORS) { { FPL("\\foo\\bar"), FPL("\\foo\\bar") }, true}, { { FPL("\\foo/bar"), FPL("\\foo/bar") }, true}, - { { FPL("\\foo/bar"), FPL("\\foo\bar") }, false}, + { { FPL("\\foo/bar"), FPL("\\foo\\bar") }, false}, { { FPL("\\"), FPL("\\") }, true}, { { FPL("\\"), FPL("/") }, false}, { { FPL(""), FPL("\\") }, false}, @@ -1004,3 +1004,47 @@ TEST_F(FilePathTest, ReferencesParent) { "i: " << i << ", input: " << input.value(); } } + +#if defined(FILE_PATH_USES_WIN_SEPARATORS) +TEST_F(FilePathTest, NormalizeWindowsPathSeparators) { + const struct UnaryTestData cases[] = { + { FPL("foo/bar"), FPL("foo\\bar") }, + { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, + { FPL("foo\\bar"), FPL("foo\\bar") }, + { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") }, + { FPL("foo"), FPL("foo") }, + // Trailing slashes don't automatically get stripped. That's what + // StripTrailingSeparators() is for. + { FPL("foo\\"), FPL("foo\\") }, + { FPL("foo/"), FPL("foo\\") }, + { FPL("foo/bar\\"), FPL("foo\\bar\\") }, + { FPL("foo\\bar/"), FPL("foo\\bar\\") }, + { FPL("foo/bar/"), FPL("foo\\bar\\") }, + { FPL("foo\\bar\\"), FPL("foo\\bar\\") }, + { FPL("\\foo/bar"), FPL("\\foo\\bar") }, + { FPL("/foo\\bar"), FPL("\\foo\\bar") }, + { FPL("c:/foo/bar/"), FPL("c:\\foo\\bar\\") }, + { FPL("/foo/bar/"), FPL("\\foo\\bar\\") }, + { FPL("\\foo\\bar\\"), FPL("\\foo\\bar\\") }, + { FPL("c:\\foo/bar"), FPL("c:\\foo\\bar") }, + { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") }, + { FPL("\\\\foo\\bar\\"), FPL("\\\\foo\\bar\\") }, + { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") }, + // This method does not normalize the number of path separators. + { FPL("foo\\\\bar"), FPL("foo\\\\bar") }, + { FPL("foo//bar"), FPL("foo\\\\bar") }, + { FPL("foo/\\bar"), FPL("foo\\\\bar") }, + { FPL("foo\\/bar"), FPL("foo\\\\bar") }, + { FPL("///foo\\\\bar"), FPL("\\\\\\foo\\\\bar") }, + { FPL("foo//bar///"), FPL("foo\\\\bar\\\\\\") }, + { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") }, + { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, + }; + for (size_t i = 0; i < arraysize(cases); ++i) { + FilePath input(cases[i].input); + FilePath observed = input.NormalizeWindowsPathSeparators(); + EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << + "i: " << i << ", input: " << input.value(); + } +} +#endif |