summaryrefslogtreecommitdiff
path: root/AK/Tests
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-15 14:07:23 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-15 14:09:27 +0200
commit2349dc1a21a9f82943532214f4e1189af1d33c16 (patch)
treee268af52fcb28b7565ab378e8700c6822eeb8b29 /AK/Tests
parent77737be7b3b8a6d5a9000997ec58a2d507817b6f (diff)
downloadserenity-2349dc1a21a9f82943532214f4e1189af1d33c16.zip
StringView: Add StringView::operator==(StringView)
Previously we'd implicitly convert the second StringView to a String when comparing two StringViews, which is obviously not what we wanted.
Diffstat (limited to 'AK/Tests')
-rw-r--r--AK/Tests/Makefile4
-rw-r--r--AK/Tests/TestStringView.cpp36
2 files changed, 39 insertions, 1 deletions
diff --git a/AK/Tests/Makefile b/AK/Tests/Makefile
index b1c7b8a248..a87819f174 100644
--- a/AK/Tests/Makefile
+++ b/AK/Tests/Makefile
@@ -1,4 +1,4 @@
-PROGRAMS = TestString TestQueue TestVector TestHashMap TestJSON TestWeakPtr TestNonnullRefPtr TestRefPtr TestFixedArray TestFileSystemPath TestURL
+PROGRAMS = TestString TestQueue TestVector TestHashMap TestJSON TestWeakPtr TestNonnullRefPtr TestRefPtr TestFixedArray TestFileSystemPath TestURL TestStringView
CXXFLAGS = -std=c++17 -Wall -Wextra -ggdb3 -O2 -I../ -I../../
@@ -62,6 +62,8 @@ TestFileSystemPath: TestFileSystemPath.o $(SHARED_TEST_OBJS)
TestURL: TestURL.o $(SHARED_TEST_OBJS)
$(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestURL.o $(SHARED_TEST_OBJS)
+TestStringView: TestStringView.o $(SHARED_TEST_OBJS)
+ $(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestStringView.o $(SHARED_TEST_OBJS)
clean:
rm -f $(SHARED_TEST_OBJS)
diff --git a/AK/Tests/TestStringView.cpp b/AK/Tests/TestStringView.cpp
new file mode 100644
index 0000000000..06c2c56589
--- /dev/null
+++ b/AK/Tests/TestStringView.cpp
@@ -0,0 +1,36 @@
+#include <AK/TestSuite.h>
+
+#include <AK/AKString.h>
+
+TEST_CASE(construct_empty)
+{
+ EXPECT(StringView().is_null());
+ EXPECT(StringView().is_empty());
+ EXPECT(!StringView().characters_without_null_termination());
+ EXPECT_EQ(StringView().length(), 0);
+}
+
+TEST_CASE(view_literal)
+{
+ const char* truth = "cats rule dogs drool";
+ StringView view(truth);
+ EXPECT_EQ(view.is_null(), false);
+ EXPECT_EQ(view.characters_without_null_termination(), truth);
+ EXPECT_EQ(view, view);
+ EXPECT_EQ(view, truth);
+}
+
+TEST_CASE(compare_views)
+{
+ String foo1 = "foo";
+ String foo2 = "foo";
+ auto view1 = foo1.view();
+ auto view2 = foo2.view();
+
+ EXPECT_EQ(view1, view2);
+ EXPECT_EQ(view1, foo1);
+ EXPECT_EQ(view1, foo2);
+ EXPECT_EQ(view1, "foo");
+}
+
+TEST_MAIN(StringView)