mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
AK: Make LexicalPath immutable
This replaces the current LexicalPath::append() API with a new method that returns a new LexicalPath object and doesn't touch the this-object. With this, LexicalPath is now immutable. It also adds a LexicalPath::parent() method and the relevant test cases.
This commit is contained in:
parent
1e80022282
commit
4c018909f7
Notes:
sideshowbarker
2024-07-18 11:13:28 +09:00
Author: https://github.com/MaxWipfli
Commit: 4c018909f7
Pull-request: https://github.com/SerenityOS/serenity/pull/8320
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
3 changed files with 38 additions and 11 deletions
|
@ -165,11 +165,38 @@ TEST_CASE(join)
|
|||
EXPECT_EQ(LexicalPath::join("anon", "foo.txt").string(), "anon/foo.txt");
|
||||
EXPECT_EQ(LexicalPath::join("/home", "anon/foo.txt").string(), "/home/anon/foo.txt");
|
||||
EXPECT_EQ(LexicalPath::join("/", "foo.txt").string(), "/foo.txt");
|
||||
EXPECT_EQ(LexicalPath::join("/home", "anon", "foo.txt").string(), "/home/anon/foo.txt");
|
||||
}
|
||||
|
||||
TEST_CASE(append)
|
||||
{
|
||||
LexicalPath path("/home/anon");
|
||||
path.append("foo.txt");
|
||||
EXPECT_EQ(path.string(), "/home/anon/foo.txt");
|
||||
LexicalPath path("/home/anon/");
|
||||
auto new_path = path.append("foo.txt");
|
||||
EXPECT_EQ(new_path.string(), "/home/anon/foo.txt");
|
||||
}
|
||||
|
||||
TEST_CASE(parent)
|
||||
{
|
||||
{
|
||||
LexicalPath path("/home/anon/foo.txt");
|
||||
auto parent = path.parent();
|
||||
EXPECT_EQ(parent.string(), "/home/anon");
|
||||
}
|
||||
{
|
||||
LexicalPath path("anon/foo.txt");
|
||||
auto parent = path.parent();
|
||||
EXPECT_EQ(parent.string(), "anon");
|
||||
}
|
||||
{
|
||||
LexicalPath path("foo.txt");
|
||||
auto parent = path.parent();
|
||||
EXPECT_EQ(parent.string(), ".");
|
||||
auto parent_of_parent = parent.parent();
|
||||
EXPECT_EQ(parent_of_parent.string(), "..");
|
||||
}
|
||||
{
|
||||
LexicalPath path("/");
|
||||
auto parent = path.parent();
|
||||
EXPECT_EQ(parent.string(), "/");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue