From 155b8606c1a798f89078aa39780a8b4c28161da7 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 2 Sep 2008 11:32:38 +0000 Subject: Added two new global funcs which ease proper handling of 'path' strings: Common::lastPathComponent() and Common::normalizePath() svn-id: r34272 --- test/common/str.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/common/str.h') diff --git a/test/common/str.h b/test/common/str.h index 72d4df6f61..c4819520d8 100644 --- a/test/common/str.h +++ b/test/common/str.h @@ -157,4 +157,36 @@ class StringTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS(str, "TEST IT, NOW! 42"); TS_ASSERT_EQUALS(str2, "Test it, NOW! 42"); } + + void test_lastPathComponent(void) { + TS_ASSERT(Common::lastPathComponent("/", '/') == ""); + TS_ASSERT(Common::lastPathComponent("/foo/bar", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("/foo//bar/", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("/foo/./bar", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("/foo//./bar//", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("/foo//.bar//", '/') == ".bar"); + + TS_ASSERT(Common::lastPathComponent("", '/') == ""); + TS_ASSERT(Common::lastPathComponent("foo/bar", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("foo//bar/", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("foo/./bar", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("foo//./bar//", '/') == "bar"); + TS_ASSERT(Common::lastPathComponent("foo//.bar//", '/') == ".bar"); + } + + void test_normalizePath(void) { + TS_ASSERT(Common::normalizePath("/", '/') == "/"); + TS_ASSERT(Common::normalizePath("/foo/bar", '/') == "/foo/bar"); + TS_ASSERT(Common::normalizePath("/foo//bar/", '/') == "/foo/bar"); + TS_ASSERT(Common::normalizePath("/foo/./bar", '/') == "/foo/bar"); + TS_ASSERT(Common::normalizePath("/foo//./bar//", '/') == "/foo/bar"); + TS_ASSERT(Common::normalizePath("/foo//.bar//", '/') == "/foo/.bar"); + + TS_ASSERT(Common::normalizePath("", '/') == ""); + TS_ASSERT(Common::normalizePath("foo/bar", '/') == "foo/bar"); + TS_ASSERT(Common::normalizePath("foo//bar/", '/') == "foo/bar"); + TS_ASSERT(Common::normalizePath("foo/./bar", '/') == "foo/bar"); + TS_ASSERT(Common::normalizePath("foo//./bar//", '/') == "foo/bar"); + TS_ASSERT(Common::normalizePath("foo//.bar//", '/') == "foo/.bar"); + } }; -- cgit v1.2.3