summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Meta/Lagom/CMakeLists.txt7
-rw-r--r--Tests/CMakeLists.txt1
-rw-r--r--Tests/LibTextCodec/CMakeLists.txt7
-rw-r--r--Tests/LibTextCodec/TestTextDecoders.cpp25
4 files changed, 40 insertions, 0 deletions
diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt
index 3ab41d441d..3ba6966dc7 100644
--- a/Meta/Lagom/CMakeLists.txt
+++ b/Meta/Lagom/CMakeLists.txt
@@ -596,6 +596,13 @@ if (BUILD_LAGOM)
lagom_test(${source} LIBS LagomSQL)
endforeach()
+ # TextCodec
+ file(GLOB LIBTEXTCODEC_TESTS CONFIGURE_DEPENDS "../../Tests/LibTextCodec/*.cpp")
+ foreach(source ${LIBTEXTCODEC_TESTS})
+ lagom_test(${source} LIBS LagomTextCodec
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTextCodec)
+ endforeach()
+
# TLS
file(GLOB LIBTLS_TESTS CONFIGURE_DEPENDS "../../Tests/LibTLS/*.cpp")
foreach(source ${LIBTLS_TESTS})
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 4af1b491da..8bd6281bc3 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -17,6 +17,7 @@ add_subdirectory(LibPthread)
add_subdirectory(LibRegex)
add_subdirectory(LibSQL)
add_subdirectory(LibTest)
+add_subdirectory(LibTextCodec)
add_subdirectory(LibThreading)
add_subdirectory(LibTimeZone)
add_subdirectory(LibUnicode)
diff --git a/Tests/LibTextCodec/CMakeLists.txt b/Tests/LibTextCodec/CMakeLists.txt
new file mode 100644
index 0000000000..ec39ad694f
--- /dev/null
+++ b/Tests/LibTextCodec/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(TEST_SOURCES
+ TestTextDecoders.cpp
+)
+
+foreach(source IN LISTS TEST_SOURCES)
+ serenity_test("${source}" LibTextCodec LIBS LibTextCodec)
+endforeach()
diff --git a/Tests/LibTextCodec/TestTextDecoders.cpp b/Tests/LibTextCodec/TestTextDecoders.cpp
new file mode 100644
index 0000000000..6d51c3b114
--- /dev/null
+++ b/Tests/LibTextCodec/TestTextDecoders.cpp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022, the SerenityOS developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/Vector.h>
+#include <LibTest/TestCase.h>
+#include <LibTextCodec/Decoder.h>
+
+TEST_CASE(test_utf8_decode)
+{
+ auto decoder = TextCodec::UTF8Decoder();
+ // Bytes for U+1F600 GRINNING FACE
+ auto test_string = "\xf0\x9f\x98\x80";
+
+ Vector<u32> processed_code_points;
+ decoder.process(test_string, [&](u32 code_point) {
+ processed_code_points.append(code_point);
+ });
+ EXPECT(processed_code_points.size() == 1);
+ EXPECT(processed_code_points[0] == 0x1F600);
+
+ EXPECT(decoder.to_utf8(test_string) == test_string);
+}