From 7c37377a717a32501b8c07406a6ad8a0b7229240 Mon Sep 17 00:00:00 2001 From: "tony@chromium.org" Date: Fri, 25 Jun 2010 05:33:17 +0000 Subject: 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 --- base/file_path_unittest.cc | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'base/file_path_unittest.cc') 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 -- cgit v1.1