mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:07:35 +00:00
AK: Make FileSystemPath better at handling relative paths
Relative paths now canonicalize into a string starting with "./" Previously, "foo" would be canonicalized as "/foo" which was clearly not right.
This commit is contained in:
parent
b1bc7a1b5d
commit
56eaf9b033
2 changed files with 54 additions and 6 deletions
|
@ -26,4 +26,37 @@ TEST_CASE(dotdot_coalescing)
|
|||
EXPECT_EQ(FileSystemPath("/../../../../").string(), "/");
|
||||
}
|
||||
|
||||
TEST_CASE(relative_paths)
|
||||
{
|
||||
{
|
||||
FileSystemPath path("simple");
|
||||
EXPECT_EQ(path.is_valid(), true);
|
||||
EXPECT_EQ(path.string(), "./simple");
|
||||
EXPECT_EQ(path.parts().size(), 2);
|
||||
EXPECT_EQ(path.basename(), "simple");
|
||||
}
|
||||
{
|
||||
FileSystemPath path("a/relative/path");
|
||||
EXPECT_EQ(path.is_valid(), true);
|
||||
EXPECT_EQ(path.string(), "./a/relative/path");
|
||||
EXPECT_EQ(path.parts().size(), 4);
|
||||
EXPECT_EQ(path.basename(), "path");
|
||||
}
|
||||
{
|
||||
FileSystemPath path("./././foo");
|
||||
EXPECT_EQ(path.is_valid(), true);
|
||||
EXPECT_EQ(path.string(), "./foo");
|
||||
EXPECT_EQ(path.parts().size(), 2);
|
||||
EXPECT_EQ(path.basename(), "foo");
|
||||
}
|
||||
|
||||
{
|
||||
FileSystemPath path(".");
|
||||
EXPECT_EQ(path.is_valid(), true);
|
||||
EXPECT_EQ(path.string(), ".");
|
||||
EXPECT_EQ(path.parts().size(), 1);
|
||||
EXPECT_EQ(path.basename(), ".");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_MAIN(FileSystemPath)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue