implement Path::join()

This commit is contained in:
Josh Holtrop 2014-06-18 23:49:00 -04:00
parent 863fb2018b
commit eb12420155
2 changed files with 10 additions and 2 deletions

View File

@ -22,8 +22,10 @@ namespace jes
Path Path::join(const Path & other) Path Path::join(const Path & other)
{ {
// TODO if (m_path.size() > 0 && *m_path.rbegin() == '/')
return ""; return Path(m_path + other.m_path);
else
return Path(m_path + '/' + other.m_path);
} }
void Path::clean() void Path::clean()

View File

@ -21,3 +21,9 @@ TEST(PathTest, convert_backslashes_to_forward_slashes)
Path p("C:\\foo\\bar.txt"); Path p("C:\\foo\\bar.txt");
EXPECT_EQ("C:/foo/bar.txt", p.to_s()); EXPECT_EQ("C:/foo/bar.txt", p.to_s());
} }
TEST(PathTest, joins_two_paths_together)
{
EXPECT_EQ("C:/foo/../baz", Path("C:\\foo").join("../baz").to_s());
EXPECT_EQ("/xyz/f.txt", Path("/xyz/").join("f.txt").to_s());
}