summaryrefslogtreecommitdiffstats
path: root/base/file_path_unittest.cc
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-25 01:53:44 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-25 01:53:44 +0000
commit922828b3ae178dc7c7985b96f54a540f1f22cc9f (patch)
tree3b47f2223d2f5416403d50ceeba76d2581386ebc /base/file_path_unittest.cc
parent3ffb5e43d0996501ea2a3923c2e8c73dcf1d9b66 (diff)
downloadchromium_src-922828b3ae178dc7c7985b96f54a540f1f22cc9f.zip
chromium_src-922828b3ae178dc7c7985b96f54a540f1f22cc9f.tar.gz
chromium_src-922828b3ae178dc7c7985b96f54a540f1f22cc9f.tar.bz2
Add an AddExtension() method in FilePath
This provides an AddExtension() method in FilePath, which will append an extension to the FilePath. This provides clearer, more deliberate functionality than AppendASCII(), and allows us to add extensions without using ReplaceExtension, which will not work on files which already have extension (or appear to, e.g. temp files). BUG=NONE TEST=FilePathTest.AddExtension (added), previous FilePathTests. Review URL: http://codereview.chromium.org/10067002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path_unittest.cc')
-rw-r--r--base/file_path_unittest.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc
index 71bff29..194ee49 100644
--- a/base/file_path_unittest.cc
+++ b/base/file_path_unittest.cc
@@ -896,6 +896,44 @@ TEST_F(FilePathTest, ReplaceExtension) {
}
}
+TEST_F(FilePathTest, AddExtension) {
+ const struct BinaryTestData cases[] = {
+ { { FPL(""), FPL("") }, FPL("") },
+ { { FPL(""), FPL("txt") }, FPL("") },
+ { { FPL("."), FPL("txt") }, FPL("") },
+ { { FPL(".."), FPL("txt") }, FPL("") },
+ { { FPL("."), FPL("") }, FPL("") },
+ { { FPL("foo.dll"), FPL("txt") }, FPL("foo.dll.txt") },
+ { { FPL("./foo.dll"), FPL("txt") }, FPL("./foo.dll.txt") },
+ { { FPL("foo..dll"), FPL("txt") }, FPL("foo..dll.txt") },
+ { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.dll.txt") },
+ { { FPL("foo"), FPL("txt") }, FPL("foo.txt") },
+ { { FPL("foo."), FPL("txt") }, FPL("foo.txt") },
+ { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") },
+ { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
+ { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.dll.txt") },
+ { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.dll.txt") },
+ { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
+ { { FPL("foo.dll"), FPL(".") }, FPL("foo.dll") },
+ { { FPL("foo"), FPL("") }, FPL("foo") },
+ { { FPL("foo"), FPL(".") }, FPL("foo") },
+ { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
+ { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz.dll") },
+#if defined(FILE_PATH_USES_WIN_SEPARATORS)
+ { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
+ { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
+#endif
+ { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
+ { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
+ };
+ for (unsigned int i = 0; i < arraysize(cases); ++i) {
+ FilePath path(cases[i].inputs[0]);
+ FilePath added = path.AddExtension(cases[i].inputs[1]);
+ EXPECT_EQ(cases[i].expected, added.value()) << "i: " << i <<
+ ", path: " << path.value() << ", add: " << cases[i].inputs[1];
+ }
+}
+
TEST_F(FilePathTest, MatchesExtension) {
const struct BinaryBooleanTestData cases[] = {
{ { FPL("foo"), FPL("") }, true},