Skip to content

Commit dcb24e9

Browse files
krkkawesomekling
authored andcommitted
Tests: Add a basic UTF-8 to UTF-8 LibTextCodec test
1 parent b006a60 commit dcb24e9

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

Meta/Lagom/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,13 @@ if (BUILD_LAGOM)
596596
lagom_test(${source} LIBS LagomSQL)
597597
endforeach()
598598

599+
# TextCodec
600+
file(GLOB LIBTEXTCODEC_TESTS CONFIGURE_DEPENDS "../../Tests/LibTextCodec/*.cpp")
601+
foreach(source ${LIBTEXTCODEC_TESTS})
602+
lagom_test(${source} LIBS LagomTextCodec
603+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTextCodec)
604+
endforeach()
605+
599606
# TLS
600607
file(GLOB LIBTLS_TESTS CONFIGURE_DEPENDS "../../Tests/LibTLS/*.cpp")
601608
foreach(source ${LIBTLS_TESTS})

Tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_subdirectory(LibPthread)
1717
add_subdirectory(LibRegex)
1818
add_subdirectory(LibSQL)
1919
add_subdirectory(LibTest)
20+
add_subdirectory(LibTextCodec)
2021
add_subdirectory(LibThreading)
2122
add_subdirectory(LibTimeZone)
2223
add_subdirectory(LibUnicode)

Tests/LibTextCodec/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(TEST_SOURCES
2+
TestTextDecoders.cpp
3+
)
4+
5+
foreach(source IN LISTS TEST_SOURCES)
6+
serenity_test("${source}" LibTextCodec LIBS LibTextCodec)
7+
endforeach()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022, the SerenityOS developers.
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <AK/Vector.h>
8+
#include <LibTest/TestCase.h>
9+
#include <LibTextCodec/Decoder.h>
10+
11+
TEST_CASE(test_utf8_decode)
12+
{
13+
auto decoder = TextCodec::UTF8Decoder();
14+
// Bytes for U+1F600 GRINNING FACE
15+
auto test_string = "\xf0\x9f\x98\x80";
16+
17+
Vector<u32> processed_code_points;
18+
decoder.process(test_string, [&](u32 code_point) {
19+
processed_code_points.append(code_point);
20+
});
21+
EXPECT(processed_code_points.size() == 1);
22+
EXPECT(processed_code_points[0] == 0x1F600);
23+
24+
EXPECT(decoder.to_utf8(test_string) == test_string);
25+
}

0 commit comments

Comments
 (0)