summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-14 06:42:21 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-14 06:42:21 +0200
commitb7cca76ca2d991c132de384dd150d8f946e92ab5 (patch)
tree711e6ed2d3e81b432ced0934e0a83c65e77456a8
parent802612f665a2d15f22840b7716522d6ad786247a (diff)
downloadserenity-b7cca76ca2d991c132de384dd150d8f946e92ab5.zip
AK: Add an extremely primitive unit test for String.
This builds for the host system rather than for Serenity. We need to improve on it a *lot*, but at least it's a place to start.
-rw-r--r--AK/Tests/.gitignore1
-rw-r--r--AK/Tests/Makefile9
-rw-r--r--AK/Tests/TestString.cpp19
3 files changed, 29 insertions, 0 deletions
diff --git a/AK/Tests/.gitignore b/AK/Tests/.gitignore
new file mode 100644
index 0000000000..3a62d28e3c
--- /dev/null
+++ b/AK/Tests/.gitignore
@@ -0,0 +1 @@
+TestString
diff --git a/AK/Tests/Makefile b/AK/Tests/Makefile
new file mode 100644
index 0000000000..fdec39410e
--- /dev/null
+++ b/AK/Tests/Makefile
@@ -0,0 +1,9 @@
+all: TestString
+
+CXXFLAGS = -std=c++17 -Wall -Wextra
+
+TestString: TestString.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
+ $(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestString.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
+
+clean:
+ rm -f TestString
diff --git a/AK/Tests/TestString.cpp b/AK/Tests/TestString.cpp
new file mode 100644
index 0000000000..fb26395a09
--- /dev/null
+++ b/AK/Tests/TestString.cpp
@@ -0,0 +1,19 @@
+#include <AK/AKString.h>
+
+int main()
+{
+ ASSERT(String().is_null());
+ ASSERT(String().is_empty());
+
+ ASSERT(!String("").is_null());
+ ASSERT(String("").is_empty());
+
+ String test_string = "ABCDEF";
+ ASSERT(!test_string.is_empty());
+ ASSERT(!test_string.is_null());
+ ASSERT(test_string.length() == 6);
+ ASSERT(test_string.length() == strlen(test_string.characters()));
+ ASSERT(!strcmp(test_string.characters(), "ABCDEF"));
+
+ return 0;
+}