diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-07 21:07:02 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-07 21:07:02 +0200 |
commit | 43ec733b61a3f38b7f4c8e12786fd3762de72425 (patch) | |
tree | d6b7c8844dce4eb721f6dff93fff1e56d2d10b2d | |
parent | 1f9b8f0e7c732ec70a77db7eaf22071f43ef46e9 (diff) | |
download | serenity-43ec733b61a3f38b7f4c8e12786fd3762de72425.zip |
AK: Add a basic unit test for FileSystemPath
Just to make sure that things are on the up-and-up.
-rw-r--r-- | AK/Tests/Makefile | 7 | ||||
-rw-r--r-- | AK/Tests/TestFileSystemPath.cpp | 29 |
2 files changed, 35 insertions, 1 deletions
diff --git a/AK/Tests/Makefile b/AK/Tests/Makefile index 7621cf97bb..380c9eab60 100644 --- a/AK/Tests/Makefile +++ b/AK/Tests/Makefile @@ -1,4 +1,4 @@ -PROGRAMS = TestString TestQueue TestVector TestHashMap TestJSON TestWeakPtr TestNonnullRefPtr TestRefPtr TestFixedArray +PROGRAMS = TestString TestQueue TestVector TestHashMap TestJSON TestWeakPtr TestNonnullRefPtr TestRefPtr TestFixedArray TestFileSystemPath CXXFLAGS = -std=c++17 -Wall -Wextra -ggdb3 -O2 -I../ -I../../ @@ -12,6 +12,7 @@ SHARED_TEST_OBJS = \ ../JsonObject.o \ ../JsonValue.o \ ../JsonParser.o \ + ../FileSystemPath.o \ .cpp.o: @echo "HOST_CXX $<"; $(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ -c $< @@ -54,6 +55,10 @@ TestRefPtr: TestRefPtr.o $(SHARED_TEST_OBJS) TestOptional: TestOptional.o $(SHARED_TEST_OBJS) $(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestOptional.o $(SHARED_TEST_OBJS) +TestFileSystemPath: TestFileSystemPath.o $(SHARED_TEST_OBJS) + $(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestFileSystemPath.o $(SHARED_TEST_OBJS) + + clean: rm -f $(SHARED_TEST_OBJS) rm -f $(PROGRAMS) diff --git a/AK/Tests/TestFileSystemPath.cpp b/AK/Tests/TestFileSystemPath.cpp new file mode 100644 index 0000000000..a3d29344ef --- /dev/null +++ b/AK/Tests/TestFileSystemPath.cpp @@ -0,0 +1,29 @@ +#include <AK/TestSuite.h> + +#include <AK/AKString.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_MAIN(FileSystemPath) |