ladybird/AK/Tests/TestFileSystemPath.cpp
Andreas Kling 73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00

62 lines
1.7 KiB
C++

#include <AK/TestSuite.h>
#include <AK/String.h>
#include <AK/FileSystemPath.h>
TEST_CASE(construct)
{
EXPECT_EQ(FileSystemPath().is_valid(), false);
}
TEST_CASE(basic)
{
FileSystemPath path("/abc/def/ghi.txt");
EXPECT_EQ(path.is_valid(), true);
EXPECT_EQ(path.basename(), "ghi.txt");
EXPECT_EQ(path.title(), "ghi");
EXPECT_EQ(path.extension(), "txt");
EXPECT_EQ(path.parts().size(), 3);
EXPECT_EQ(path.parts(), Vector<String>({ "abc", "def", "ghi.txt" }));
EXPECT_EQ(path.string(), "/abc/def/ghi.txt");
}
TEST_CASE(dotdot_coalescing)
{
EXPECT_EQ(FileSystemPath("/home/user/../../not/home").string(), "/not/home");
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)