AK: Add a basic unit test for FileSystemPath

Just to make sure that things are on the up-and-up.
This commit is contained in:
Andreas Kling 2019-08-07 21:07:02 +02:00
parent 1f9b8f0e7c
commit 43ec733b61
Notes: sideshowbarker 2024-07-19 12:50:13 +09:00
2 changed files with 35 additions and 1 deletions

View file

@ -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)

View file

@ -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)