fix Path::ext() when new_ext == ""

This commit is contained in:
Josh Holtrop 2014-06-22 21:01:38 -04:00
parent a1e9c30af2
commit cae4b077d9
2 changed files with 6 additions and 1 deletions

View File

@ -58,7 +58,11 @@ namespace jes
}
i--;
}
if (new_ext[0] == '.')
if (new_ext.size() == 0)
{
return new Path(std::string(m_path, 0, i));
}
else if (new_ext[0] == '.')
{
return new Path(std::string(m_path, 0, i) + new_ext);
}

View File

@ -49,6 +49,7 @@ TEST(PathTest, ext)
EXPECT_EQ("file.h", Path("file.c").ext("h")->to_s());
EXPECT_EQ("/some/crazy/dir/foo.txt", Path("/some/crazy/dir/foo").ext(".txt")->to_s());
EXPECT_EQ("/some/crazy/dir/foo.txt", Path("/some/crazy/dir/foo").ext("txt")->to_s());
EXPECT_EQ("C:/baz", Path("C:\\baz.xyz").ext("")->to_s());
}
TEST(PathTest, exists)